Yet Another eXchange Tool  DO_NOT_EDIT_HERE
xt_exchanger_irecv_isend_packed.c
Go to the documentation of this file.
1 
12 /*
13  * Keywords:
14  * Maintainer: Jörg Behrens <behrens@dkrz.de>
15  * Moritz Hanke <hanke@dkrz.de>
16  * Thomas Jahns <jahns@dkrz.de>
17  * URL: https://redmine.dkrz.de/doc/yaxt/html/index.html
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met:
22  *
23  * Redistributions of source code must retain the above copyright notice,
24  * this list of conditions and the following disclaimer.
25  *
26  * Redistributions in binary form must reproduce the above copyright
27  * notice, this list of conditions and the following disclaimer in the
28  * documentation and/or other materials provided with the distribution.
29  *
30  * Neither the name of the DKRZ GmbH nor the names of its contributors
31  * may be used to endorse or promote products derived from this software
32  * without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
38  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  */
46 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif
49 
50 #include "core/ppm_xfuncs.h"
51 #include "xt/xt_mpi.h"
52 #include "xt_mpi_internal.h"
53 #include "xt_redist_internal.h"
56 
57 static void
58 xt_exchanger_irecv_isend_packed_s_exchange(const void *src_data, void *dst_data,
59  int nsend, int nrecv,
60  struct Xt_redist_msg * send_msgs,
61  struct Xt_redist_msg * recv_msgs,
62  int tag_offset, MPI_Comm comm) {
63 
64  MPI_Request * requests =
65  xmalloc((size_t)(nrecv + nsend) * sizeof (*requests));
66  void ** buffers =
67  xmalloc((size_t)(nrecv + nsend) * sizeof (*buffers));
68 
69  int buffer_size;
70  for (int i = 0; i < nrecv; ++i) {
71  xt_mpi_call(MPI_Pack_size(1, recv_msgs[i].datatype, comm, &buffer_size),
72  comm);
73  buffers[i] = xmalloc((size_t)buffer_size);
74  xt_mpi_call(MPI_Irecv(buffers[i], buffer_size, MPI_PACKED,
75  recv_msgs[i].rank,
76  tag_offset + xt_mpi_tag_exchange_msg, comm,
77  requests+i), comm);
78  }
79 
80  for (int i = 0; i < nsend; ++i) {
81  int position = 0;
82  xt_mpi_call(MPI_Pack_size(1, send_msgs[i].datatype, comm, &buffer_size),
83  comm);
84  buffers[nrecv + i] = xmalloc((size_t)buffer_size);
85  xt_mpi_call(MPI_Pack((void*)src_data, 1, send_msgs[i].datatype,
86  buffers[nrecv + i], buffer_size, &position,
87  comm), comm);
88  xt_mpi_call(MPI_Isend(buffers[nrecv + i], buffer_size, MPI_PACKED,
89  send_msgs[i].rank,
90  tag_offset + xt_mpi_tag_exchange_msg, comm,
91  requests+nrecv+i), comm);
92  }
93 
94  xt_mpi_call(MPI_Waitall(nrecv + nsend, requests, MPI_STATUSES_IGNORE), comm);
95 
96  for (int i = 0; i < nrecv; ++i) {
97  int position = 0;
98  xt_mpi_call(MPI_Pack_size(1, recv_msgs[i].datatype, comm, &buffer_size),
99  comm);
100  xt_mpi_call(MPI_Unpack(buffers[i], buffer_size, &position, dst_data,
101  1, recv_msgs[i].datatype, comm), comm);
102  }
103 
104  for (int i = 0; i < nsend + nrecv; ++i)
105  free(buffers[i]);
106  free(buffers);
107  free(requests);
108 }
109 
112  struct Xt_redist_msg * send_msgs,
113  struct Xt_redist_msg * recv_msgs,
114  MPI_Comm comm, int tag_offset) {
115 
116  return xt_exchanger_simple_base_new(nsend, nrecv, send_msgs, recv_msgs,
117  comm, tag_offset,
119 }
120 
121 /*
122  * Local Variables:
123  * c-basic-offset: 2
124  * coding: utf-8
125  * indent-tabs-mode: nil
126  * show-trailing-whitespace: t
127  * require-trailing-newline: t
128  * End:
129  */
redistribution of data, non-public declarations
Xt_exchanger xt_exchanger_simple_base_new(int nsend, int nrecv, struct Xt_redist_msg *send_msgs, struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset, xt_simple_exchange_func func)
add versions of standard API functions not returning on error
Xt_exchanger xt_exchanger_irecv_isend_packed_new(int nsend, int nrecv, struct Xt_redist_msg *send_msgs, struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
static void xt_exchanger_irecv_isend_packed_s_exchange(const void *src_data, void *dst_data, int nsend, int nrecv, struct Xt_redist_msg *send_msgs, struct Xt_redist_msg *recv_msgs, int tag_offset, MPI_Comm comm)
MPI_Datatype datatype
#define xt_mpi_call(call, comm)
Definition: xt_mpi.h:68
#define xmalloc(size)
Definition: ppm_xfuncs.h:66
int MPI_Comm
Definition: core.h:64
utility routines for MPI