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