MADNESS 0.10.1
stubmpi.h
Go to the documentation of this file.
1#ifndef MADNESS_STUBMPI_H
2#define MADNESS_STUBMPI_H
3
5#include <cstddef>
6#include <cstdlib>
7#include <cstring>
10
11typedef int MPI_Group;
12typedef int MPI_Request;
13typedef struct MPI_Status {
14 int count;
19
21#define MPI_STATUS_IGNORE ((MPI_Status *)1)
22#define MPI_STATUSES_IGNORE ((MPI_Status *)1)
23
24typedef int MPI_Comm;
25#define MPI_COMM_WORLD (0x44000000)
26#define MPI_UNDEFINED (-32766)
27
28typedef int MPI_Errhandler;
29
30typedef int MPI_Info;
31
32typedef std::ptrdiff_t MPI_Aint;
33
34/* MPI's error classes */
35/* these constants are consistent with MPICH2 mpi.h */
36#define MPI_SUCCESS 0 /* Successful return code */
37#define MPI_ERR_COUNT 2 /* Invalid count argument */
38#define MPI_ERR_COMM 5 /* Invalid communicator */
39#define MPI_ERR_ARG 12 /* Invalid argument */
40#define MPI_ERR_IN_STATUS 999999
41#define MPI_ERRORS_RETURN 888888
42#define MPI_MAX_ERROR_STRING 1024
43
44/* Results of the compare operations. */
45#define MPI_IDENT 0
46#define MPI_CONGRUENT 1
47#define MPI_SIMILAR 2
48#define MPI_UNEQUAL 3
49
50/* MPI null objects */
51#define MPI_COMM_NULL ((MPI_Comm)0x04000000)
52#define MPI_OP_NULL ((MPI_Op)0x18000000)
53#define MPI_GROUP_NULL ((MPI_Group)0x08000000)
54#define MPI_DATATYPE_NULL ((MPI_Datatype)0x0c000000)
55#define MPI_REQUEST_NULL ((MPI_Request)0x2c000000)
56#define MPI_ERRHANDLER_NULL ((MPI_Errhandler)0x14000000)
57
58/* MPI thread support levels */
59/* these constants are consistent with MPICH2 mpi.h */
60#define MPI_THREAD_SINGLE 0
61#define MPI_THREAD_FUNNELED 1
62#define MPI_THREAD_SERIALIZED 2
63#define MPI_THREAD_MULTIPLE 3
64#define MPI_COMM_TYPE_SHARED 4
65
66/* these constants are consistent with MPICH2 mpi.h */
67#define MPI_IN_PLACE ((void *) -1)
68#define MPI_PROC_NULL -1
69#define MPI_ANY_SOURCE -2
70#define MPI_ANY_TAG -1
71
72/* MPI data types */
73/* these constants are consistent with MPICH2 mpi.h */
74typedef int MPI_Datatype;
75#define MPI_CHAR ((MPI_Datatype)0x4c000101)
76#define MPI_SIGNED_CHAR ((MPI_Datatype)0x4c000118)
77#define MPI_UNSIGNED_CHAR ((MPI_Datatype)0x4c000102)
78#define MPI_BYTE ((MPI_Datatype)0x4c00010d)
79#define MPI_WCHAR ((MPI_Datatype)0x4c00040e)
80#define MPI_SHORT ((MPI_Datatype)0x4c000203)
81#define MPI_UNSIGNED_SHORT ((MPI_Datatype)0x4c000204)
82#define MPI_INT ((MPI_Datatype)0x4c000405)
83#define MPI_UNSIGNED ((MPI_Datatype)0x4c000406)
84#define MPI_LONG ((MPI_Datatype)0x4c000807)
85#define MPI_UNSIGNED_LONG ((MPI_Datatype)0x4c000808)
86#define MPI_FLOAT ((MPI_Datatype)0x4c00040a)
87#define MPI_DOUBLE ((MPI_Datatype)0x4c00080b)
88#define MPI_LONG_DOUBLE ((MPI_Datatype)0x4c00100c)
89#define MPI_LONG_LONG_INT ((MPI_Datatype)0x4c000809)
90#define MPI_UNSIGNED_LONG_LONG ((MPI_Datatype)0x4c000819)
91#define MPI_LONG_LONG ((MPI_Datatype)0x4c000809)
92
93// derived datatypes describe messages, and there are none to send here
95inline int MPI_Type_create_struct(int, const int[], const MPI_Aint[], const MPI_Datatype[], MPI_Datatype *) { return MPI_ERR_COMM; }
96inline int MPI_Type_commit(MPI_Datatype *) { return MPI_ERR_COMM; }
97inline int MPI_Type_free(MPI_Datatype *) { return MPI_ERR_COMM; }
98
99inline int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint *lb,
100 MPI_Aint *extent) {
101 switch(datatype) {
102 case MPI_CHAR:
103 *extent = sizeof(char); break;
104 case MPI_SIGNED_CHAR:
105 *extent = sizeof(signed char); break;
107 *extent = sizeof(unsigned char); break;
108 case MPI_BYTE:
109 *extent = 1; break;
110 case MPI_WCHAR:
111 *extent = sizeof(wchar_t); break;
112 case MPI_SHORT:
113 *extent = sizeof(short); break;
115 *extent = sizeof(unsigned short); break;
116 case MPI_INT:
117 *extent = sizeof(int); break;
118 case MPI_UNSIGNED:
119 *extent = sizeof(unsigned); break;
120 case MPI_LONG:
121 *extent = sizeof(long); break;
123 *extent = sizeof(unsigned long); break;
124 case MPI_FLOAT:
125 *extent = sizeof(float); break;
126 case MPI_DOUBLE:
127 *extent = sizeof(double); break;
128 case MPI_LONG_DOUBLE:
129 *extent = sizeof(long double); break;
130 case MPI_LONG_LONG_INT: // same as MPI_LONG_LONG
131 *extent = sizeof(long long int); break;
133 *extent = sizeof(unsigned long long); break;
134 default:
135 *extent = MPI_UNDEFINED;
136 }
137 *lb = 0;
138 return MPI_SUCCESS;
139}
140
141/* MPI Reduction operation */
142/* these constants are consistent with MPICH2 mpi.h */
143typedef int MPI_Op;
144#define MPI_MAX ((MPI_Op)0x58000001)
145#define MPI_MIN ((MPI_Op)0x58000002)
146#define MPI_SUM ((MPI_Op)0x58000003)
147#define MPI_PROD ((MPI_Op)0x58000004)
148#define MPI_LAND ((MPI_Op)0x58000005)
149#define MPI_BAND ((MPI_Op)0x58000006)
150#define MPI_LOR ((MPI_Op)0x58000007)
151#define MPI_BOR ((MPI_Op)0x58000008)
152#define MPI_LXOR ((MPI_Op)0x58000009)
153#define MPI_BXOR ((MPI_Op)0x5800000a)
154#define MPI_MINLOC ((MPI_Op)0x5800000b)
155#define MPI_MAXLOC ((MPI_Op)0x5800000c)
156#define MPI_REPLACE ((MPI_Op)0x5800000d)
157
158/* function type given to MPI_Op_create */
159typedef void (MPI_User_function) ( void * a,
160 void * b, int * len, MPI_Datatype * );
161
162inline int MPI_Group_translate_ranks(MPI_Group, int, const int [],
163 MPI_Group, int ranks2[]) {
164 ranks2[0] = 0;
165 return MPI_SUCCESS;
166}
167
168/* TODO The NO-OP implementation of may not be adequate. */
169inline int MPI_Group_incl(MPI_Group, int, const int [], MPI_Group *) {
170 return MPI_SUCCESS;
171}
172
173/* TODO The NO-OP implementation may not be adequate. */
175 return MPI_SUCCESS;
176}
177
178// Initialization and finalize functions
179inline int MPI_Init(int *, char ***) { return MPI_SUCCESS; }
180inline int MPI_Init_thread(int *, char ***, int, int *provided) { *provided = MADNESS_MPI_THREAD_LEVEL; return MPI_SUCCESS; }
181inline int MPI_Initialized(int* flag) { *flag = 1; return MPI_SUCCESS; }
182inline int MPI_Finalize() { return MPI_SUCCESS; }
183inline int MPI_Finalized(int* flag) { *flag = 0; return MPI_SUCCESS; }
184inline int MPI_Query_thread(int *provided) { *provided = MADNESS_MPI_THREAD_LEVEL; return MPI_SUCCESS; }
185
186// Buffer functions (do nothing since no messages may be sent)
187inline int MPI_Buffer_attach(void*, int) { return MPI_SUCCESS; }
188inline int MPI_Buffer_detach(void*, int*) { return MPI_SUCCESS; }
189
190inline int MPI_Test(MPI_Request *, int *flag, MPI_Status *) {
191 *flag = 1;
192 return MPI_SUCCESS;
193}
194
195inline int MPI_Testany(int, MPI_Request[], int* index, int *flag, MPI_Status*) {
196 *index = MPI_UNDEFINED;
197 *flag = 1;
198 return MPI_SUCCESS;
199}
200
201inline int MPI_Testsome(int, MPI_Request*, int *outcount, int*, MPI_Status*) {
202 *outcount = MPI_UNDEFINED;
203 return MPI_SUCCESS;
204}
205
206inline int MPI_Get_count(MPI_Status *, MPI_Datatype, int *count) {
207 *count = 0;
208 return MPI_SUCCESS;
209}
210
211// Communicator rank and size
212inline int MPI_Comm_rank(MPI_Comm, int* rank) { *rank = 0; return MPI_SUCCESS; }
213inline unsigned int MPI_Comm_size(MPI_Comm, int* size) { *size = 1; return MPI_SUCCESS; }
214
215// There is only one node so sending messages is not allowed. Always return MPI_ERR_COMM
216inline int MPI_Isend(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *) { return MPI_ERR_COMM; }
217inline int MPI_Issend(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *) { return MPI_ERR_COMM; }
218inline int MPI_Send(void*, int, MPI_Datatype, int, int, MPI_Comm) { return MPI_ERR_COMM; }
219inline int MPI_Ssend(void*, int, MPI_Datatype, int, int, MPI_Comm) { return MPI_ERR_COMM; }
220inline int MPI_Bsend(void*, int, MPI_Datatype, int, int, MPI_Comm) { return MPI_ERR_COMM; }
221inline int MPI_Irecv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request*) { return MPI_ERR_COMM; }
222inline int MPI_Recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*) { return MPI_ERR_COMM; }
223
224// Gather = copy
225inline int MPI_Gatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
226 void *recvbuf, const int recvcounts[], const int [], MPI_Datatype recvtype,
227 int, MPI_Comm) {
228 MPI_Aint recvtype_extent;
229 MPI_Aint recvtype_lb;
230 MPI_Type_get_extent(recvtype, &recvtype_lb, &recvtype_extent);
231 MADNESS_ASSERT(recvtype_lb == 0);
232 MPI_Aint sendtype_extent;
233 MPI_Aint sendtype_lb;
234 MPI_Type_get_extent(sendtype, &sendtype_lb, &sendtype_extent);
235 MADNESS_ASSERT(sendtype_lb == 0);
236 MADNESS_ASSERT(sendcount * sendtype_extent <= recvcounts[0] * recvtype_extent);
237 std::memcpy(recvbuf, sendbuf, sendcount * sendtype_extent);
238 return MPI_SUCCESS;
239}
240inline int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
241 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
242 const int recvcounts[1] = {recvcount};
243 const int displs[1] = {0};
244 return MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm);
245}
246
247// Bcast does nothing but return MPI_SUCCESS
248inline int MPI_Bcast(void*, int, MPI_Datatype, int, MPI_Comm) { return MPI_SUCCESS; }
249
250// Reduce does memcpy and returns MPI_SUCCESS
251inline int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, int, MPI_Comm) {
252 if(sendbuf != MPI_IN_PLACE) std::memcpy(recvbuf, sendbuf, count);
253 return MPI_SUCCESS;
254}
255inline int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, MPI_Comm) {
256 if(sendbuf != MPI_IN_PLACE) std::memcpy(recvbuf, sendbuf, count);
257 return MPI_SUCCESS;
258}
259
260inline int MPI_Comm_get_attr(MPI_Comm, int, void*, int*) { return MPI_ERR_COMM; }
261
262inline int MPI_Comm_split(MPI_Comm, int, int, MPI_Comm *newcomm) {
263 //*newcomm = MPI_COMM_NULL;
264 *newcomm = MPI_COMM_WORLD; // So that can successfully split a 1 process communicator
265 return MPI_SUCCESS;
266}
267
268inline int MPI_Comm_split_type(MPI_Comm comm, int split_type, int, MPI_Info, MPI_Comm *newcomm) {
269 *newcomm = (split_type == MPI_UNDEFINED) ? MPI_COMM_NULL : comm;
270 return MPI_SUCCESS;
271}
272
273inline int MPI_Abort(MPI_Comm, int code) { exit(code); return MPI_SUCCESS; }
274
275inline int MPI_Barrier(MPI_Comm) { return MPI_SUCCESS; }
276
278 //*newcomm = MPI_COMM_NULL;
279 *newcomm = MPI_COMM_WORLD; // So that can successfully split a 1 process communicator
280 return MPI_SUCCESS;
281}
282
283inline int MPI_Comm_group(MPI_Comm, MPI_Group* group) {
284 *group = MPI_GROUP_NULL;
285 return MPI_SUCCESS;
286}
287
288inline int MPI_Comm_free(MPI_Comm * comm) {
289 *comm = MPI_COMM_NULL;
290 return MPI_SUCCESS;
291}
292
293inline int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result) {
294 if (comm1 == comm2) {
295 *result = MPI_IDENT;
296 } else {
297 *result = MPI_UNEQUAL;
298 }
299 return MPI_SUCCESS;
300}
301
302
303inline int MPI_Error_string(int errorcode, char *string, int *resultlen) {
304 switch(errorcode) {
305 case MPI_SUCCESS:
306 *resultlen = 8;
307 std::strncpy(string, "Success", *resultlen);
308 break;
309 case MPI_ERR_COMM:
310 *resultlen = 21;
311 std::strncpy(string, "Invalid communicator", *resultlen);
312 break;
313 case MPI_ERR_ARG:
314 *resultlen = 17;
315 std::strncpy(string, "Invalid argument", *resultlen);
316 break;
317 default:
318 return MPI_ERR_ARG;
319 break;
320 }
321
322 return MPI_SUCCESS;
323}
324
326
327inline double MPI_Wtime() { return madness::wall_time(); }
328
330 return MPI_SUCCESS;
331}
332
333inline int MPI_Op_free(MPI_Op *) {
334 return MPI_SUCCESS;
335}
336
337inline int MPI_Info_create (MPI_Info *) { return MPI_SUCCESS; }
338inline int MPI_Info_free (MPI_Info *) { return MPI_SUCCESS; }
339
340#endif
Macros and tools pertaining to the configuration of MADNESS.
Defines madness::MadnessException for exception handling.
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
static const double b
Definition nonlinschro.cc:119
static const double a
Definition nonlinschro.cc:118
Definition stubmpi.h:13
int count
Definition stubmpi.h:14
int cancelled
Definition stubmpi.h:15
int MPI_SOURCE
Definition stubmpi.h:16
int MPI_TAG
Definition stubmpi.h:17
int MPI_ERROR
Definition stubmpi.h:18
#define MPI_SUCCESS
Definition stubmpi.h:36
#define MPI_SIGNED_CHAR
Definition stubmpi.h:76
int MPI_Ssend(void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition stubmpi.h:219
int MPI_Type_contiguous(int, MPI_Datatype, MPI_Datatype *)
Definition stubmpi.h:94
int MPI_Buffer_detach(void *, int *)
Definition stubmpi.h:188
int MPI_Bcast(void *, int, MPI_Datatype, int, MPI_Comm)
Definition stubmpi.h:248
#define MPI_ERR_COMM
Definition stubmpi.h:38
#define MPI_COMM_NULL
Definition stubmpi.h:51
int MPI_Error_string(int errorcode, char *string, int *resultlen)
Definition stubmpi.h:303
int MPI_Isend(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition stubmpi.h:216
int MPI_Op
Definition stubmpi.h:143
int MPI_Request
Definition stubmpi.h:12
#define MPI_WCHAR
Definition stubmpi.h:79
void MPI_User_function(void *a, void *b, int *len, MPI_Datatype *)
Definition stubmpi.h:159
int MPI_Gatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int recvcounts[], const int[], MPI_Datatype recvtype, int, MPI_Comm)
Definition stubmpi.h:225
int MPI_Op_create(MPI_User_function *, int, MPI_Op *)
Definition stubmpi.h:329
int MPI_Errhandler
Definition stubmpi.h:28
std::ptrdiff_t MPI_Aint
Definition stubmpi.h:32
#define MPI_COMM_WORLD
Definition stubmpi.h:25
int MPI_Group
Definition stubmpi.h:11
int MPI_Type_free(MPI_Datatype *)
Definition stubmpi.h:97
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
Definition stubmpi.h:293
#define MPI_UNSIGNED_LONG_LONG
Definition stubmpi.h:90
int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint *lb, MPI_Aint *extent)
Definition stubmpi.h:99
#define MPI_INT
Definition stubmpi.h:82
int MPI_Finalize()
Definition stubmpi.h:182
#define MPI_FLOAT
Definition stubmpi.h:86
int MPI_Query_thread(int *provided)
Definition stubmpi.h:184
int MPI_Comm_create(MPI_Comm, MPI_Group, MPI_Comm *newcomm)
Definition stubmpi.h:277
int MPI_Finalized(int *flag)
Definition stubmpi.h:183
#define MPI_BYTE
Definition stubmpi.h:78
int MPI_Recv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *)
Definition stubmpi.h:222
int MPI_Comm
Definition stubmpi.h:24
#define MPI_IDENT
Definition stubmpi.h:45
int MPI_Issend(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition stubmpi.h:217
int MPI_Info_create(MPI_Info *)
Definition stubmpi.h:337
int MPI_Init_thread(int *, char ***, int, int *provided)
Definition stubmpi.h:180
#define MPI_ERR_ARG
Definition stubmpi.h:39
#define MPI_UNEQUAL
Definition stubmpi.h:48
#define MPI_UNSIGNED_CHAR
Definition stubmpi.h:77
int MPI_Info_free(MPI_Info *)
Definition stubmpi.h:338
unsigned int MPI_Comm_size(MPI_Comm, int *size)
Definition stubmpi.h:213
int MPI_Buffer_attach(void *, int)
Definition stubmpi.h:187
#define MPI_GROUP_NULL
Definition stubmpi.h:53
int MPI_Abort(MPI_Comm, int code)
Definition stubmpi.h:273
int MPI_Comm_split(MPI_Comm, int, int, MPI_Comm *newcomm)
Definition stubmpi.h:262
#define MPI_UNSIGNED_LONG
Definition stubmpi.h:85
int MPI_Group_translate_ranks(MPI_Group, int, const int[], MPI_Group, int ranks2[])
Definition stubmpi.h:162
#define MPI_SHORT
Definition stubmpi.h:80
int MPI_Comm_rank(MPI_Comm, int *rank)
Definition stubmpi.h:212
int MPI_Comm_set_errhandler(MPI_Comm, MPI_Errhandler)
Definition stubmpi.h:325
int MPI_Comm_free(MPI_Comm *comm)
Definition stubmpi.h:288
double MPI_Wtime()
Definition stubmpi.h:327
int MPI_Comm_get_attr(MPI_Comm, int, void *, int *)
Definition stubmpi.h:260
int MPI_Info
Definition stubmpi.h:30
#define MPI_DOUBLE
Definition stubmpi.h:87
int MPI_Type_commit(MPI_Datatype *)
Definition stubmpi.h:96
#define MPI_LONG
Definition stubmpi.h:84
int MPI_Group_free(MPI_Group *)
Definition stubmpi.h:174
int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, MPI_Comm)
Definition stubmpi.h:255
#define MPI_LONG_LONG_INT
Definition stubmpi.h:89
#define MPI_IN_PLACE
Definition stubmpi.h:67
int MPI_Bsend(void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition stubmpi.h:220
int MPI_Irecv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition stubmpi.h:221
int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
Definition stubmpi.h:240
#define MPI_CHAR
Definition stubmpi.h:75
#define MPI_UNSIGNED
Definition stubmpi.h:83
int MPI_Comm_group(MPI_Comm, MPI_Group *group)
Definition stubmpi.h:283
#define MPI_UNSIGNED_SHORT
Definition stubmpi.h:81
int MPI_Barrier(MPI_Comm)
Definition stubmpi.h:275
int MPI_Group_incl(MPI_Group, int, const int[], MPI_Group *)
Definition stubmpi.h:169
int MPI_Testsome(int, MPI_Request *, int *outcount, int *, MPI_Status *)
Definition stubmpi.h:201
int MPI_Get_count(MPI_Status *, MPI_Datatype, int *count)
Definition stubmpi.h:206
int MPI_Type_create_struct(int, const int[], const MPI_Aint[], const MPI_Datatype[], MPI_Datatype *)
Definition stubmpi.h:95
int MPI_Initialized(int *flag)
Definition stubmpi.h:181
int MPI_Init(int *, char ***)
Definition stubmpi.h:179
int MPI_Send(void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition stubmpi.h:218
#define MPI_LONG_DOUBLE
Definition stubmpi.h:88
int MPI_Test(MPI_Request *, int *flag, MPI_Status *)
Definition stubmpi.h:190
int MPI_Op_free(MPI_Op *)
Definition stubmpi.h:333
int MPI_Comm_split_type(MPI_Comm comm, int split_type, int, MPI_Info, MPI_Comm *newcomm)
Definition stubmpi.h:268
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, int, MPI_Comm)
Definition stubmpi.h:251
#define MPI_UNDEFINED
Definition stubmpi.h:26
int MPI_Datatype
Definition stubmpi.h:74
int MPI_Testany(int, MPI_Request[], int *index, int *flag, MPI_Status *)
Definition stubmpi.h:195
Wrappers around platform dependent timers and performance info.