Yet Another eXchange Tool 0.11.3
Loading...
Searching...
No Matches
xt_exchanger_irecv_send.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://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
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 <mpi.h>
51#ifdef _OPENMP
52#include <omp.h>
53#endif
54
55#include "core/ppm_xfuncs.h"
56#include "xt/xt_mpi.h"
57#include "xt_config_internal.h"
58#include "xt_mpi_internal.h"
60#include "xt_redist_internal.h"
63
64/* unfortunately GCC 11 cannot handle the literal constants used for
65 * MPI_STATUSES_IGNORE by MPICH */
66#if __GNUC__ >= 11 && __GNUC__ <= 13 && defined MPICH
67#pragma GCC diagnostic push
68#pragma GCC diagnostic ignored "-Wstringop-overread"
69#pragma GCC diagnostic ignored "-Wstringop-overflow"
70#endif
71
72static void
73xt_exchanger_irecv_send_s_exchange_(const void *src_data, void *dst_data,
74 int nsend, int nrecv,
75 const struct Xt_redist_msg *send_msgs,
76 const struct Xt_redist_msg *recv_msgs,
77 int tag_offset, MPI_Comm comm,
78 MPI_Request *recv_request)
79{
80 for (int i = 0; i < nrecv; ++i)
81 xt_mpi_call(MPI_Irecv(dst_data, 1, recv_msgs[i].datatype,
82 recv_msgs[i].rank,
83 tag_offset + xt_mpi_tag_exchange_msg, comm,
84 recv_request+i), comm);
85
86 for (int i = 0; i < nsend; ++i)
87 xt_mpi_call(MPI_Send(CAST_MPI_SEND_BUF(src_data), 1, send_msgs[i].datatype,
88 send_msgs[i].rank,
89 tag_offset + xt_mpi_tag_exchange_msg, comm),
90 comm);
91
92 xt_mpi_call(MPI_Waitall(nrecv, recv_request, MPI_STATUSES_IGNORE), comm);
93}
94
95
96static void
97xt_exchanger_irecv_send_s_exchange(const void *src_data, void *dst_data,
98 int nsend, int nrecv,
99 const struct Xt_redist_msg *send_msgs,
100 const struct Xt_redist_msg *recv_msgs,
101 int tag_offset, MPI_Comm comm) {
102
103 MPI_Request *recv_request
104 = xmalloc((size_t)nrecv * sizeof (*recv_request));
105
106 xt_exchanger_irecv_send_s_exchange_(src_data, dst_data,
107 nsend, nrecv,
108 send_msgs, recv_msgs,
109 tag_offset, comm,
110 recv_request);
111
112 free(recv_request);
113}
114
115#ifdef _OPENMP
116static void
117xt_exchanger_irecv_send_s_exchange_mt(const void *src_data, void *dst_data,
118 int nsend, int nrecv,
119 const struct Xt_redist_msg *send_msgs,
120 const struct Xt_redist_msg *recv_msgs,
121 int tag_offset, MPI_Comm comm,
122 Xt_exchanger_omp_share shared_req)
123{
124 MPI_Request *recv_request
126 int num_threads = omp_get_num_threads(),
127 tid = omp_get_thread_num();
128 int start_send = (nsend * tid) / num_threads,
129 nsend_ = (nsend * (tid+1)) / num_threads - start_send,
130 start_recv = (nrecv * tid) / num_threads,
131 nrecv_ = (nrecv * (tid+1)) / num_threads - start_recv;
133 dst_data,
134 nsend_, nrecv_,
135 send_msgs+start_send,
136 recv_msgs+start_recv,
137 tag_offset, comm,
138 recv_request+start_recv);
139}
140
141static void
142xt_exchanger_irecv_send_s_exchange_omp(const void *src_data, void *dst_data,
143 int nsend, int nrecv,
144 const struct Xt_redist_msg *send_msgs,
145 const struct Xt_redist_msg *recv_msgs,
146 int tag_offset, MPI_Comm comm) {
147
148 struct Xt_config_ conf = xt_default_config;
150 Xt_exchanger_omp_share shared_req
151 = (Xt_exchanger_omp_share)xt_request_msgs_alloc(nrecv, comm, &conf);
152#pragma omp parallel
153 xt_exchanger_irecv_send_s_exchange_mt(src_data, dst_data,
154 nsend, nrecv,
155 send_msgs, recv_msgs,
156 tag_offset, comm,
157 shared_req);
158 free(shared_req);
159}
160
161
162#endif
163
164
167 int nsend, int nrecv,
168 const struct Xt_redist_msg *send_msgs,
169 const struct Xt_redist_msg *recv_msgs,
170 MPI_Comm comm)
171{
172 (void)nsend;
173 (void)send_msgs;
174 (void)recv_msgs;
175 struct Xt_config_ conf = xt_default_config;
177 return (Xt_exchanger_omp_share)xt_request_msgs_alloc(nrecv, comm, &conf);
178}
179
180
182xt_exchanger_irecv_send_new(int nsend, int nrecv,
183 const struct Xt_redist_msg * send_msgs,
184 const struct Xt_redist_msg * recv_msgs,
185 MPI_Comm comm, int tag_offset, Xt_config config)
186{
191 static const xt_simple_s_exchange_func
192 s_exch_by_mthread_mode[] = {
194#ifdef _OPENMP
195 xt_exchanger_irecv_send_s_exchange_omp,
196#else
198#endif
199 };
200 int mthread_mode = xt_config_get_redist_mthread_mode(config);
202 nsend, nrecv, send_msgs, recv_msgs,
203 comm, tag_offset,
204 s_exch_by_mthread_mode[mthread_mode], 0,
206}
207
208/*
209 * Local Variables:
210 * c-basic-offset: 2
211 * coding: utf-8
212 * indent-tabs-mode: nil
213 * show-trailing-whitespace: t
214 * require-trailing-newline: t
215 * End:
216 */
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
struct Xt_config_ xt_default_config
Definition xt_config.c:204
void xt_config_set_redist_mthread_mode(Xt_config config, int mode)
Definition xt_config.c:347
struct Xt_config_ * Xt_config
Definition xt_config.h:58
@ XT_MT_OPENMP
Definition xt_config.h:142
int xt_config_get_redist_mthread_mode(Xt_config config)
Definition xt_config.c:340
implementation of configuration object
struct Xt_exchanger_omp_share_ * Xt_exchanger_omp_share
struct Xt_exchanger_ * Xt_exchanger
Xt_exchanger xt_exchanger_irecv_send_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_config config)
static void xt_exchanger_irecv_send_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, MPI_Request *recv_request)
static void xt_exchanger_irecv_send_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 Xt_exchanger_omp_share xt_exchanger_irecv_send_create_omp_share(int nsend, int nrecv, const struct Xt_redist_msg *send_msgs, const struct Xt_redist_msg *recv_msgs, MPI_Comm comm)
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, xt_simple_create_omp_share_func create_omp_share_func, Xt_config config)
void(* xt_simple_s_exchange_func)(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)
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
struct Xt_request_ * Xt_request
Definition xt_request.h:51
MPI_Request * xt_request_msgs_get_req_ptr(Xt_request request)
Xt_request xt_request_msgs_alloc(int n, MPI_Comm comm, Xt_config config)
internal interfaces for xt_request_msgs