Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6316d189e8a19c1d6ec6f54c908651fe63cd1f3b
[simgrid.git] / include / smpi / smpi.h
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SMPI_H
8 #define SMPI_H
9
10 #include <stddef.h>
11 #include <sys/time.h>
12 #include <xbt/misc.h>
13 #include <xbt/function_types.h>
14
15 #define MPI_CALL(type,name,args) \
16   type name args; \
17   type P##name args
18
19 SG_BEGIN_DECL()
20 #define MPI_THREAD_SINGLE     0
21 #define MPI_THREAD_FUNNELED   1
22 #define MPI_THREAD_SERIALIZED 2
23 #define MPI_THREAD_MULTIPLE   3
24 //FIXME: check values
25 #define MPI_MAX_PROCESSOR_NAME 100
26 #define MPI_MAX_ERROR_STRING   100
27 #define MPI_MAX_DATAREP_STRIN  100
28 #define MPI_MAX_INFO_KEY       100
29 #define MPI_MAX_INFO_VAL       100
30 #define MPI_MAX_OBJECT_NAME    100
31 #define MPI_MAX_PORT_NAME      100
32 #define SMPI_RAND_SEED 5
33 #define MPI_ANY_SOURCE -1
34 #define MPI_PROC_NULL -2
35 #define MPI_ANY_TAG -1
36 #define MPI_UNDEFINED -1
37 // errorcodes
38 #define MPI_SUCCESS       0
39 #define MPI_ERR_COMM      1
40 #define MPI_ERR_ARG       2
41 #define MPI_ERR_TYPE      3
42 #define MPI_ERR_REQUEST   4
43 #define MPI_ERR_INTERN    5
44 #define MPI_ERR_COUNT     6
45 #define MPI_ERR_RANK      7
46 #define MPI_ERR_TAG       8
47 #define MPI_ERR_TRUNCATE  9
48 #define MPI_ERR_GROUP    10
49 #define MPI_ERR_OP       11
50 #define MPI_IDENT     0
51 #define MPI_SIMILAR   1
52 #define MPI_UNEQUAL   2
53 #define MPI_CONGRUENT 3
54 #define MPI_WTIME_IS_GLOBAL 1
55 typedef ptrdiff_t MPI_Aint;
56 typedef long long MPI_Offset;
57
58 struct s_smpi_mpi_datatype;
59 typedef struct s_smpi_mpi_datatype *MPI_Datatype;
60
61 typedef struct {
62   int MPI_SOURCE;
63   int MPI_TAG;
64   int MPI_ERROR;
65   int count;
66 } MPI_Status;
67
68 #define MPI_STATUS_IGNORE NULL
69
70 #define MPI_DATATYPE_NULL NULL
71 extern MPI_Datatype MPI_CHAR;
72 extern MPI_Datatype MPI_SHORT;
73 extern MPI_Datatype MPI_INT;
74 extern MPI_Datatype MPI_LONG;
75 extern MPI_Datatype MPI_LONG_LONG;
76 #define MPI_LONG_LONG_INT MPI_LONG_LONG
77 extern MPI_Datatype MPI_SIGNED_CHAR;
78 extern MPI_Datatype MPI_UNSIGNED_CHAR;
79 extern MPI_Datatype MPI_UNSIGNED_SHORT;
80 extern MPI_Datatype MPI_UNSIGNED;
81 extern MPI_Datatype MPI_UNSIGNED_LONG;
82 extern MPI_Datatype MPI_UNSIGNED_LONG_LONG;
83 extern MPI_Datatype MPI_FLOAT;
84 extern MPI_Datatype MPI_DOUBLE;
85 extern MPI_Datatype MPI_LONG_DOUBLE;
86 extern MPI_Datatype MPI_WCHAR;
87 extern MPI_Datatype MPI_C_BOOL;
88 extern MPI_Datatype MPI_INT8_T;
89 extern MPI_Datatype MPI_INT16_T;
90 extern MPI_Datatype MPI_INT32_T;
91 extern MPI_Datatype MPI_INT64_T;
92 extern MPI_Datatype MPI_UINT8_T;
93 #define MPI_BYTE MPI_UINT8_T
94 extern MPI_Datatype MPI_UINT16_T;
95 extern MPI_Datatype MPI_UINT32_T;
96 extern MPI_Datatype MPI_UINT64_T;
97 extern MPI_Datatype MPI_C_FLOAT_COMPLEX;
98 #define MPI_C_COMPLEX MPI_C_FLOAT_COMPLEX
99 extern MPI_Datatype MPI_C_DOUBLE_COMPLEX;
100 extern MPI_Datatype MPI_C_LONG_DOUBLE_COMPLEX;
101 extern MPI_Datatype MPI_AINT;
102 extern MPI_Datatype MPI_OFFSET;
103
104 //The following are datatypes for the MPI functions MPI_MAXLOC  and MPI_MINLOC.
105 extern MPI_Datatype MPI_FLOAT_INT;
106 extern MPI_Datatype MPI_LONG_INT;
107 extern MPI_Datatype MPI_DOUBLE_INT;
108 extern MPI_Datatype MPI_SHORT_INT;
109 extern MPI_Datatype MPI_2INT;
110 extern MPI_Datatype MPI_LONG_DOUBLE_INT;
111
112
113 typedef void MPI_User_function(void *invec, void *inoutvec, int *len,
114                                MPI_Datatype * datatype);
115 struct s_smpi_mpi_op;
116 typedef struct s_smpi_mpi_op *MPI_Op;
117
118 #define MPI_OP_NULL NULL
119 extern MPI_Op MPI_MAX;
120 extern MPI_Op MPI_MIN;
121 extern MPI_Op MPI_MAXLOC;
122 extern MPI_Op MPI_MINLOC;
123 extern MPI_Op MPI_SUM;
124 extern MPI_Op MPI_PROD;
125 extern MPI_Op MPI_LAND;
126 extern MPI_Op MPI_LOR;
127 extern MPI_Op MPI_LXOR;
128 extern MPI_Op MPI_BAND;
129 extern MPI_Op MPI_BOR;
130 extern MPI_Op MPI_BXOR;
131
132 struct s_smpi_mpi_group;
133 typedef struct s_smpi_mpi_group *MPI_Group;
134
135 #define MPI_GROUP_NULL NULL
136
137 extern MPI_Group MPI_GROUP_EMPTY;
138
139 struct s_smpi_mpi_communicator;
140 typedef struct s_smpi_mpi_communicator *MPI_Comm;
141
142 #define MPI_COMM_NULL NULL
143 extern MPI_Comm MPI_COMM_WORLD;
144 #define MPI_COMM_SELF smpi_process_comm_self()
145
146 struct s_smpi_mpi_request;
147 typedef struct s_smpi_mpi_request *MPI_Request;
148
149 #define MPI_REQUEST_NULL NULL
150
151 MPI_CALL(XBT_PUBLIC(int), MPI_Init, (int *argc, char ***argv));
152 MPI_CALL(XBT_PUBLIC(int), MPI_Finalize, (void));
153 MPI_CALL(XBT_PUBLIC(int), MPI_Init_thread,
154                             (int *argc, char ***argv, int required,
155                              int *provided));
156 MPI_CALL(XBT_PUBLIC(int), MPI_Query_thread, (int *provided));
157 MPI_CALL(XBT_PUBLIC(int), MPI_Is_thread_main, (int *flag));
158 MPI_CALL(XBT_PUBLIC(int), MPI_Abort, (MPI_Comm comm, int errorcode));
159 MPI_CALL(XBT_PUBLIC(double), MPI_Wtime, (void));
160
161 MPI_CALL(XBT_PUBLIC(int), MPI_Address, (void *location, MPI_Aint * address));
162
163 MPI_CALL(XBT_PUBLIC(int), MPI_Type_free, (MPI_Datatype * datatype));
164 MPI_CALL(XBT_PUBLIC(int), MPI_Type_size, (MPI_Datatype datatype, int *size));
165 MPI_CALL(XBT_PUBLIC(int), MPI_Type_get_extent,
166                             (MPI_Datatype datatype, MPI_Aint * lb,
167                              MPI_Aint * extent));
168 MPI_CALL(XBT_PUBLIC(int), MPI_Type_extent, (MPI_Datatype datatype, MPI_Aint * extent));
169 MPI_CALL(XBT_PUBLIC(int), MPI_Type_lb, (MPI_Datatype datatype, MPI_Aint * disp));
170 MPI_CALL(XBT_PUBLIC(int), MPI_Type_ub, (MPI_Datatype datatype, MPI_Aint * disp));
171
172 MPI_CALL(XBT_PUBLIC(int), MPI_Op_create,
173                             (MPI_User_function * function, int commute,
174                              MPI_Op * op));
175 MPI_CALL(XBT_PUBLIC(int), MPI_Op_free, (MPI_Op * op));
176
177 MPI_CALL(XBT_PUBLIC(int), MPI_Group_free, (MPI_Group * group));
178 MPI_CALL(XBT_PUBLIC(int), MPI_Group_size, (MPI_Group group, int *size));
179 MPI_CALL(XBT_PUBLIC(int), MPI_Group_rank, (MPI_Group group, int *rank));
180 MPI_CALL(XBT_PUBLIC(int), MPI_Group_translate_ranks,
181                             (MPI_Group group1, int n,
182                              int *ranks1, MPI_Group group2,
183                              int *ranks2));
184 MPI_CALL(XBT_PUBLIC(int), MPI_Group_compare,
185                             (MPI_Group group1, MPI_Group group2,
186                              int *result));
187 MPI_CALL(XBT_PUBLIC(int), MPI_Group_union,
188                             (MPI_Group group1, MPI_Group group2,
189                              MPI_Group * newgroup));
190 MPI_CALL(XBT_PUBLIC(int), MPI_Group_intersection,
191                             (MPI_Group group1, MPI_Group group2,
192                              MPI_Group * newgroup));
193 MPI_CALL(XBT_PUBLIC(int), MPI_Group_difference,
194                             (MPI_Group group1, MPI_Group group2,
195                              MPI_Group * newgroup));
196 MPI_CALL(XBT_PUBLIC(int), MPI_Group_incl,
197                             (MPI_Group group, int n, int *ranks,
198                              MPI_Group * newgroup));
199 MPI_CALL(XBT_PUBLIC(int), MPI_Group_excl,
200                             (MPI_Group group, int n, int *ranks,
201                              MPI_Group * newgroup));
202 MPI_CALL(XBT_PUBLIC(int), MPI_Group_range_incl,
203                             (MPI_Group group, int n, int ranges[][3],
204                              MPI_Group * newgroup));
205 MPI_CALL(XBT_PUBLIC(int), MPI_Group_range_excl,
206                             (MPI_Group group, int n, int ranges[][3],
207                              MPI_Group * newgroup));
208
209 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_rank, (MPI_Comm comm, int *rank));
210 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_size, (MPI_Comm comm, int *size));
211 MPI_CALL(XBT_PUBLIC(int), MPI_Get_processor_name, (char *name, int *resultlen));
212 MPI_CALL(XBT_PUBLIC(int), MPI_Get_count,
213                             (MPI_Status * status, MPI_Datatype datatype,
214                              int *count));
215
216 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_group, (MPI_Comm comm, MPI_Group * group));
217 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_compare,
218                             (MPI_Comm comm1, MPI_Comm comm2, int *result));
219 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_dup, (MPI_Comm comm, MPI_Comm * newcomm));
220 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_create,
221                             (MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm));
222 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_free, (MPI_Comm * comm));
223 MPI_CALL(XBT_PUBLIC(int), MPI_Comm_split, (MPI_Comm comm, int color, int key, MPI_Comm* comm_out));
224
225 MPI_CALL(XBT_PUBLIC(int), MPI_Send_init,
226                             (void *buf, int count, MPI_Datatype datatype,
227                              int dst, int tag, MPI_Comm comm,
228                              MPI_Request * request));
229 MPI_CALL(XBT_PUBLIC(int), MPI_Recv_init,
230                             (void *buf, int count, MPI_Datatype datatype,
231                              int src, int tag, MPI_Comm comm,
232                              MPI_Request * request));
233 MPI_CALL(XBT_PUBLIC(int), MPI_Start, (MPI_Request * request));
234 MPI_CALL(XBT_PUBLIC(int), MPI_Startall, (int count, MPI_Request * requests));
235 MPI_CALL(XBT_PUBLIC(int), MPI_Request_free, (MPI_Request * request));
236 MPI_CALL(XBT_PUBLIC(int), MPI_Irecv,
237                             (void *buf, int count, MPI_Datatype datatype,
238                              int src, int tag, MPI_Comm comm,
239                              MPI_Request * request));
240 MPI_CALL(XBT_PUBLIC(int), MPI_Isend,
241                             (void *buf, int count, MPI_Datatype datatype,
242                              int dst, int tag, MPI_Comm comm,
243                              MPI_Request * request));
244 MPI_CALL(XBT_PUBLIC(int), MPI_Recv,
245                             (void *buf, int count, MPI_Datatype datatype,
246                              int src, int tag, MPI_Comm comm,
247                              MPI_Status * status));
248 MPI_CALL(XBT_PUBLIC(int), MPI_Send,
249                             (void *buf, int count, MPI_Datatype datatype,
250                              int dst, int tag, MPI_Comm comm));
251 MPI_CALL(XBT_PUBLIC(int), MPI_Sendrecv,
252                             (void *sendbuf, int sendcount,
253                              MPI_Datatype sendtype, int dst, int sendtag,
254                              void *recvbuf, int recvcount,
255                              MPI_Datatype recvtype, int src, int recvtag,
256                              MPI_Comm comm, MPI_Status * status));
257 MPI_CALL(XBT_PUBLIC(int), MPI_Sendrecv_replace,
258                             (void *buf, int count,
259                              MPI_Datatype datatype, int dst,
260                              int sendtag, int src, int recvtag,
261                              MPI_Comm comm, MPI_Status * status));
262
263 MPI_CALL(XBT_PUBLIC(int), MPI_Test,
264                             (MPI_Request * request, int *flag, MPI_Status* status));
265 MPI_CALL(XBT_PUBLIC(int), MPI_Testany,
266                             (int count, MPI_Request requests[], int *index,
267                              int *flag, MPI_Status * status));
268 MPI_CALL(XBT_PUBLIC(int), MPI_Wait, (MPI_Request * request, MPI_Status * status));
269 MPI_CALL(XBT_PUBLIC(int), MPI_Waitany,
270                             (int count, MPI_Request requests[], int *index,
271                              MPI_Status * status));
272 MPI_CALL(XBT_PUBLIC(int), MPI_Waitall,
273                             (int count, MPI_Request requests[],
274                              MPI_Status status[]));
275 MPI_CALL(XBT_PUBLIC(int), MPI_Waitsome,
276                             (int incount, MPI_Request requests[],
277                              int *outcount, int *indices,
278                              MPI_Status status[]));
279
280 MPI_CALL(XBT_PUBLIC(int), MPI_Bcast,
281                             (void *buf, int count, MPI_Datatype datatype,
282                              int root, MPI_Comm comm));
283 MPI_CALL(XBT_PUBLIC(int), MPI_Barrier, (MPI_Comm comm));
284 MPI_CALL(XBT_PUBLIC(int), MPI_Gather,
285                             (void *sendbuf, int sendcount,
286                              MPI_Datatype sendtype, void *recvbuf,
287                              int recvcount, MPI_Datatype recvtype, int root,
288                              MPI_Comm comm));
289 MPI_CALL(XBT_PUBLIC(int), MPI_Gatherv,
290                             (void *sendbuf, int sendcount,
291                              MPI_Datatype sendtype, void *recvbuf,
292                              int *recvcounts, int *displs,
293                              MPI_Datatype recvtype, int root,
294                              MPI_Comm comm));
295 MPI_CALL(XBT_PUBLIC(int), MPI_Allgather,
296                             (void *sendbuf, int sendcount,
297                              MPI_Datatype sendtype, void *recvbuf,
298                              int recvcount, MPI_Datatype recvtype,
299                              MPI_Comm comm));
300 MPI_CALL(XBT_PUBLIC(int), MPI_Allgatherv,
301                             (void *sendbuf, int sendcount,
302                              MPI_Datatype sendtype, void *recvbuf,
303                              int *recvcounts, int *displs,
304                              MPI_Datatype recvtype, MPI_Comm comm));
305 MPI_CALL(XBT_PUBLIC(int), MPI_Scatter,
306                             (void *sendbuf, int sendcount,
307                              MPI_Datatype sendtype, void *recvbuf,
308                              int recvcount, MPI_Datatype recvtype, int root,
309                              MPI_Comm comm));
310 MPI_CALL(XBT_PUBLIC(int), MPI_Scatterv,
311                             (void *sendbuf, int *sendcounts, int *displs,
312                              MPI_Datatype sendtype, void *recvbuf,
313                              int recvcount, MPI_Datatype recvtype,
314                              int root, MPI_Comm comm));
315 MPI_CALL(XBT_PUBLIC(int), MPI_Reduce,
316                             (void *sendbuf, void *recvbuf, int count,
317                              MPI_Datatype datatype, MPI_Op op, int root,
318                              MPI_Comm comm));
319 MPI_CALL(XBT_PUBLIC(int), MPI_Allreduce,
320                             (void *sendbuf, void *recvbuf, int count,
321                              MPI_Datatype datatype, MPI_Op op,
322                              MPI_Comm comm));
323 MPI_CALL(XBT_PUBLIC(int), MPI_Scan,
324                             (void *sendbuf, void *recvbuf, int count,
325                              MPI_Datatype datatype, MPI_Op op, MPI_Comm comm));
326 MPI_CALL(XBT_PUBLIC(int), MPI_Reduce_scatter,
327                             (void *sendbuf, void *recvbuf,
328                              int *recvcounts, MPI_Datatype datatype,
329                              MPI_Op op, MPI_Comm comm));
330 MPI_CALL(XBT_PUBLIC(int), MPI_Alltoall,
331                             (void *sendbuf, int sendcount,
332                              MPI_Datatype sendtype, void *recvbuf,
333                              int recvcount, MPI_Datatype recvtype,
334                              MPI_Comm comm));
335 MPI_CALL(XBT_PUBLIC(int), MPI_Alltoallv,
336                             (void *sendbuf, int *sendcounts,
337                              int *senddisps, MPI_Datatype sendtype,
338                              void *recvbuf, int *recvcounts,
339                              int *recvdisps, MPI_Datatype recvtype,
340                              MPI_Comm comm));
341
342 // smpi functions
343 XBT_IMPORT_NO_EXPORT(int) smpi_simulated_main(int argc, char **argv);
344 XBT_PUBLIC(MPI_Comm) smpi_process_comm_self(void);
345 /*
346 XBT_PUBLIC(void) smpi_exit(int);
347 */
348
349 XBT_PUBLIC(unsigned int) smpi_sleep(unsigned int secs);
350 XBT_PUBLIC(int) smpi_gettimeofday(struct timeval *tv, struct timezone *tz);
351 XBT_PUBLIC(void) smpi_sample_1(int global, const char *file, int line,
352                                int max);
353 XBT_PUBLIC(int) smpi_sample_2(int global, const char *file, int line);
354 XBT_PUBLIC(void) smpi_sample_3(int global, const char *file, int line);
355 XBT_PUBLIC(void) smpi_sample_flops(double flops);
356
357 #define SMPI_SAMPLE_LOCAL(num) for(smpi_sample_1(0, __FILE__, __LINE__, num); \
358                                    smpi_sample_2(0, __FILE__, __LINE__);      \
359                                    smpi_sample_3(0, __FILE__, __LINE__))
360
361 #define SMPI_SAMPLE_GLOBAL(num) for(smpi_sample_1(1, __FILE__, __LINE__, num); \
362                                     smpi_sample_2(1, __FILE__, __LINE__);      \
363                                     smpi_sample_3(1, __FILE__, __LINE__))
364
365 #define SMPI_SAMPLE_DELAY(flops) for(smpi_sample_flops(flops); 0; )
366
367 XBT_PUBLIC(void *) smpi_shared_malloc(size_t size, const char *file,
368                                       int line);
369 #define SMPI_SHARED_MALLOC(size) smpi_shared_malloc(size, __FILE__, __LINE__)
370
371 XBT_PUBLIC(void) smpi_shared_free(void *data);
372 #define SMPI_SHARED_FREE(data) smpi_shared_free(data)
373
374 /* Fortran specific stuff */
375 XBT_PUBLIC(int) MAIN__(void);
376
377 SG_END_DECL()
378 #endif