Documentation 6b54b78464
Loading...
Searching...
No Matches
mpi_structure.hpp
Go to the documentation of this file.
1/*!
2 * \file mpi_structure.hpp
3 * \brief Headers of the mpi interface for generalized datatypes.
4 * The subroutines and functions are in the <i>mpi_structure.cpp</i> file.
5 * \author T. Albring
6 * \version 8.5.0 "Harrier"
7 *
8 * SU2 Project Website: https://su2code.github.io
9 *
10 * The SU2 Project is maintained by the SU2 Foundation
11 * (http://su2foundation.org)
12 *
13 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
14 *
15 * SU2 is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * SU2 is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29#pragma once
30
31#ifdef HAVE_MPI
32#include <map>
33#include "mpi.h"
34#endif
35
36#include <stdlib.h>
37#include "../basic_types/datatype_structure.hpp"
38#ifndef _MSC_VER
39#include <unistd.h>
40#else
41#include <io.h>
42#endif
43
44#include "omp_structure.hpp"
45
46/* Depending on the compiler, define the correct macro to get the current function name */
47
48#if defined(__GNUC__) || (defined(__ICC) && (__ICC >= 600))
49#define CURRENT_FUNCTION __PRETTY_FUNCTION__
50#elif defined(__FUNCSIG__)
51#define CURRENT_FUNCTION __FUNCSIG__
52#elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600))
53#define CURRENT_FUNCTION __FUNCTION__
54#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
55#define CURRENT_FUNCTION __func__
56#elif defined(__cplusplus) && (__cplusplus >= 201103)
57#define CURRENT_FUNCTION __func__
58#else
59#define CURRENT_FUNCTION "(unknown)"
60#endif
61
62#ifdef HAVE_MPI
63
64#ifdef USE_SINGLE_PRECISION
65#undef MPI_DOUBLE
66#define MPI_DOUBLE MPI_FLOAT
67#endif
68
69/*--- Depending on the datatype used, the correct MPI wrapper class is defined.
70 * For the default (double type) case this results in using the normal MPI routines. ---*/
71#if defined CODI_REVERSE_TYPE || defined CODI_FORWARD_TYPE
72
73#include <medi/medi.hpp>
74using namespace medi;
75
76#include <codi/tools/mpi/codiMpiTypes.hpp>
77
78class CMediMPIWrapper;
79using SU2_MPI = CMediMPIWrapper;
80
81using MediTypes = codi::CoDiMpiTypes<su2double>;
82using MediTool = MediTypes::Tool;
83
84extern MediTypes* mediTypes;
85#define AMPI_ADOUBLE ((medi::MpiTypeInterface*)mediTypes->MPI_TYPE)
86
87#else
88class CBaseMPIWrapper;
90#endif // defined CODI_REVERSE_TYPE || defined CODI_FORWARD_TYPE
91
92/*!
93 * \class CMPIWrapper
94 * \brief Class for defining the MPI wrapper routines; this class features as a base class for
95 * MPI interfaces for non-primitive dataypes e.g. used by AD, complex etc.
96 */
97class CBaseMPIWrapper {
98 public:
99 using Request = MPI_Request;
100 using Status = MPI_Status;
101 using Datatype = MPI_Datatype;
102 using Op = MPI_Op;
103 using Comm = MPI_Comm;
104 using Win = MPI_Win;
105
106 protected:
107 static int Rank, Size, MinRankError;
108 static Comm currentComm;
109 static bool winMinRankErrorInUse;
110 static Win winMinRankError;
111
112 public:
113 static void CopyData(const void* sendbuf, void* recvbuf, int size, Datatype datatype, int recvshift = 0,
114 int sendshift = 0);
115
116 static void Error(const std::string& ErrorMsg, const std::string& FunctionName);
117
118 static inline int GetRank() { return Rank; }
119
120 static inline int GetSize() { return Size; }
121
122 static inline void SetComm(Comm newComm) {
123 currentComm = newComm;
124 MPI_Comm_rank(currentComm, &Rank);
125 MPI_Comm_size(currentComm, &Size);
126
127 if (winMinRankErrorInUse) MPI_Win_free(&winMinRankError);
128 MinRankError = Size;
129 MPI_Win_create(&MinRankError, sizeof(int), sizeof(int), MPI_INFO_NULL, currentComm, &winMinRankError);
130 winMinRankErrorInUse = true;
131 }
132
133 static inline Comm GetComm() { return currentComm; }
134
135 static inline void Init(int* argc, char*** argv) {
136 MPI_Init(argc, argv);
137 MPI_Comm_rank(currentComm, &Rank);
138 MPI_Comm_size(currentComm, &Size);
139
140 MinRankError = Size;
141 MPI_Win_create(&MinRankError, sizeof(int), sizeof(int), MPI_INFO_NULL, currentComm, &winMinRankError);
142 winMinRankErrorInUse = true;
143 }
144
145 static inline void Init_thread(int* argc, char*** argv, int required, int* provided) {
146 MPI_Init_thread(argc, argv, required, provided);
147 MPI_Comm_rank(currentComm, &Rank);
148 MPI_Comm_size(currentComm, &Size);
149
150 MinRankError = Size;
151 MPI_Win_create(&MinRankError, sizeof(int), sizeof(int), MPI_INFO_NULL, currentComm, &winMinRankError);
152 winMinRankErrorInUse = true;
153 }
154
155 static inline void Comm_rank(Comm comm, int* rank) { MPI_Comm_rank(comm, rank); }
156
157 static inline void Comm_size(Comm comm, int* size) { MPI_Comm_size(comm, size); }
158
159 static inline void Finalize() {
160 if (winMinRankErrorInUse) MPI_Win_free(&winMinRankError);
161 MPI_Finalize();
162 }
163
164 static inline void Barrier(Comm comm) { MPI_Barrier(comm); }
165
166 static inline void Abort(Comm comm, int error) { MPI_Abort(comm, error); }
167
168 static inline void Get_count(const Status* status, Datatype datatype, int* count) {
169 MPI_Get_count(status, datatype, count);
170 }
171
172 static inline void Isend(const void* buf, int count, Datatype datatype, int dest, int tag, Comm comm,
173 Request* request) {
174 MPI_Isend(buf, count, datatype, dest, tag, comm, request);
175 }
176
177 static inline void Irecv(void* buf, int count, Datatype datatype, int dest, int tag, Comm comm, Request* request) {
178 MPI_Irecv(buf, count, datatype, dest, tag, comm, request);
179 }
180
181 static inline void Wait(Request* request, Status* status) { MPI_Wait(request, status); }
182
183 static inline int Request_free(Request* request) { return MPI_Request_free(request); }
184
185 static inline void Testall(int count, Request* array_of_requests, int* flag, Status* array_of_statuses) {
186 MPI_Testall(count, array_of_requests, flag, array_of_statuses);
187 }
188
189 static inline void Waitall(int nrequests, Request* request, Status* status) {
190 MPI_Waitall(nrequests, request, status);
191 }
192
193 static inline void Probe(int source, int tag, Comm comm, Status* status) { MPI_Probe(source, tag, comm, status); }
194
195 static inline void Send(const void* buf, int count, Datatype datatype, int dest, int tag, Comm comm) {
196 MPI_Send(buf, count, datatype, dest, tag, comm);
197 }
198
199 static inline void Recv(void* buf, int count, Datatype datatype, int dest, int tag, Comm comm, Status* status) {
200 MPI_Recv(buf, count, datatype, dest, tag, comm, status);
201 }
202
203 static inline void Bcast(void* buf, int count, Datatype datatype, int root, Comm comm) {
204 MPI_Bcast(buf, count, datatype, root, comm);
205 }
206
207 static inline void Reduce(const void* sendbuf, void* recvbuf, int count, Datatype datatype, Op op, int root,
208 Comm comm) {
209 MPI_Reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
210 }
211
212 static inline void Allreduce(const void* sendbuf, void* recvbuf, int count, Datatype datatype, Op op, Comm comm) {
213 MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm);
214 }
215
216 static inline void Gather(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
217 Datatype recvtype, int root, Comm comm) {
218 MPI_Gather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, root, comm);
219 }
220
221 static inline void Scatter(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
222 Datatype recvtype, int root, Comm comm) {
223 MPI_Scatter(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, root, comm);
224 }
225
226 static inline void Allgather(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
227 Datatype recvtype, Comm comm) {
228 MPI_Allgather(sendbuf, sendcnt, sendtype, recvbuf, recvcnt, recvtype, comm);
229 }
230
231 static inline void Allgatherv(const void* sendbuf, int sendcount, Datatype sendtype, void* recvbuf,
232 const int* recvcounts, const int* displs, Datatype recvtype, Comm comm) {
233 MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
234 }
235
236 static inline void Alltoall(const void* sendbuf, int sendcount, Datatype sendtype, void* recvbuf, int recvcount,
237 Datatype recvtype, Comm comm) {
238 MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
239 }
240
241 static inline void Alltoallv(const void* sendbuf, const int* sendcounts, const int* sdispls, Datatype sendtype,
242 void* recvbuf, const int* recvcounts, const int* recvdispls, Datatype recvtype,
243 Comm comm) {
244 MPI_Alltoallv(sendbuf, sendcounts, sdispls, sendtype, recvbuf, recvcounts, recvdispls, recvtype, comm);
245 }
246
247 static inline void Sendrecv(const void* sendbuf, int sendcnt, Datatype sendtype, int dest, int sendtag, void* recvbuf,
248 int recvcnt, Datatype recvtype, int source, int recvtag, Comm comm, Status* status) {
249 MPI_Sendrecv(sendbuf, sendcnt, sendtype, dest, sendtag, recvbuf, recvcnt, recvtype, source, recvtag, comm, status);
250 }
251
252 static inline void Reduce_scatter(const void* sendbuf, void* recvbuf, const int* recvcounts, Datatype datatype, Op op,
253 Comm comm) {
254 MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, datatype, op, comm);
255 }
256
257 static inline void Waitany(int nrequests, Request* request, int* index, Status* status) {
258 MPI_Waitany(nrequests, request, index, status);
259 }
260
261 static inline passivedouble Wtime(void) { return MPI_Wtime(); }
262};
263
264using SU2_Comm = MPI_Comm;
265
266#if defined CODI_REVERSE_TYPE || defined CODI_FORWARD_TYPE
267
268/*!
269 * \class CMediMPIWrapper
270 * \brief MPI wrapper functions for MediPack tool.
271 */
272
273class CMediMPIWrapper : public CBaseMPIWrapper {
274 public:
275 using Request = AMPI_Request;
276 using Status = AMPI_Status;
277
278 static inline void Init(int* argc, char*** argv) {
279 AMPI_Init(argc, argv);
280 mediTypes = new MediTypes();
281 AMPI_Comm_rank(convertComm(currentComm), &Rank);
282 AMPI_Comm_size(convertComm(currentComm), &Size);
283
284 MinRankError = Size;
285 MPI_Win_create(&MinRankError, sizeof(int), sizeof(int), MPI_INFO_NULL, currentComm, &winMinRankError);
286 winMinRankErrorInUse = true;
287 }
288
289 static inline void Init_thread(int* argc, char*** argv, int required, int* provided) {
290 AMPI_Init_thread(argc, argv, required, provided);
291 mediTypes = new MediTypes();
292 AMPI_Comm_rank(convertComm(currentComm), &Rank);
293 AMPI_Comm_size(convertComm(currentComm), &Size);
294
295 MinRankError = Size;
296 MPI_Win_create(&MinRankError, sizeof(int), sizeof(int), MPI_INFO_NULL, currentComm, &winMinRankError);
297 winMinRankErrorInUse = true;
298 }
299
300 static inline void Init_AMPI(void) {
301 AMPI_Init_common();
302 mediTypes = new MediTypes();
303 }
304
305 static inline void SetComm(Comm newComm) {
306 currentComm = newComm;
307 AMPI_Comm_rank(convertComm(currentComm), &Rank);
308 AMPI_Comm_size(convertComm(currentComm), &Size);
309
310 if (winMinRankErrorInUse) MPI_Win_free(&winMinRankError);
311 MinRankError = Size;
312 MPI_Win_create(&MinRankError, sizeof(int), sizeof(int), MPI_INFO_NULL, currentComm, &winMinRankError);
313 winMinRankErrorInUse = true;
314 }
315
316 static inline AMPI_Comm convertComm(MPI_Comm comm) { return comm; }
317
318 static inline AMPI_Datatype convertDatatype(MPI_Datatype datatype) {
319 if (datatype == MPI_DOUBLE) {
320 return AMPI_ADOUBLE;
321 } else if (datatype == MPI_SHORT) {
322 return AMPI_SHORT;
323 } else if (datatype == MPI_UNSIGNED_SHORT) {
324 return AMPI_UNSIGNED_SHORT;
325 } else if (datatype == MPI_LONG) {
326 return AMPI_LONG;
327 } else if (datatype == MPI_UNSIGNED_LONG) {
328 return AMPI_UNSIGNED_LONG;
329 } else if (datatype == MPI_SHORT) {
330 return AMPI_SHORT;
331 } else if (datatype == MPI_CHAR) {
332 return AMPI_CHAR;
333 } else if (datatype == MPI_INT) {
334 return AMPI_INT;
335 } else {
336 Error("Conversion not implemented", CURRENT_FUNCTION);
337 return AMPI_DOUBLE;
338 }
339 }
340
341 static inline AMPI_Op convertOp(MPI_Op op) {
342 if (MPI_SUM == op) {
343 return medi::AMPI_SUM;
344 } else if (MPI_PROD == op) {
345 return medi::AMPI_PROD;
346 } else if (MPI_MIN == op) {
347 return medi::AMPI_MIN;
348 } else if (MPI_MAX == op) {
349 return medi::AMPI_MAX;
350 } else if (MPI_BOR == op) {
351 return medi::AMPI_BOR;
352 } else {
353 Error("Conversion not implemented", CURRENT_FUNCTION);
354 return medi::AMPI_SUM;
355 }
356 }
357
358 static inline void Comm_rank(Comm comm, int* rank) { AMPI_Comm_rank(convertComm(comm), rank); }
359
360 static inline void Comm_size(Comm comm, int* size) { AMPI_Comm_size(convertComm(comm), size); }
361
362 static inline void Finalize() {
363 if (winMinRankErrorInUse) MPI_Win_free(&winMinRankError);
364
365 delete mediTypes;
366 AMPI_Finalize();
367 }
368
369 static inline void Barrier(Comm comm) { AMPI_Barrier(convertComm(comm)); }
370
371 static inline void Abort(Comm comm, int error) { AMPI_Abort(convertComm(comm), error); }
372
373 static inline void Get_count(const Status* status, Datatype datatype, int* count) {
374 AMPI_Get_count(status, convertDatatype(datatype), count);
375 }
376
377 static inline void Isend(const void* buf, int count, Datatype datatype, int dest, int tag, Comm comm,
378 Request* request) {
379 AMPI_Isend(buf, count, convertDatatype(datatype), dest, tag, convertComm(comm), request);
380 }
381
382 static inline void Irecv(void* buf, int count, Datatype datatype, int dest, int tag, Comm comm, Request* request) {
383 AMPI_Irecv(buf, count, convertDatatype(datatype), dest, tag, convertComm(comm), request);
384 }
385
386 static inline void Wait(SU2_MPI::Request* request, Status* status) { AMPI_Wait(request, status); }
387
388 static inline int Request_free(Request* request) { return AMPI_Request_free(request); }
389
390 static inline void Testall(int count, Request* array_of_requests, int* flag, Status* array_of_statuses) {
391 AMPI_Testall(count, array_of_requests, flag, array_of_statuses);
392 }
393
394 static inline void Waitall(int nrequests, Request* request, Status* status) {
395 AMPI_Waitall(nrequests, request, status);
396 }
397
398 static inline void Probe(int source, int tag, Comm comm, Status* status) {
399 AMPI_Probe(source, tag, convertComm(comm), status);
400 }
401
402 static inline void Send(const void* buf, int count, Datatype datatype, int dest, int tag, Comm comm) {
403 AMPI_Send(buf, count, convertDatatype(datatype), dest, tag, convertComm(comm));
404 }
405
406 static inline void Recv(void* buf, int count, Datatype datatype, int dest, int tag, Comm comm, Status* status) {
407 AMPI_Recv(buf, count, convertDatatype(datatype), dest, tag, convertComm(comm), status);
408 }
409
410 static inline void Bcast(void* buf, int count, Datatype datatype, int root, Comm comm) {
411 AMPI_Bcast(buf, count, convertDatatype(datatype), root, convertComm(comm));
412 }
413
414 static inline void Reduce(const void* sendbuf, void* recvbuf, int count, Datatype datatype, Op op, int root,
415 Comm comm) {
416 AMPI_Reduce(sendbuf, recvbuf, count, convertDatatype(datatype), convertOp(op), root, convertComm(comm));
417 }
418
419 static inline void Allreduce(const void* sendbuf, void* recvbuf, int count, Datatype datatype, Op op, Comm comm) {
420 AMPI_Allreduce(sendbuf, recvbuf, count, convertDatatype(datatype), convertOp(op), convertComm(comm));
421 }
422
423 static inline void Gather(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
424 Datatype recvtype, int root, Comm comm) {
425 AMPI_Gather(sendbuf, sendcnt, convertDatatype(sendtype), recvbuf, recvcnt, convertDatatype(recvtype), root,
426 convertComm(comm));
427 }
428
429 static inline void Scatter(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
430 Datatype recvtype, int root, Comm comm) {
431 AMPI_Scatter(sendbuf, sendcnt, convertDatatype(sendtype), recvbuf, recvcnt, convertDatatype(recvtype), root,
432 convertComm(comm));
433 }
434
435 static inline void Allgather(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
436 Datatype recvtype, Comm comm) {
437 AMPI_Allgather(sendbuf, sendcnt, convertDatatype(sendtype), recvbuf, recvcnt, convertDatatype(recvtype),
438 convertComm(comm));
439 }
440
441 static inline void Allgatherv(const void* sendbuf, int sendcount, Datatype sendtype, void* recvbuf,
442 const int* recvcounts, const int* displs, Datatype recvtype, Comm comm) {
443 AMPI_Allgatherv(sendbuf, sendcount, convertDatatype(sendtype), recvbuf, recvcounts, displs,
444 convertDatatype(recvtype), convertComm(comm));
445 }
446
447 static inline void Alltoall(const void* sendbuf, int sendcount, Datatype sendtype, void* recvbuf, int recvcount,
448 Datatype recvtype, Comm comm) {
449 AMPI_Alltoall(sendbuf, sendcount, convertDatatype(sendtype), recvbuf, recvcount, convertDatatype(recvtype),
450 convertComm(comm));
451 }
452
453 static inline void Alltoallv(const void* sendbuf, const int* sendcounts, const int* sdispls, Datatype sendtype,
454 void* recvbuf, const int* recvcounts, const int* recvdispls, Datatype recvtype,
455 Comm comm) {
456 AMPI_Alltoallv(sendbuf, sendcounts, sdispls, convertDatatype(sendtype), recvbuf, recvcounts, recvdispls,
457 convertDatatype(recvtype), comm);
458 }
459
460 static inline void Sendrecv(const void* sendbuf, int sendcnt, Datatype sendtype, int dest, int sendtag, void* recvbuf,
461 int recvcnt, Datatype recvtype, int source, int recvtag, Comm comm, Status* status) {
462 AMPI_Sendrecv(sendbuf, sendcnt, convertDatatype(sendtype), dest, sendtag, recvbuf, recvcnt,
463 convertDatatype(recvtype), source, recvtag, convertComm(comm), status);
464 }
465
466 static inline void Reduce_scatter(const void* sendbuf, void* recvbuf, const int* recvcounts, Datatype datatype, Op op,
467 Comm comm) {
468 if (datatype == MPI_DOUBLE) Error("Reduce_scatter not possible with MPI_DOUBLE", CURRENT_FUNCTION);
469 MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, datatype, op, comm);
470 }
471
472 static inline void Waitany(int nrequests, Request* request, int* index, Status* status) {
473 AMPI_Waitany(nrequests, request, index, status);
474 }
475};
476#endif
477
478#else // HAVE_MPI
479
480#define MPI_UNSIGNED_LONG 1
481#define MPI_LONG 2
482#define MPI_UNSIGNED_SHORT 3
483#define MPI_FLOAT 4
484#define MPI_DOUBLE 4
485#define MPI_ANY_SOURCE 5
486#define MPI_SUM 6
487#define MPI_CHAR 7
488#define MPI_SHORT 8
489#define MPI_MIN 9
490#define MPI_MAX 10
491#define MPI_INT 11
492#define MPI_PROD 12
493#define MPI_BOR 13
494#define MPI_STATUS_IGNORE nullptr
495
496/*!
497 * \class CMPIWrapper
498 * \brief Version for when there is no MPI.
499 */
500template <typename ScalarType>
502 public:
503 using Comm = int;
504 using Datatype = int;
505 using Request = int;
506 using Op = int;
507
508 struct Status {
512 };
513
514 private:
515 static int Rank, Size;
516 static Comm currentComm;
517
518 public:
519 static void CopyData(const void* sendbuf, void* recvbuf, int size, Datatype datatype, int recvshift = 0,
520 int sendshift = 0);
521
522 static void Error(const std::string& ErrorMsg, const std::string& FunctionName);
523
524 static inline int GetRank() { return Rank; }
525
526 static inline int GetSize() { return Size; }
527
528 static inline void SetComm(Comm newComm) { currentComm = newComm; }
529
530 static inline Comm GetComm() { return currentComm; }
531
532 static inline void Init(int* argc, char*** argv) {}
533
534 static inline void Init_thread(int* argc, char*** argv, int required, int* provided) { *provided = required; }
535
536 static inline void Barrier(Comm comm) {}
537
538 static inline void Abort(Comm comm, int error) { exit(EXIT_FAILURE); }
539
540 static inline void Comm_rank(Comm comm, int* rank) { *rank = 0; }
541
542 static inline void Comm_size(Comm comm, int* size) { *size = 1; }
543
544 static inline void Finalize() {}
545
546 static inline void Isend(const void* buf, int count, Datatype datatype, int dest, int tag, Comm comm,
547 Request* request) {}
548
549 static inline void Irecv(void* buf, int count, Datatype datatype, int source, int tag, Comm comm, Request* request) {}
550
551 static inline void Wait(Request* request, Status* status) {}
552
553 static inline int Request_free(Request* request) { return 0; }
554
555 static inline void Waitall(int nrequests, Request* request, Status* status) {}
556
557 static inline void Waitany(int nrequests, Request* request, int* index, Status* status) {}
558
559 static inline void Send(const void* buf, int count, Datatype datatype, int dest, int tag, Comm comm) {}
560
561 static inline void Recv(void* buf, int count, Datatype datatype, int dest, int tag, Comm comm, Status* status) {}
562
563 static inline void Bcast(void* buf, int count, Datatype datatype, int root, Comm comm) {}
564
565 static inline void Reduce(const void* sendbuf, void* recvbuf, int count, Datatype datatype, Op op, int root,
566 Comm comm) {
567 CopyData(sendbuf, recvbuf, count, datatype);
568 }
569
570 static inline void Allreduce(const void* sendbuf, void* recvbuf, int count, Datatype datatype, Op op, Comm comm) {
571 CopyData(sendbuf, recvbuf, count, datatype);
572 }
573
574 static inline void Gather(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
575 Datatype recvtype, int root, Comm comm) {
576 CopyData(sendbuf, recvbuf, sendcnt, sendtype);
577 }
578
579 static inline void Scatter(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
580 Datatype recvtype, int root, Comm comm) {
581 CopyData(sendbuf, recvbuf, sendcnt, sendtype);
582 }
583
584 static inline void Allgatherv(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, const int* recvcnt,
585 const int* displs, Datatype recvtype, Comm comm) {
586 CopyData(sendbuf, recvbuf, sendcnt, sendtype, displs[0]);
587 }
588
589 static inline void Allgather(const void* sendbuf, int sendcnt, Datatype sendtype, void* recvbuf, int recvcnt,
590 Datatype recvtype, Comm comm) {
591 CopyData(sendbuf, recvbuf, sendcnt, sendtype);
592 }
593
594 static inline void Sendrecv(const void* sendbuf, int sendcnt, Datatype sendtype, int dest, int sendtag, void* recvbuf,
595 int recvcnt, Datatype recvtype, int source, int recvtag, Comm comm, Status* status) {
596 CopyData(sendbuf, recvbuf, sendcnt, sendtype);
597 }
598
599 static inline void Reduce_scatter(const void* sendbuf, void* recvbuf, const int* recvcounts, Datatype datatype, Op op,
600 Comm comm) {
601 CopyData(sendbuf, recvbuf, recvcounts[0], datatype);
602 }
603
604 static inline void Alltoall(const void* sendbuf, int sendcount, Datatype sendtype, void* recvbuf, int recvcount,
605 Datatype recvtype, Comm comm) {
606 CopyData(sendbuf, recvbuf, recvcount, sendtype);
607 }
608
609 static inline void Alltoallv(const void* sendbuf, const int* sendcounts, const int* sdispls, Datatype sendtype,
610 void* recvbuf, const int* recvcounts, const int* recvdispls, Datatype recvtype,
611 Comm comm) {
612 CopyData(sendbuf, recvbuf, recvcounts[0], recvtype, recvdispls[0], sdispls[0]);
613 }
614
615 static inline void Probe(int source, int tag, Comm comm, Status* status) {}
616
617 static inline passivedouble Wtime(void) { return omp_get_wtime(); }
618};
619using SU2_Comm = int;
621
622#endif
623
624/*--- Select the appropriate MPI wrapper based on datatype, to use in templated classes. ---*/
625template <class T>
627 using W = SU2_MPI;
628};
629
630/*--- In AD we specialize for the passive wrapper. ---*/
631#if defined CODI_REVERSE_TYPE
632template <>
634#if defined HAVE_MPI
635 using W = CBaseMPIWrapper;
636#else
638#endif
639};
640#endif
641
642/*--- Specialize for the low precision type. ---*/
643#if defined(USE_MIXED_PRECISION) && !defined(USE_SINGLE_PRECISION)
644template <>
646#if defined HAVE_MPI
647 using W = CBaseMPIWrapper;
648#else
650#endif
651};
652#endif
Definition mpi_structure.hpp:501
static void Probe(int source, int tag, Comm comm, Status *status)
Definition mpi_structure.hpp:615
static void Allgatherv(const void *sendbuf, int sendcnt, Datatype sendtype, void *recvbuf, const int *recvcnt, const int *displs, Datatype recvtype, Comm comm)
Definition mpi_structure.hpp:584
static void Sendrecv(const void *sendbuf, int sendcnt, Datatype sendtype, int dest, int sendtag, void *recvbuf, int recvcnt, Datatype recvtype, int source, int recvtag, Comm comm, Status *status)
Definition mpi_structure.hpp:594
static void Init_thread(int *argc, char ***argv, int required, int *provided)
Definition mpi_structure.hpp:534
static int GetRank()
Definition mpi_structure.hpp:524
static void Send(const void *buf, int count, Datatype datatype, int dest, int tag, Comm comm)
Definition mpi_structure.hpp:559
static void Comm_size(Comm comm, int *size)
Definition mpi_structure.hpp:542
int Op
Definition mpi_structure.hpp:506
static void Reduce(const void *sendbuf, void *recvbuf, int count, Datatype datatype, Op op, int root, Comm comm)
Definition mpi_structure.hpp:565
static Comm GetComm()
Definition mpi_structure.hpp:530
static void Allreduce(const void *sendbuf, void *recvbuf, int count, Datatype datatype, Op op, Comm comm)
Definition mpi_structure.hpp:570
static void Finalize()
Definition mpi_structure.hpp:544
int Datatype
Definition mpi_structure.hpp:504
static void Bcast(void *buf, int count, Datatype datatype, int root, Comm comm)
Definition mpi_structure.hpp:563
int Request
Definition mpi_structure.hpp:505
static void SetComm(Comm newComm)
Definition mpi_structure.hpp:528
static void Abort(Comm comm, int error)
Definition mpi_structure.hpp:538
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
static void Init(int *argc, char ***argv)
Definition mpi_structure.hpp:532
int Comm
Definition mpi_structure.hpp:503
static void Irecv(void *buf, int count, Datatype datatype, int source, int tag, Comm comm, Request *request)
Definition mpi_structure.hpp:549
static void Wait(Request *request, Status *status)
Definition mpi_structure.hpp:551
static int Request_free(Request *request)
Definition mpi_structure.hpp:553
static void Comm_rank(Comm comm, int *rank)
Definition mpi_structure.hpp:540
static int GetSize()
Definition mpi_structure.hpp:526
static void Gather(const void *sendbuf, int sendcnt, Datatype sendtype, void *recvbuf, int recvcnt, Datatype recvtype, int root, Comm comm)
Definition mpi_structure.hpp:574
static void Alltoall(const void *sendbuf, int sendcount, Datatype sendtype, void *recvbuf, int recvcount, Datatype recvtype, Comm comm)
Definition mpi_structure.hpp:604
static void Waitall(int nrequests, Request *request, Status *status)
Definition mpi_structure.hpp:555
static passivedouble Wtime(void)
Definition mpi_structure.hpp:617
static void Isend(const void *buf, int count, Datatype datatype, int dest, int tag, Comm comm, Request *request)
Definition mpi_structure.hpp:546
static void Recv(void *buf, int count, Datatype datatype, int dest, int tag, Comm comm, Status *status)
Definition mpi_structure.hpp:561
static void Scatter(const void *sendbuf, int sendcnt, Datatype sendtype, void *recvbuf, int recvcnt, Datatype recvtype, int root, Comm comm)
Definition mpi_structure.hpp:579
static void Waitany(int nrequests, Request *request, int *index, Status *status)
Definition mpi_structure.hpp:557
static void CopyData(const void *sendbuf, void *recvbuf, int size, Datatype datatype, int recvshift=0, int sendshift=0)
Definition mpi_structure.cpp:144
static void Barrier(Comm comm)
Definition mpi_structure.hpp:536
static void Reduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcounts, Datatype datatype, Op op, Comm comm)
Definition mpi_structure.hpp:599
static void Allgather(const void *sendbuf, int sendcnt, Datatype sendtype, void *recvbuf, int recvcnt, Datatype recvtype, Comm comm)
Definition mpi_structure.hpp:589
static void Alltoallv(const void *sendbuf, const int *sendcounts, const int *sdispls, Datatype sendtype, void *recvbuf, const int *recvcounts, const int *recvdispls, Datatype recvtype, Comm comm)
Definition mpi_structure.hpp:609
double passivedouble
Definition code_config.hpp:129
passivedouble su2mixedfloat
Definition code_config.hpp:189
#define MPI_PROD
Definition mpi_structure.hpp:492
#define MPI_INT
Definition mpi_structure.hpp:491
int SU2_Comm
Definition mpi_structure.hpp:619
#define MPI_MAX
Definition mpi_structure.hpp:490
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59
#define MPI_UNSIGNED_LONG
Definition mpi_structure.hpp:480
#define MPI_SHORT
Definition mpi_structure.hpp:488
#define MPI_SUM
Definition mpi_structure.hpp:486
#define MPI_MIN
Definition mpi_structure.hpp:489
CBaseMPIWrapper< su2double > SU2_MPI
Definition mpi_structure.hpp:620
#define MPI_DOUBLE
Definition mpi_structure.hpp:484
#define MPI_LONG
Definition mpi_structure.hpp:481
#define MPI_CHAR
Definition mpi_structure.hpp:487
#define MPI_UNSIGNED_SHORT
Definition mpi_structure.hpp:482
#define MPI_BOR
Definition mpi_structure.hpp:493
OpenMP interface header, provides compatibility functions if the code is built without OpenMP support...
passivedouble omp_get_wtime()
Return the wall time.
Definition omp_structure.hpp:95
Definition mpi_structure.hpp:508
int MPI_TAG
Definition mpi_structure.hpp:509
int MPI_SOURCE
Definition mpi_structure.hpp:510
Status()
Definition mpi_structure.hpp:511
Definition mpi_structure.hpp:626
SU2_MPI W
Definition mpi_structure.hpp:627