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