Yet Another eXchange Tool 0.11.3
Loading...
Searching...
No Matches
xt_request_msgs.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 <assert.h>
51#include <stdlib.h>
52#include <string.h>
53
54#include <mpi.h>
55#ifdef _OPENMP
56#include <omp.h>
57#endif
58
59#include "core/ppm_xfuncs.h"
60#include "xt/xt_mpi.h"
61#include "xt/xt_config.h"
62#include "xt/xt_request_msgs.h"
64#include "xt_mpi_internal.h"
65#include "xt_config_internal.h"
66#include "xt_request_internal.h"
67
68static void xt_request_msgs_wait(Xt_request request);
69static int xt_request_msgs_test(Xt_request request);
70
71#ifdef _OPENMP
72static void xt_request_msgs_wait_omp(Xt_request request);
73static int xt_request_msgs_test_omp(Xt_request request);
74#endif
75
81#ifdef _OPENMP
82 , request_msgs_auto_omp_vtable = {
83 .wait = xt_request_msgs_wait_omp,
84 .test = xt_request_msgs_test_omp,
85};
86#endif
87 ;
88
90
92
94 int n;
96 MPI_Request requests[];
97};
98
101{
102 Xt_request_msgs request
103 = xmalloc(sizeof(*request) + (size_t)n * sizeof(MPI_Request) +
104 (size_t)n * sizeof(int));
105#ifndef _OPENMP
106 (void)config;
107#else
108 int mthread_mode = xt_config_get_redist_mthread_mode(config);
109 if (mthread_mode == XT_MT_OPENMP)
110 request->vtable = &request_msgs_auto_omp_vtable;
111 else
112#endif
113 request->vtable = &request_msgs_vtable;
114 request->n = n;
115 request->comm = comm;
116 return (Xt_request)request;
117}
118
119
122 const MPI_Request requests[n],
123 MPI_Comm comm)
124{
125 return xt_request_msgs_custom_new(n, requests, comm, &xt_default_config);
126}
127
130 const MPI_Request requests[n],
131 MPI_Comm comm,
132 Xt_config config)
133{
134 assert(n >= 0);
135 Xt_request_msgs request
136 = (Xt_request_msgs)xt_request_msgs_alloc(n, comm, config);
137
138 memcpy(request->requests, requests, (size_t)n * sizeof(*request->requests));
139
140 return (Xt_request)request;
141}
142
143MPI_Request *
145{
146 Xt_request_msgs request_msgs = (Xt_request_msgs)request;
147#ifdef _OPENMP
148 assert(request->vtable == &request_msgs_vtable
149 || request->vtable == &request_msgs_auto_omp_vtable);
150#else
151 assert(request->vtable == &request_msgs_vtable);
152#endif
153 return request_msgs->requests;
154}
155
156
157static void xt_request_msgs_wait(Xt_request request) {
158
159 Xt_request_msgs request_msgs = (Xt_request_msgs)request;
160
161#if __GNUC__ >= 11 && __GNUC__ <= 13 && defined MPICH
162 /* GCC 11 has no means to specify that the special value pointer
163 * MPI_STATUSES_IGNORE does not need to point to something of size > 0 */
164#pragma GCC diagnostic push
165#pragma GCC diagnostic ignored "-Wstringop-overread"
166#pragma GCC diagnostic ignored "-Wstringop-overflow"
167#endif
168 xt_mpi_call(MPI_Waitall(request_msgs->n, request_msgs->requests,
169 MPI_STATUSES_IGNORE), request_msgs->comm);
170#if __GNUC__ >= 11 && __GNUC__ <= 13 && defined MPICH
171#pragma GCC diagnostic pop
172#endif
173
174 free(request_msgs);
175}
176
177static int xt_request_msgs_test(Xt_request request) {
178
179 Xt_request_msgs request_msgs = (Xt_request_msgs)request;
180
181 size_t n = (size_t)request_msgs->n;
182 int *ops_completed_buffer = (int *)(request_msgs->requests + n);
183 int flag = xt_mpi_test_some(&(request_msgs->n), request_msgs->requests,
184 ops_completed_buffer, request_msgs->comm);
185
186 if (flag) free(request_msgs);
187
188 return flag;
189}
190
191#ifdef _OPENMP
192static void
193xt_request_msgs_wait_omp(Xt_request request)
194{
195#pragma omp parallel
196 {
197 Xt_request_msgs request_msgs = (Xt_request_msgs)request;
198
199#if __GNUC__ >= 11 && __GNUC__ <= 13 && defined MPICH
200 /* GCC 11 has no means to specify that the special value pointer
201 * MPI_STATUSES_IGNORE does not need to point to something of size > 0 */
202#pragma GCC diagnostic push
203#pragma GCC diagnostic ignored "-Wstringop-overread"
204#pragma GCC diagnostic ignored "-Wstringop-overflow"
205#endif
206 int num_threads = omp_get_num_threads(),
207 tid = omp_get_thread_num();
208 int nreq = request_msgs->n,
209 start_req = (nreq * tid) / num_threads,
210 nreq_ = (nreq * (tid+1)) / num_threads - start_req;
211 xt_mpi_call(MPI_Waitall(nreq_, request_msgs->requests+start_req,
212 MPI_STATUSES_IGNORE), request_msgs->comm);
213#if __GNUC__ >= 11 && __GNUC__ <= 13 && defined MPICH
214#pragma GCC diagnostic pop
215#endif
216 }
217
218 free(request);
219}
220
221static int
222xt_request_msgs_test_omp(Xt_request request) {
223
224 bool flag = true;
225#pragma omp parallel reduction(&: flag)
226 {
227 Xt_request_msgs request_msgs = (Xt_request_msgs)request;
228 size_t n = (size_t)request_msgs->n;
229 int *ops_completed_buffer = (int *)(request_msgs->requests + n);
230
231 flag &= xt_mpi_test_some_mt(&request_msgs->n, request_msgs->requests,
232 ops_completed_buffer, request_msgs->comm);
233 }
234 if (flag) free(request);
235
236 return flag;
237}
238#endif
239
240/*
241 * Local Variables:
242 * c-basic-offset: 2
243 * coding: utf-8
244 * indent-tabs-mode: nil
245 * show-trailing-whitespace: t
246 * require-trailing-newline: t
247 * End:
248 */
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
const struct Xt_request_vtable * vtable
MPI_Request requests[]
const struct Xt_request_vtable * vtable
void(* wait)(Xt_request request)
struct Xt_config_ xt_default_config
Definition xt_config.c:204
opaque configuration object for settings where the default needs to be overridden
@ 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
bool xt_mpi_test_some(int *restrict num_req, MPI_Request *restrict req, int *restrict ops_completed, MPI_Comm comm)
Definition xt_mpi.c:415
utility routines for MPI
#define xt_mpi_call(call, comm)
Definition xt_mpi.h:68
Provide non-public declarations common to all requests.
static int xt_request_msgs_test(Xt_request request)
Xt_request xt_request_msgs_custom_new(int n, const MPI_Request requests[n], MPI_Comm comm, Xt_config config)
MPI_Request * xt_request_msgs_get_req_ptr(Xt_request request)
static const struct Xt_request_vtable request_msgs_vtable
static void xt_request_msgs_wait(Xt_request request)
Xt_request xt_request_msgs_alloc(int n, MPI_Comm comm, Xt_config config)
Xt_request xt_request_msgs_new(int n, const MPI_Request requests[n], MPI_Comm comm)
struct Xt_request_msgs_ * Xt_request_msgs
internal interfaces for xt_request_msgs