Yet Another eXchange Tool  0.9.0
xt_exchanger_irecv_isend.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://doc.redmine.dkrz.de/yaxt/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/xt_request_msgs.h"
53 #include "xt_mpi_internal.h"
54 #include "xt_redist_internal.h"
57 
58 static void
59 xt_exchanger_irecv_isend_s_exchange(const void *src_data, void *dst_data,
60  int nsend, int nrecv,
61  const struct Xt_redist_msg *send_msgs,
62  const struct Xt_redist_msg *recv_msgs,
63  int tag_offset, MPI_Comm comm) {
64 
65  MPI_Request *requests
66  = xmalloc((size_t)(nrecv + nsend) * sizeof (*requests));
67 
68  for (int i = 0; i < nrecv; ++i)
69  xt_mpi_call(MPI_Irecv(dst_data, 1, recv_msgs[i].datatype,
70  recv_msgs[i].rank,
71  tag_offset + xt_mpi_tag_exchange_msg, comm,
72  requests+i), comm);
73 
74  for (int i = 0; i < nsend; ++i)
75  xt_mpi_call(MPI_Isend(CAST_MPI_SEND_BUF(src_data), 1, send_msgs[i].datatype,
76  send_msgs[i].rank,
77  tag_offset + xt_mpi_tag_exchange_msg, comm,
78  requests+nrecv+i), comm);
79 
80  xt_mpi_call(MPI_Waitall(nrecv + nsend, requests, MPI_STATUSES_IGNORE), comm);
81 
82  free(requests);
83 }
84 
85 static void
86 xt_exchanger_irecv_isend_a_exchange(const void *src_data, void *dst_data,
87  int nsend, int nrecv,
88  const struct Xt_redist_msg * send_msgs,
89  const struct Xt_redist_msg * recv_msgs,
90  int tag_offset, MPI_Comm comm,
91  Xt_request *request) {
92 
93  MPI_Request *tmp_requests
94  = xmalloc((size_t)(nrecv + nsend) * sizeof (*tmp_requests));
95 
96  for (int i = 0; i < nrecv; ++i)
97  xt_mpi_call(MPI_Irecv(dst_data, 1, recv_msgs[i].datatype,
98  recv_msgs[i].rank,
99  tag_offset + xt_mpi_tag_exchange_msg, comm,
100  tmp_requests+i), comm);
101 
102  for (int i = 0; i < nsend; ++i)
103  xt_mpi_call(MPI_Isend(CAST_MPI_SEND_BUF(src_data), 1, send_msgs[i].datatype,
104  send_msgs[i].rank,
105  tag_offset + xt_mpi_tag_exchange_msg, comm,
106  tmp_requests+nrecv+i), comm);
107 
108  Xt_request requests = xt_request_msgs_new(nrecv + nsend, tmp_requests, comm);
109 
110  free(tmp_requests);
111 
112  *request = requests;
113 }
114 
116 xt_exchanger_irecv_isend_new(int nsend, int nrecv,
117  const struct Xt_redist_msg *send_msgs,
118  const struct Xt_redist_msg *recv_msgs,
119  MPI_Comm comm, int tag_offset) {
120 
125  return xt_exchanger_simple_base_new(nsend, nrecv, send_msgs, recv_msgs,
126  comm, tag_offset,
129 }
130 
131 
132 /*
133  * Local Variables:
134  * c-basic-offset: 2
135  * coding: utf-8
136  * indent-tabs-mode: nil
137  * show-trailing-whitespace: t
138  * require-trailing-newline: t
139  * End:
140  */
int MPI_Comm
Definition: core.h:64
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition: ppm_xfuncs.h:70
static void xt_exchanger_irecv_isend_s_exchange(const void *src_data, void *dst_data, int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, int tag_offset, MPI_Comm comm)
static void xt_exchanger_irecv_isend_a_exchange(const void *src_data, void *dst_data, int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, int tag_offset, MPI_Comm comm, Xt_request *request)
Xt_exchanger xt_exchanger_irecv_isend_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset)
Xt_exchanger xt_exchanger_simple_base_new(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm, int tag_offset, xt_simple_s_exchange_func s_func, xt_simple_a_exchange_func a_func)
utility routines for MPI
#define xt_mpi_call(call, comm)
Definition: xt_mpi.h:68
@ xt_mpi_tag_exchange_msg
redistribution of data, non-public declarations
Xt_request xt_request_msgs_new(int n, const MPI_Request requests[n], MPI_Comm comm)