core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
mpi_stub.hpp
Go to the documentation of this file.
1// core -- single-rank no-MPI stub. When the library is built without MPI (PECLET_CORE_NO_MPI), the
2// grid solver runs as ONE block: every ghost cell is a periodic self-copy onto the same block, so
3// there are no remote neighbours. The only collectives ever EXECUTED at size 1 are the trivial ones
4// -- rank=0, size=1, Allreduce/Bcast are local identities. The point-to-point and
5// neighbourhood-collective calls exist only so the single code path compiles and links; they are
6// never reached at size 1.
7//
8// This keeps "one code": the same GridHaloTopology / GridHalo / NbxEngine run, with MPI replaced by
9// these stubs. Build WITH MPI (the default) and this header is never included -- see
10// peclet/core/common/mpi.hpp.
11#pragma once
12
13#include <cstdlib>
14#include <cstring>
15
16using MPI_Comm = int;
17using MPI_Request = int;
18using MPI_Datatype = int; // value doubles as the element byte size (so Allreduce can memcpy)
19using MPI_Op = int;
20using MPI_Info = int;
21struct MPI_Status {
24};
25
26#define MPI_COMM_WORLD 0
27#define MPI_COMM_NULL (-1)
28#define MPI_REQUEST_NULL 0
29#define MPI_INFO_NULL 0
30#define MPI_STATUS_IGNORE (static_cast<MPI_Status*>(nullptr))
31#define MPI_STATUSES_IGNORE (static_cast<MPI_Status*>(nullptr))
32#define MPI_ANY_SOURCE (-1)
33#define MPI_UNDEFINED (-32766)
34#define MPI_UNWEIGHTED (static_cast<int*>(nullptr))
35#define MPI_SUCCESS 0
36// datatypes carry their byte size (MPI_Allreduce copies count * datatype bytes)
37#define MPI_BYTE 1
38#define MPI_INT 4
39#define MPI_LONG 8
40#define MPI_DOUBLE 8
41// reduction ops are ignored: at size 1 the local value IS the global value
42#define MPI_SUM 0
43#define MPI_MAX 1
44#define MPI_MIN 2
45#define MPI_LAND 3
46
47inline int MPI_Init(int*, char***) {
48 return MPI_SUCCESS;
49}
50inline int MPI_Initialized(int* f) {
51 *f = 1;
52 return MPI_SUCCESS;
53} // pretend initialised (no real MPI)
54inline int MPI_Finalize() {
55 return MPI_SUCCESS;
56}
57inline int MPI_Finalized(int* f) {
58 *f = 0;
59 return MPI_SUCCESS;
60}
61inline int MPI_Abort(MPI_Comm, int code) {
62 std::abort();
63 return code;
64}
65inline int MPI_Comm_rank(MPI_Comm, int* r) {
66 *r = 0;
67 return MPI_SUCCESS;
68}
69inline int MPI_Comm_size(MPI_Comm, int* s) {
70 *s = 1;
71 return MPI_SUCCESS;
72}
73inline int MPI_Comm_free(MPI_Comm*) {
74 return MPI_SUCCESS;
75}
76inline int MPI_Barrier(MPI_Comm) {
77 return MPI_SUCCESS;
78}
79// single rank: the local contribution is already the global result.
80inline int MPI_Allreduce(const void* sbuf, void* rbuf, int count, MPI_Datatype dt, MPI_Op,
81 MPI_Comm) {
82 if (sbuf != rbuf)
83 std::memcpy(rbuf, sbuf, static_cast<size_t>(count) * static_cast<size_t>(dt));
84 return MPI_SUCCESS;
85}
86inline int MPI_Bcast(void*, int, MPI_Datatype, int, MPI_Comm) {
87 return MPI_SUCCESS;
88} // 1 rank: no-op
89
90// --- never reached at size 1 (no remote neighbours); present only to compile/link the one code
91// path ---
92inline int MPI_Send(const void*, int, MPI_Datatype, int, int, MPI_Comm) {
93 return MPI_SUCCESS;
94}
95inline int MPI_Recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*) {
96 return MPI_SUCCESS;
97}
98inline int MPI_Isend(const void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request*) {
99 return MPI_SUCCESS;
100}
101inline int MPI_Irecv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request*) {
102 return MPI_SUCCESS;
103}
104inline int MPI_Issend(const void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request*) {
105 return MPI_SUCCESS;
106}
107inline int MPI_Iprobe(int, int, MPI_Comm, int* flag, MPI_Status*) {
108 *flag = 0;
109 return MPI_SUCCESS;
110}
111inline int MPI_Get_count(const MPI_Status*, MPI_Datatype, int* c) {
112 *c = 0;
113 return MPI_SUCCESS;
114}
115inline int MPI_Test(MPI_Request*, int* flag, MPI_Status*) {
116 *flag = 1;
117 return MPI_SUCCESS;
118}
119inline int MPI_Testall(int, MPI_Request*, int* flag, MPI_Status*) {
120 *flag = 1;
121 return MPI_SUCCESS;
122}
124 return MPI_SUCCESS;
125}
126inline int MPI_Waitall(int, MPI_Request*, MPI_Status*) {
127 return MPI_SUCCESS;
128}
129inline int MPI_Waitany(int, MPI_Request*, int* idx, MPI_Status*) {
130 *idx = MPI_UNDEFINED;
131 return MPI_SUCCESS;
132}
134 return MPI_SUCCESS;
135}
136inline int MPI_Dist_graph_create_adjacent(MPI_Comm c, int, const int*, const int*, int, const int*,
137 const int*, MPI_Info, int, MPI_Comm* out) {
138 *out = c;
139 return MPI_SUCCESS;
140}
141inline int MPI_Neighbor_alltoallv(const void*, const int*, const int*, MPI_Datatype, void*,
142 const int*, const int*, MPI_Datatype, MPI_Comm) {
143 return MPI_SUCCESS;
144}
#define MPI_SUCCESS
Definition mpi_stub.hpp:35
int MPI_Comm_size(MPI_Comm, int *s)
Definition mpi_stub.hpp:69
int MPI_Bcast(void *, int, MPI_Datatype, int, MPI_Comm)
Definition mpi_stub.hpp:86
int MPI_Testall(int, MPI_Request *, int *flag, MPI_Status *)
Definition mpi_stub.hpp:119
int MPI_Allreduce(const void *sbuf, void *rbuf, int count, MPI_Datatype dt, MPI_Op, MPI_Comm)
Definition mpi_stub.hpp:80
int MPI_Comm
Definition mpi_stub.hpp:16
int MPI_Request
Definition mpi_stub.hpp:17
int MPI_Waitall(int, MPI_Request *, MPI_Status *)
Definition mpi_stub.hpp:126
int MPI_Finalize()
Definition mpi_stub.hpp:54
int MPI_Comm_free(MPI_Comm *)
Definition mpi_stub.hpp:73
int MPI_Op
Definition mpi_stub.hpp:19
int MPI_Iprobe(int, int, MPI_Comm, int *flag, MPI_Status *)
Definition mpi_stub.hpp:107
int MPI_Recv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *)
Definition mpi_stub.hpp:95
int MPI_Waitany(int, MPI_Request *, int *idx, MPI_Status *)
Definition mpi_stub.hpp:129
int MPI_Ibarrier(MPI_Comm, MPI_Request *)
Definition mpi_stub.hpp:133
int MPI_Isend(const void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition mpi_stub.hpp:98
int MPI_Get_count(const MPI_Status *, MPI_Datatype, int *c)
Definition mpi_stub.hpp:111
int MPI_Finalized(int *f)
Definition mpi_stub.hpp:57
int MPI_Wait(MPI_Request *, MPI_Status *)
Definition mpi_stub.hpp:123
int MPI_Abort(MPI_Comm, int code)
Definition mpi_stub.hpp:61
int MPI_Issend(const void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition mpi_stub.hpp:104
int MPI_Comm_rank(MPI_Comm, int *r)
Definition mpi_stub.hpp:65
int MPI_Initialized(int *f)
Definition mpi_stub.hpp:50
int MPI_Send(const void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition mpi_stub.hpp:92
int MPI_Irecv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition mpi_stub.hpp:101
int MPI_Barrier(MPI_Comm)
Definition mpi_stub.hpp:76
int MPI_Datatype
Definition mpi_stub.hpp:18
int MPI_Init(int *, char ***)
Definition mpi_stub.hpp:47
int MPI_Info
Definition mpi_stub.hpp:20
int MPI_Neighbor_alltoallv(const void *, const int *, const int *, MPI_Datatype, void *, const int *, const int *, MPI_Datatype, MPI_Comm)
Definition mpi_stub.hpp:141
int MPI_Test(MPI_Request *, int *flag, MPI_Status *)
Definition mpi_stub.hpp:115
int MPI_Dist_graph_create_adjacent(MPI_Comm c, int, const int *, const int *, int, const int *, const int *, MPI_Info, int, MPI_Comm *out)
Definition mpi_stub.hpp:136
#define MPI_UNDEFINED
Definition mpi_stub.hpp:33
int MPI_SOURCE
Definition mpi_stub.hpp:22