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>
8 #include <madness/world/timers.h>
9 
10 typedef int MPI_Group;
11 typedef int MPI_Request;
12 typedef struct MPI_Status {
13  int count;
14  int cancelled;
16  int MPI_TAG;
17  int MPI_ERROR;
18 
20 #define MPI_STATUS_IGNORE ((MPI_Status *)1)
21 #define MPI_STATUSES_IGNORE ((MPI_Status *)1)
22 
23 typedef int MPI_Comm;
24 #define MPI_COMM_WORLD (0x44000000)
25 #define MPI_UNDEFINED (-32766)
26 
27 typedef int MPI_Errhandler;
28 
29 typedef int MPI_Info;
30 
31 /* MPI's error classes */
32 /* these constants are consistent with MPICH2 mpi.h */
33 #define MPI_SUCCESS 0 /* Successful return code */
34 #define MPI_ERR_COMM 5 /* Invalid communicator */
35 #define MPI_ERR_ARG 12 /* Invalid argument */
36 #define MPI_ERR_IN_STATUS 999999
37 #define MPI_ERRORS_RETURN 888888
38 #define MPI_MAX_ERROR_STRING 1024
39 
40 /* Results of the compare operations. */
41 #define MPI_IDENT 0
42 #define MPI_CONGRUENT 1
43 #define MPI_SIMILAR 2
44 #define MPI_UNEQUAL 3
45 
46 /* MPI null objects */
47 #define MPI_COMM_NULL ((MPI_Comm)0x04000000)
48 #define MPI_OP_NULL ((MPI_Op)0x18000000)
49 #define MPI_GROUP_NULL ((MPI_Group)0x08000000)
50 #define MPI_DATATYPE_NULL ((MPI_Datatype)0x0c000000)
51 #define MPI_REQUEST_NULL ((MPI_Request)0x2c000000)
52 #define MPI_ERRHANDLER_NULL ((MPI_Errhandler)0x14000000)
53 
54 /* MPI thread support levels */
55 /* these constants are consistent with MPICH2 mpi.h */
56 #define MPI_THREAD_SINGLE 0
57 #define MPI_THREAD_FUNNELED 1
58 #define MPI_THREAD_SERIALIZED 2
59 #define MPI_THREAD_MULTIPLE 3
60 #define MPI_COMM_TYPE_SHARED 4
61 
62 /* these constants are consistent with MPICH2 mpi.h */
63 #define MPI_IN_PLACE ((void *) -1)
64 #define MPI_PROC_NULL -1
65 #define MPI_ANY_SOURCE -2
66 #define MPI_ANY_TAG -1
67 
68 /* MPI data types */
69 /* these constants are consistent with MPICH2 mpi.h */
70 typedef int MPI_Datatype;
71 #define MPI_CHAR ((MPI_Datatype)0x4c000101)
72 #define MPI_SIGNED_CHAR ((MPI_Datatype)0x4c000118)
73 #define MPI_UNSIGNED_CHAR ((MPI_Datatype)0x4c000102)
74 #define MPI_BYTE ((MPI_Datatype)0x4c00010d)
75 #define MPI_WCHAR ((MPI_Datatype)0x4c00040e)
76 #define MPI_SHORT ((MPI_Datatype)0x4c000203)
77 #define MPI_UNSIGNED_SHORT ((MPI_Datatype)0x4c000204)
78 #define MPI_INT ((MPI_Datatype)0x4c000405)
79 #define MPI_UNSIGNED ((MPI_Datatype)0x4c000406)
80 #define MPI_LONG ((MPI_Datatype)0x4c000807)
81 #define MPI_UNSIGNED_LONG ((MPI_Datatype)0x4c000808)
82 #define MPI_FLOAT ((MPI_Datatype)0x4c00040a)
83 #define MPI_DOUBLE ((MPI_Datatype)0x4c00080b)
84 #define MPI_LONG_DOUBLE ((MPI_Datatype)0x4c00100c)
85 #define MPI_LONG_LONG_INT ((MPI_Datatype)0x4c000809)
86 #define MPI_UNSIGNED_LONG_LONG ((MPI_Datatype)0x4c000819)
87 #define MPI_LONG_LONG ((MPI_Datatype)0x4c000809)
88 
89 /* MPI Reduction operation */
90 /* these constants are consistent with MPICH2 mpi.h */
91 typedef int MPI_Op;
92 #define MPI_MAX ((MPI_Op)0x58000001)
93 #define MPI_MIN ((MPI_Op)0x58000002)
94 #define MPI_SUM ((MPI_Op)0x58000003)
95 #define MPI_PROD ((MPI_Op)0x58000004)
96 #define MPI_LAND ((MPI_Op)0x58000005)
97 #define MPI_BAND ((MPI_Op)0x58000006)
98 #define MPI_LOR ((MPI_Op)0x58000007)
99 #define MPI_BOR ((MPI_Op)0x58000008)
100 #define MPI_LXOR ((MPI_Op)0x58000009)
101 #define MPI_BXOR ((MPI_Op)0x5800000a)
102 #define MPI_MINLOC ((MPI_Op)0x5800000b)
103 #define MPI_MAXLOC ((MPI_Op)0x5800000c)
104 #define MPI_REPLACE ((MPI_Op)0x5800000d)
105 
106 /* function type given to MPI_Op_create */
107 typedef void (MPI_User_function) ( void * a,
108  void * b, int * len, MPI_Datatype * );
109 
110 inline int MPI_Group_translate_ranks(MPI_Group, int, const int [],
111  MPI_Group, int ranks2[]) {
112  ranks2[0] = 0;
113  return MPI_SUCCESS;
114 }
115 
116 /* TODO The NO-OP implementation of may not be adequate. */
117 inline int MPI_Group_incl(MPI_Group group, int n, const int ranks[], MPI_Group *newgroup) {
118  return MPI_SUCCESS;
119 }
120 
121 /* TODO The NO-OP implementation may not be adequate. */
122 inline int MPI_Group_free(MPI_Group *group) {
123  return MPI_SUCCESS;
124 }
125 
126 // Initialization and finalize functions
127 inline int MPI_Init(int *, char ***) { return MPI_SUCCESS; }
128 inline int MPI_Init_thread(int *, char ***, int, int *provided) { *provided = MADNESS_MPI_THREAD_LEVEL; return MPI_SUCCESS; }
129 inline int MPI_Initialized(int* flag) { *flag = 1; return MPI_SUCCESS; }
130 inline int MPI_Finalize() { return MPI_SUCCESS; }
131 inline int MPI_Finalized(int* flag) { *flag = 0; return MPI_SUCCESS; }
132 inline int MPI_Query_thread(int *provided) { *provided = MADNESS_MPI_THREAD_LEVEL; return MPI_SUCCESS; }
133 
134 // Buffer functions (do nothing since no messages may be sent)
135 inline int MPI_Buffer_attach(void*, int) { return MPI_SUCCESS; }
136 inline int MPI_Buffer_detach(void* buffer, int* size) { return MPI_SUCCESS; }
137 
138 inline int MPI_Test(MPI_Request *, int *flag, MPI_Status *) {
139  *flag = 1;
140  return MPI_SUCCESS;
141 }
142 
143 inline int MPI_Testany(int, MPI_Request[], int* index, int *flag, MPI_Status*) {
144  *index = MPI_UNDEFINED;
145  *flag = 1;
146  return MPI_SUCCESS;
147 }
148 
149 inline int MPI_Testsome(int, MPI_Request*, int *outcount, int*, MPI_Status*) {
150  *outcount = MPI_UNDEFINED;
151  return MPI_SUCCESS;
152 }
153 
154 inline int MPI_Get_count(MPI_Status *, MPI_Datatype, int *count) {
155  *count = 0;
156  return MPI_SUCCESS;
157 }
158 
159 // Communicator rank and size
160 inline int MPI_Comm_rank(MPI_Comm, int* rank) { *rank = 0; return MPI_SUCCESS; }
161 inline unsigned int MPI_Comm_size(MPI_Comm, int* size) { *size = 1; return MPI_SUCCESS; }
162 
163 // There is only one node so sending messages is not allowed. Always return MPI_ERR_COMM
164 inline int MPI_Isend(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *) { return MPI_ERR_COMM; }
165 inline int MPI_Issend(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *) { return MPI_ERR_COMM; }
166 inline int MPI_Send(void*, int, MPI_Datatype, int, int, MPI_Comm) { return MPI_ERR_COMM; }
167 inline int MPI_Ssend(void*, int, MPI_Datatype, int, int, MPI_Comm) { return MPI_ERR_COMM; }
168 inline int MPI_Bsend(void*, int, MPI_Datatype, int, int, MPI_Comm) { return MPI_ERR_COMM; }
169 inline int MPI_Irecv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request*) { return MPI_ERR_COMM; }
170 inline int MPI_Recv(void*, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status*) { return MPI_ERR_COMM; }
171 
172 // Bcast does nothing but return MPI_SUCCESS
173 inline int MPI_Bcast(void*, int, MPI_Datatype, int, MPI_Comm) { return MPI_SUCCESS; }
174 
175 // Reduce does memcpy and returns MPI_SUCCESS
176 inline int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, int, MPI_Comm) {
177  if(sendbuf != MPI_IN_PLACE) std::memcpy(recvbuf, sendbuf, count);
178  return MPI_SUCCESS;
179 }
180 inline int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, MPI_Comm) {
181  if(sendbuf != MPI_IN_PLACE) std::memcpy(recvbuf, sendbuf, count);
182  return MPI_SUCCESS;
183 }
184 
185 inline int MPI_Comm_get_attr(MPI_Comm, int, void*, int*) { return MPI_ERR_COMM; }
186 
187 inline int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm) {
188  //*newcomm = MPI_COMM_NULL;
189  *newcomm = MPI_COMM_WORLD; // So that can successfully split a 1 process communicator
190  return MPI_SUCCESS;
191 }
192 
193 inline int MPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm) {
194  *newcomm = (split_type == MPI_UNDEFINED) ? MPI_COMM_NULL : comm;
195  return MPI_SUCCESS;
196 }
197 
198 inline int MPI_Abort(MPI_Comm, int code) { exit(code); return MPI_SUCCESS; }
199 
200 inline int MPI_Barrier(MPI_Comm) { return MPI_SUCCESS; }
201 
202 inline int MPI_Comm_create(MPI_Comm, MPI_Group, MPI_Comm *newcomm) {
203  //*newcomm = MPI_COMM_NULL;
204  *newcomm = MPI_COMM_WORLD; // So that can successfully split a 1 process communicator
205  return MPI_SUCCESS;
206 }
207 
208 inline int MPI_Comm_group(MPI_Comm, MPI_Group* group) {
209  *group = MPI_GROUP_NULL;
210  return MPI_SUCCESS;
211 }
212 
213 inline int MPI_Comm_free(MPI_Comm * comm) {
214  *comm = MPI_COMM_NULL;
215  return MPI_SUCCESS;
216 }
217 
218 inline int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result) {
219  if (comm1 == comm2) {
220  *result = MPI_IDENT;
221  } else {
222  *result = MPI_UNEQUAL;
223  }
224  return MPI_SUCCESS;
225 }
226 
227 
228 inline int MPI_Error_string(int errorcode, char *string, int *resultlen) {
229  switch(errorcode) {
230  case MPI_SUCCESS:
231  *resultlen = 8;
232  std::strncpy(string, "Success", *resultlen);
233  break;
234  case MPI_ERR_COMM:
235  *resultlen = 21;
236  std::strncpy(string, "Invalid communicator", *resultlen);
237  break;
238  case MPI_ERR_ARG:
239  *resultlen = 17;
240  std::strncpy(string, "Invalid argument", *resultlen);
241  break;
242  default:
243  return MPI_ERR_ARG;
244  break;
245  }
246 
247  return MPI_SUCCESS;
248 }
249 
250 inline int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {return MPI_SUCCESS;}
251 
252 inline double MPI_Wtime() { return madness::wall_time(); }
253 
254 inline int MPI_Op_create(MPI_User_function *user_fn, int commute, MPI_Op *op) {
255  return MPI_SUCCESS;
256 }
257 
258 inline int MPI_Op_free(MPI_Op *op) {
259  return MPI_SUCCESS;
260 }
261 
262 inline int MPI_Info_create (MPI_Info *info) { return MPI_SUCCESS; }
263 inline int MPI_Info_free (MPI_Info *info) { return MPI_SUCCESS; }
264 
265 #endif
char * strncpy()
Tensor< double > op(const Tensor< double > &x)
Definition: kain.cc:508
Macros and tools pertaining to the configuration of MADNESS.
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:12
int count
Definition: stubmpi.h:13
int cancelled
Definition: stubmpi.h:14
int MPI_SOURCE
Definition: stubmpi.h:15
int MPI_TAG
Definition: stubmpi.h:16
int MPI_ERROR
Definition: stubmpi.h:17
#define MPI_SUCCESS
Definition: stubmpi.h:33
int MPI_Op_free(MPI_Op *op)
Definition: stubmpi.h:258
int MPI_Ssend(void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition: stubmpi.h:167
void() MPI_User_function(void *a, void *b, int *len, MPI_Datatype *)
Definition: stubmpi.h:107
int MPI_Info_create(MPI_Info *info)
Definition: stubmpi.h:262
int MPI_Bcast(void *, int, MPI_Datatype, int, MPI_Comm)
Definition: stubmpi.h:173
#define MPI_ERR_COMM
Definition: stubmpi.h:34
#define MPI_COMM_NULL
Definition: stubmpi.h:47
int MPI_Error_string(int errorcode, char *string, int *resultlen)
Definition: stubmpi.h:228
int MPI_Isend(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition: stubmpi.h:164
int MPI_Op
Definition: stubmpi.h:91
int MPI_Group_free(MPI_Group *group)
Definition: stubmpi.h:122
int MPI_Request
Definition: stubmpi.h:11
int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm)
Definition: stubmpi.h:187
int MPI_Errhandler
Definition: stubmpi.h:27
#define MPI_COMM_WORLD
Definition: stubmpi.h:24
int MPI_Group
Definition: stubmpi.h:10
int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
Definition: stubmpi.h:218
int MPI_Finalize()
Definition: stubmpi.h:130
int MPI_Info_free(MPI_Info *info)
Definition: stubmpi.h:263
int MPI_Query_thread(int *provided)
Definition: stubmpi.h:132
int MPI_Comm_create(MPI_Comm, MPI_Group, MPI_Comm *newcomm)
Definition: stubmpi.h:202
int MPI_Op_create(MPI_User_function *user_fn, int commute, MPI_Op *op)
Definition: stubmpi.h:254
int MPI_Finalized(int *flag)
Definition: stubmpi.h:131
int MPI_Recv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Status *)
Definition: stubmpi.h:170
int MPI_Comm
Definition: stubmpi.h:23
#define MPI_IDENT
Definition: stubmpi.h:41
int MPI_Issend(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition: stubmpi.h:165
int MPI_Init_thread(int *, char ***, int, int *provided)
Definition: stubmpi.h:128
#define MPI_ERR_ARG
Definition: stubmpi.h:35
#define MPI_UNEQUAL
Definition: stubmpi.h:44
unsigned int MPI_Comm_size(MPI_Comm, int *size)
Definition: stubmpi.h:161
int MPI_Buffer_attach(void *, int)
Definition: stubmpi.h:135
#define MPI_GROUP_NULL
Definition: stubmpi.h:49
int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler)
Definition: stubmpi.h:250
int MPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm)
Definition: stubmpi.h:193
int MPI_Abort(MPI_Comm, int code)
Definition: stubmpi.h:198
int MPI_Group_translate_ranks(MPI_Group, int, const int[], MPI_Group, int ranks2[])
Definition: stubmpi.h:110
int MPI_Comm_rank(MPI_Comm, int *rank)
Definition: stubmpi.h:160
int MPI_Comm_free(MPI_Comm *comm)
Definition: stubmpi.h:213
double MPI_Wtime()
Definition: stubmpi.h:252
int MPI_Comm_get_attr(MPI_Comm, int, void *, int *)
Definition: stubmpi.h:185
int MPI_Info
Definition: stubmpi.h:29
int MPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, MPI_Comm)
Definition: stubmpi.h:180
#define MPI_IN_PLACE
Definition: stubmpi.h:63
int MPI_Bsend(void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition: stubmpi.h:168
int MPI_Irecv(void *, int, MPI_Datatype, int, int, MPI_Comm, MPI_Request *)
Definition: stubmpi.h:169
int MPI_Comm_group(MPI_Comm, MPI_Group *group)
Definition: stubmpi.h:208
int MPI_Barrier(MPI_Comm)
Definition: stubmpi.h:200
int MPI_Testsome(int, MPI_Request *, int *outcount, int *, MPI_Status *)
Definition: stubmpi.h:149
int MPI_Get_count(MPI_Status *, MPI_Datatype, int *count)
Definition: stubmpi.h:154
struct MPI_Status MPI_Status
int MPI_Initialized(int *flag)
Definition: stubmpi.h:129
int MPI_Init(int *, char ***)
Definition: stubmpi.h:127
int MPI_Send(void *, int, MPI_Datatype, int, int, MPI_Comm)
Definition: stubmpi.h:166
int MPI_Test(MPI_Request *, int *flag, MPI_Status *)
Definition: stubmpi.h:138
int MPI_Group_incl(MPI_Group group, int n, const int ranks[], MPI_Group *newgroup)
Definition: stubmpi.h:117
int MPI_Buffer_detach(void *buffer, int *size)
Definition: stubmpi.h:136
int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype, MPI_Op, int, MPI_Comm)
Definition: stubmpi.h:176
#define MPI_UNDEFINED
Definition: stubmpi.h:25
int MPI_Datatype
Definition: stubmpi.h:70
int MPI_Testany(int, MPI_Request[], int *index, int *flag, MPI_Status *)
Definition: stubmpi.h:143
Wrappers around platform dependent timers and performance info.