Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1e2a3c21426cd22d005e423fe3176c49ef5756ed
[simgrid.git] / src / smpi / private.h
1 /* Copyright (c) 2007, 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_PRIVATE_H
8 #define SMPI_PRIVATE_H
9
10 #include "xbt.h"
11 #include "xbt/xbt_os_time.h"
12 #include "simgrid/simix.h"
13 #include "smpi/smpi_interface.h"
14 #include "smpi/smpi.h"
15 #include "smpi/smpif.h"
16 #include "smpi/smpi_cocci.h"
17 #include "instr/instr_private.h"
18
19 struct s_smpi_process_data;
20 typedef struct s_smpi_process_data *smpi_process_data_t;
21
22 #define PERSISTENT     0x1
23 #define NON_PERSISTENT 0x2
24 #define SEND           0x4
25 #define RECV           0x8
26 #define RECV_DELETE    0x10
27 #define ISEND          0x20
28 #define SSEND          0x40
29 #define PREPARED       0x80
30 // this struct is here to handle the problem of non-contignous data
31 // for each such structure these function should be implemented (vector
32 // index hvector hindex struct)
33 typedef struct s_smpi_subtype{
34   void (*serialize)(const void * input, void *output, size_t count, void* subtype);
35   void (*unserialize)(const void * input, void *output, size_t count, void* subtype);
36   void (*subtype_free)(MPI_Datatype* type);
37 } s_smpi_subtype_t;
38
39 typedef struct s_smpi_mpi_datatype{
40   size_t size;
41   /* this let us know if a serialization is required*/
42   size_t has_subtype;
43   MPI_Aint lb;
44   MPI_Aint ub;
45   int flags;
46   /* this let us know how to serialize and unserialize*/
47   void *substruct;
48   int in_use;
49 } s_smpi_mpi_datatype_t;
50
51
52 #define COLL_TAG_REDUCE -112
53 #define COLL_TAG_SCATTER -223
54 #define COLL_TAG_SCATTERV -334
55 #define COLL_TAG_GATHER -445
56 #define COLL_TAG_ALLGATHER -556
57 #define COLL_TAG_ALLGATHERV -667
58 #define COLL_TAG_BARRIER -778
59 #define COLL_TAG_REDUCE_SCATTER -889
60 #define COLL_TAG_ALLTOALLV -1000
61 #define COLL_TAG_ALLTOALL -1112
62 #define COLL_TAG_GATHERV -2223
63 #define COLL_TAG_BCAST -3334
64 #define COLL_TAG_ALLREDUCE -4445
65 //*****************************************************************************************
66
67 typedef struct s_smpi_mpi_request {
68   void *buf;
69   /* in the case of non-contignous memory the user address shoud be keep
70    * to unserialize the data inside the user memory*/
71   void *old_buf;
72   /* this let us know how tounserialize at the end of
73    * the communication*/
74   MPI_Datatype old_type;
75   size_t size;
76   int src;
77   int dst;
78   int tag;
79   //to handle cases where we have an unknown sender
80   //We can't override src, tag, and size, because the request may be reused later
81   int real_src;
82   int real_tag;
83   int truncated;
84   size_t real_size;
85   MPI_Comm comm;
86   smx_action_t action;
87   unsigned flags;
88   int detached;
89   MPI_Request detached_sender;
90   int refcount;
91 #ifdef HAVE_TRACING
92   int send;
93   int recv;
94 #endif
95 } s_smpi_mpi_request_t;
96
97 void smpi_process_init(int *argc, char ***argv);
98 void smpi_process_destroy(void);
99 void smpi_process_finalize(void);
100 int smpi_process_finalized(void);
101
102 smpi_process_data_t smpi_process_data(void);
103 smpi_process_data_t smpi_process_remote_data(int index);
104 void smpi_process_set_user_data(void *);
105 void* smpi_process_get_user_data(void);
106 int smpi_process_count(void);
107 smx_rdv_t smpi_process_mailbox(void);
108 smx_rdv_t smpi_process_remote_mailbox(int index);
109 smx_rdv_t smpi_process_mailbox_small(void);
110 smx_rdv_t smpi_process_remote_mailbox_small(int index);
111 xbt_os_timer_t smpi_process_timer(void);
112 void smpi_process_simulated_start(void);
113 double smpi_process_simulated_elapsed(void);
114
115 void print_request(const char *message, MPI_Request request);
116
117 void smpi_global_init(void);
118 void smpi_global_destroy(void);
119
120 size_t smpi_datatype_size(MPI_Datatype datatype);
121 MPI_Aint smpi_datatype_lb(MPI_Datatype datatype);
122 MPI_Aint smpi_datatype_ub(MPI_Datatype datatype);
123 int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint * lb,
124                          MPI_Aint * extent);
125 MPI_Aint smpi_datatype_get_extent(MPI_Datatype datatype);
126 int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
127                        void *recvbuf, int recvcount,
128                        MPI_Datatype recvtype);
129 void smpi_datatype_use(MPI_Datatype type);
130 void smpi_datatype_unuse(MPI_Datatype type);
131
132 int smpi_datatype_contiguous(int count, MPI_Datatype old_type,
133                        MPI_Datatype* new_type, MPI_Aint lb);
134 int smpi_datatype_vector(int count, int blocklen, int stride,
135                       MPI_Datatype old_type, MPI_Datatype* new_type);
136
137 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride,
138                       MPI_Datatype old_type, MPI_Datatype* new_type);
139 int smpi_datatype_indexed(int count, int* blocklens, int* indices,
140                      MPI_Datatype old_type, MPI_Datatype* new_type);
141 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices,
142                      MPI_Datatype old_type, MPI_Datatype* new_type);
143 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices,
144                     MPI_Datatype* old_types, MPI_Datatype* new_type);
145
146 void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int has_subtype, void *struct_type, int flags);
147
148
149 void smpi_datatype_free(MPI_Datatype* type);
150 void smpi_datatype_commit(MPI_Datatype* datatype);
151
152 void smpi_empty_status(MPI_Status * status);
153 MPI_Op smpi_op_new(MPI_User_function * function, int commute);
154 int smpi_op_is_commute(MPI_Op op);
155 void smpi_op_destroy(MPI_Op op);
156 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
157                    MPI_Datatype * datatype);
158
159 MPI_Group smpi_group_new(int size);
160 void smpi_group_destroy(MPI_Group group);
161 void smpi_group_set_mapping(MPI_Group group, int index, int rank);
162 int smpi_group_index(MPI_Group group, int rank);
163 int smpi_group_rank(MPI_Group group, int index);
164 int smpi_group_use(MPI_Group group);
165 int smpi_group_unuse(MPI_Group group);
166 int smpi_group_size(MPI_Group group);
167 int smpi_group_compare(MPI_Group group1, MPI_Group group2);
168
169 MPI_Comm smpi_comm_new(MPI_Group group);
170 void smpi_comm_destroy(MPI_Comm comm);
171 MPI_Group smpi_comm_group(MPI_Comm comm);
172 int smpi_comm_size(MPI_Comm comm);
173 void smpi_comm_get_name(MPI_Comm comm, char* name, int* len);
174 int smpi_comm_rank(MPI_Comm comm);
175 MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key);
176 void smpi_comm_use(MPI_Comm comm);
177 void smpi_comm_unuse(MPI_Comm comm);
178
179 MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype,
180                                int dst, int tag, MPI_Comm comm);
181 MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype,
182                                int src, int tag, MPI_Comm comm);
183 MPI_Request smpi_mpi_ssend_init(void *buf, int count, MPI_Datatype datatype,
184                                int dst, int tag, MPI_Comm comm);
185 void smpi_mpi_start(MPI_Request request);
186 void smpi_mpi_startall(int count, MPI_Request * requests);
187 void smpi_mpi_request_free(MPI_Request * request);
188 MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype,
189                             int dst, int tag, MPI_Comm comm);
190 MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype,
191                            int dst, int tag, MPI_Comm comm);
192 MPI_Request smpi_mpi_issend(void *buf, int count, MPI_Datatype datatype,
193                            int dst, int tag, MPI_Comm comm);
194 MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype,
195                             int src, int tag, MPI_Comm comm);
196 MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype,
197                            int src, int tag, MPI_Comm comm);
198 void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src,
199                    int tag, MPI_Comm comm, MPI_Status * status);
200 void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst,
201                    int tag, MPI_Comm comm);
202 void smpi_mpi_ssend(void *buf, int count, MPI_Datatype datatype, int dst,
203                    int tag, MPI_Comm comm);
204 void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
205                        int dst, int sendtag, void *recvbuf, int recvcount,
206                        MPI_Datatype recvtype, int src, int recvtag,
207                        MPI_Comm comm, MPI_Status * status);
208 int smpi_mpi_test(MPI_Request * request, MPI_Status * status);
209 int smpi_mpi_testany(int count, MPI_Request requests[], int *index,
210                      MPI_Status * status);
211 int smpi_mpi_testall(int count, MPI_Request requests[],
212                      MPI_Status status[]);
213 void smpi_mpi_probe(int source, int tag, MPI_Comm comm, MPI_Status* status);
214 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag,
215                     MPI_Status* status);
216 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype);
217 void smpi_mpi_wait(MPI_Request * request, MPI_Status * status);
218 int smpi_mpi_waitany(int count, MPI_Request requests[],
219                      MPI_Status * status);
220 int smpi_mpi_waitall(int count, MPI_Request requests[],
221                       MPI_Status status[]);
222 int smpi_mpi_waitsome(int incount, MPI_Request requests[], int *indices,
223                       MPI_Status status[]);
224 int smpi_mpi_testsome(int incount, MPI_Request requests[], int *indices,
225                       MPI_Status status[]);
226 void smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root,
227                     MPI_Comm comm);
228 void smpi_mpi_barrier(MPI_Comm comm);
229 void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
230                      void *recvbuf, int recvcount, MPI_Datatype recvtype,
231                      int root, MPI_Comm comm);
232 void smpi_mpi_reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
233                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
234 void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
235                       void *recvbuf, int *recvcounts, int *displs,
236                       MPI_Datatype recvtype, int root, MPI_Comm comm);
237 void smpi_mpi_allgather(void *sendbuf, int sendcount,
238                         MPI_Datatype sendtype, void *recvbuf,
239                         int recvcount, MPI_Datatype recvtype,
240                         MPI_Comm comm);
241 void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
242                          MPI_Datatype sendtype, void *recvbuf,
243                          int *recvcounts, int *displs,
244                          MPI_Datatype recvtype, MPI_Comm comm);
245 void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
246                       void *recvbuf, int recvcount, MPI_Datatype recvtype,
247                       int root, MPI_Comm comm);
248 void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
249                        MPI_Datatype sendtype, void *recvbuf, int recvcount,
250                        MPI_Datatype recvtype, int root, MPI_Comm comm);
251 void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
252                      MPI_Datatype datatype, MPI_Op op, int root,
253                      MPI_Comm comm);
254 void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count,
255                         MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
256 void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
257                    MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
258
259 void nary_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root,
260                      MPI_Comm comm, int arity);
261 void nary_tree_barrier(MPI_Comm comm, int arity);
262
263 int smpi_coll_tuned_alltoall_ompi2(void *sendbuf, int sendcount,
264                                       MPI_Datatype sendtype, void *recvbuf,
265                                       int recvcount, MPI_Datatype recvtype,
266                                       MPI_Comm comm);
267 int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount,
268                                    MPI_Datatype sendtype, void *recvbuf,
269                                    int recvcount, MPI_Datatype recvtype,
270                                    MPI_Comm comm);
271 int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount,
272                                           MPI_Datatype sendtype,
273                                           void *recvbuf, int recvcount,
274                                           MPI_Datatype recvtype,
275                                           MPI_Comm comm);
276 int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts,
277                               int *senddisps, MPI_Datatype sendtype,
278                               void *recvbuf, int *recvcounts,
279                               int *recvdisps, MPI_Datatype recvtype,
280                               MPI_Comm comm);
281
282 // utilities
283 void smpi_bench_destroy(void);
284 void smpi_bench_begin(void);
285 void smpi_bench_end(void);
286 void smpi_execute_flops(double flops);
287
288 // f77 wrappers
289 void mpi_init_(int*);
290 void mpi_finalize_(int*);
291 void mpi_abort_(int* comm, int* errorcode, int* ierr);
292 void mpi_comm_rank_(int* comm, int* rank, int* ierr);
293 void mpi_comm_size_(int* comm, int* size, int* ierr);
294 double mpi_wtime_(void);
295 double mpi_wtick_(void);
296 void mpi_initialized_(int* flag, int* ierr);
297
298 void mpi_comm_dup_(int* comm, int* newcomm, int* ierr);
299 void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr);
300 void mpi_comm_free_(int* comm, int* ierr);
301 void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr);
302 void mpi_group_incl_(int* group, int* n, int* key, int* group_out, int* ierr) ;
303 void mpi_comm_group_(int* comm, int* group_out,  int* ierr);
304 void mpi_send_init_(void *buf, int* count, int* datatype, int* dst, int* tag,
305                      int* comm, int* request, int* ierr);
306 void mpi_isend_(void *buf, int* count, int* datatype, int* dst,
307                  int* tag, int* comm, int* request, int* ierr);
308 void mpi_irsend_(void *buf, int* count, int* datatype, int* dst,
309                  int* tag, int* comm, int* request, int* ierr);
310 void mpi_send_(void* buf, int* count, int* datatype, int* dst,
311                 int* tag, int* comm, int* ierr);
312 void mpi_rsend_(void* buf, int* count, int* datatype, int* dst,
313                 int* tag, int* comm, int* ierr);
314 void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag,
315                      int* comm, int* request, int* ierr);
316 void mpi_irecv_(void *buf, int* count, int* datatype, int* src, int* tag,
317                  int* comm, int* request, int* ierr);
318 void mpi_recv_(void* buf, int* count, int* datatype, int* src,
319                 int* tag, int* comm, MPI_Status* status, int* ierr);
320 void mpi_start_(int* request, int* ierr);
321 void mpi_startall_(int* count, int* requests, int* ierr);
322 void mpi_wait_(int* request, MPI_Status* status, int* ierr);
323 void mpi_waitany_(int* count, int* requests, int* index, MPI_Status* status, int* ierr);
324 void mpi_waitall_(int* count, int* requests, MPI_Status* status, int* ierr);
325
326 void mpi_barrier_(int* comm, int* ierr);
327 void mpi_bcast_(void* buf, int* count, int* datatype, int* root, int* comm, int* ierr);
328 void mpi_reduce_(void* sendbuf, void* recvbuf, int* count,
329                   int* datatype, int* op, int* root, int* comm, int* ierr);
330 void mpi_allreduce_(void* sendbuf, void* recvbuf, int* count, int* datatype,
331                      int* op, int* comm, int* ierr);
332 void mpi_reduce_scatter_(void* sendbuf, void* recvbuf, int* recvcounts, int* datatype,
333                      int* op, int* comm, int* ierr) ;
334 void mpi_scatter_(void* sendbuf, int* sendcount, int* sendtype,
335                    void* recvbuf, int* recvcount, int* recvtype,
336                    int* root, int* comm, int* ierr);
337 void mpi_scatterv_(void* sendbuf, int* sendcounts, int* displs, int* sendtype,
338                    void* recvbuf, int* recvcount, int* recvtype,
339                    int* root, int* comm, int* ierr);
340 void mpi_gather_(void* sendbuf, int* sendcount, int* sendtype,
341                   void* recvbuf, int* recvcount, int* recvtype,
342                   int* root, int* comm, int* ierr);
343 void mpi_gatherv_(void* sendbuf, int* sendcount, int* sendtype,
344                   void* recvbuf, int* recvcounts, int* displs, int* recvtype,
345                   int* root, int* comm, int* ierr);
346 void mpi_allgather_(void* sendbuf, int* sendcount, int* sendtype,
347                      void* recvbuf, int* recvcount, int* recvtype,
348                      int* comm, int* ierr);
349 void mpi_allgatherv_(void* sendbuf, int* sendcount, int* sendtype,
350                      void* recvbuf, int* recvcount,int* displs, int* recvtype,
351                      int* comm, int* ierr) ;
352 void mpi_type_size_(int* datatype, int *size, int* ierr);
353
354 void mpi_scan_(void* sendbuf, void* recvbuf, int* count, int* datatype,
355                 int* op, int* comm, int* ierr);
356 void mpi_alltoall_(void* sendbuf, int* sendcount, int* sendtype,
357                     void* recvbuf, int* recvcount, int* recvtype, int* comm, int* ierr);
358 void mpi_alltoallv_(void* sendbuf, int* sendcounts, int* senddisps, int* sendtype,
359                     void* recvbuf, int* recvcounts, int* recvdisps, int* recvtype, int* comm, int* ierr);
360 void mpi_get_processor_name_(char *name, int *resultlen, int* ierr);
361 void mpi_test_ (int * request, int *flag, MPI_Status * status, int* ierr);
362 void mpi_testall_ (int* count, int * requests,  int *flag, MPI_Status * statuses, int* ierr);
363 void mpi_get_count_(MPI_Status * status, int* datatype, int *count, int* ierr);
364 void mpi_type_extent_(int* datatype, MPI_Aint * extent, int* ierr);
365 void mpi_attr_get_(int* comm, int* keyval, void* attr_value, int* flag, int* ierr );
366 void mpi_type_commit_(int* datatype,  int* ierr);
367 void mpi_type_vector_(int* count, int* blocklen, int* stride, int* old_type, int* newtype,  int* ierr);
368 void mpi_type_create_vector_(int* count, int* blocklen, int* stride, int* old_type, int* newtype,  int* ierr);
369 void mpi_type_hvector_(int* count, int* blocklen, MPI_Aint* stride, int* old_type, int* newtype,  int* ierr);
370 void mpi_type_create_hvector_(int* count, int* blocklen, MPI_Aint* stride, int* old_type, int* newtype,  int* ierr);
371 void mpi_type_free_(int* datatype, int* ierr);
372 void mpi_type_lb_(int* datatype, MPI_Aint * extent, int* ierr);
373 void mpi_type_ub_(int* datatype, MPI_Aint * extent, int* ierr);
374 void mpi_win_fence_( int* assert,  int* win, int* ierr);
375 void mpi_win_free_( int* win, int* ierr);
376 void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr);
377 void mpi_info_create_( int *info, int* ierr);
378 void mpi_info_set_( int *info, char *key, char *value, int* ierr);
379 void mpi_info_free_(int* info, int* ierr);
380 void mpi_get_( int *origin_addr, int* origin_count, int* origin_datatype, int* target_rank,
381     MPI_Aint* target_disp, int* target_count, int* target_datatype, int* win, int* ierr);
382 void mpi_error_string_(int* errorcode, char* string, int* resultlen, int* ierr);
383 void mpi_sendrecv_(void* sendbuf, int* sendcount, int* sendtype, int* dst,
384                 int* sendtag, void *recvbuf, int* recvcount,
385                 int* recvtype, int* src, int* recvtag,
386                 int* comm, MPI_Status* status, int* ierr);
387
388 /********** Tracing **********/
389 /* from smpi_instr.c */
390 void TRACE_internal_smpi_set_category (const char *category);
391 const char *TRACE_internal_smpi_get_category (void);
392 void TRACE_smpi_collective_in(int rank, int root, const char *operation);
393 void TRACE_smpi_collective_out(int rank, int root, const char *operation);
394 void TRACE_smpi_computing_init(int rank);
395 void TRACE_smpi_computing_out(int rank);
396 void TRACE_smpi_computing_in(int rank);
397
398 #endif