Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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/smpif.h"
15 #include "smpi/smpi_cocci.h"
16 #include "instr/instr_private.h"
17
18 struct s_smpi_process_data;
19 typedef struct s_smpi_process_data *smpi_process_data_t;
20
21 #define PERSISTENT     0x1
22 #define NON_PERSISTENT 0x2
23 #define SEND           0x4
24 #define RECV           0x8
25 #define RECV_DELETE    0x10
26 #define ISEND          0x20
27 #define SSEND          0x40
28 // this struct is here to handle the problem of non-contignous data
29 // for each such structure these function should be implemented (vector
30 // index hvector hindex struct)
31 typedef struct s_smpi_subtype{
32   void (*serialize)(const void * input, void *output, size_t count, void* subtype);
33   void (*unserialize)(const void * input, void *output, size_t count, void* subtype);
34   void (*subtype_free)(MPI_Datatype* type);
35 } s_smpi_subtype_t;
36
37 typedef struct s_smpi_mpi_datatype{
38   size_t size;
39   /* this let us know if a serialization is required*/
40   size_t has_subtype;
41   MPI_Aint lb;
42   MPI_Aint ub;
43   int flags;
44   /* this let us know how to serialize and unserialize*/
45   void *substruct;
46   int in_use;
47 } s_smpi_mpi_datatype_t;
48
49 //*****************************************************************************************
50
51 typedef struct s_smpi_mpi_request {
52   void *buf;
53   /* in the case of non-contignous memory the user address shoud be keep
54    * to unserialize the data inside the user memory*/
55   void *old_buf;
56   /* this let us know how tounserialize at the end of
57    * the communication*/
58   MPI_Datatype old_type;
59   size_t size;
60   int src;
61   int dst;
62   int tag;
63   //to handle cases where we have an unknown sender
64   //We can't override src, tag, and size, because the request may be reused later
65   int real_src;
66   int real_tag;
67   int truncated;
68   size_t real_size;
69   MPI_Comm comm;
70   smx_action_t action;
71   unsigned flags;
72   int detached;
73   MPI_Request detached_sender;
74   int refcount;
75 #ifdef HAVE_TRACING
76   int send;
77   int recv;
78 #endif
79 } s_smpi_mpi_request_t;
80
81 void smpi_process_init(int *argc, char ***argv);
82 void smpi_process_destroy(void);
83 void smpi_process_finalize(void);
84
85 smpi_process_data_t smpi_process_data(void);
86 smpi_process_data_t smpi_process_remote_data(int index);
87 void smpi_process_set_user_data(void *);
88 void* smpi_process_get_user_data(void);
89 int smpi_process_count(void);
90 smx_rdv_t smpi_process_mailbox(void);
91 smx_rdv_t smpi_process_remote_mailbox(int index);
92 smx_rdv_t smpi_process_mailbox_small(void);
93 smx_rdv_t smpi_process_remote_mailbox_small(int index);
94 xbt_os_timer_t smpi_process_timer(void);
95 void smpi_process_simulated_start(void);
96 double smpi_process_simulated_elapsed(void);
97
98 void print_request(const char *message, MPI_Request request);
99
100 void smpi_global_init(void);
101 void smpi_global_destroy(void);
102
103 size_t smpi_datatype_size(MPI_Datatype datatype);
104 MPI_Aint smpi_datatype_lb(MPI_Datatype datatype);
105 MPI_Aint smpi_datatype_ub(MPI_Datatype datatype);
106 int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint * lb,
107                          MPI_Aint * extent);
108 MPI_Aint smpi_datatype_get_extent(MPI_Datatype datatype);
109 int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
110                        void *recvbuf, int recvcount,
111                        MPI_Datatype recvtype);
112 void smpi_datatype_use(MPI_Datatype type);
113 void smpi_datatype_unuse(MPI_Datatype type);
114
115 int smpi_datatype_contiguous(int count, MPI_Datatype old_type,
116                        MPI_Datatype* new_type);
117 int smpi_datatype_vector(int count, int blocklen, int stride,
118                       MPI_Datatype old_type, MPI_Datatype* new_type);
119
120 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride,
121                       MPI_Datatype old_type, MPI_Datatype* new_type);
122 int smpi_datatype_indexed(int count, int* blocklens, int* indices,
123                      MPI_Datatype old_type, MPI_Datatype* new_type);
124 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices,
125                      MPI_Datatype old_type, MPI_Datatype* new_type);
126 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices,
127                     MPI_Datatype* old_types, MPI_Datatype* new_type);
128
129 void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int has_subtype, void *struct_type, int flags);
130
131
132 void smpi_datatype_free(MPI_Datatype* type);
133 void smpi_datatype_commit(MPI_Datatype* datatype);
134
135 void smpi_empty_status(MPI_Status * status);
136 MPI_Op smpi_op_new(MPI_User_function * function, int commute);
137 void smpi_op_destroy(MPI_Op op);
138 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
139                    MPI_Datatype * datatype);
140
141 MPI_Group smpi_group_new(int size);
142 void smpi_group_destroy(MPI_Group group);
143 void smpi_group_set_mapping(MPI_Group group, int index, int rank);
144 int smpi_group_index(MPI_Group group, int rank);
145 int smpi_group_rank(MPI_Group group, int index);
146 int smpi_group_use(MPI_Group group);
147 int smpi_group_unuse(MPI_Group group);
148 int smpi_group_size(MPI_Group group);
149 int smpi_group_compare(MPI_Group group1, MPI_Group group2);
150
151 MPI_Comm smpi_comm_new(MPI_Group group);
152 void smpi_comm_destroy(MPI_Comm comm);
153 MPI_Group smpi_comm_group(MPI_Comm comm);
154 int smpi_comm_size(MPI_Comm comm);
155 void smpi_comm_get_name(MPI_Comm comm, char* name, int* len);
156 int smpi_comm_rank(MPI_Comm comm);
157 MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key);
158
159 MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype,
160                                int dst, int tag, MPI_Comm comm);
161 MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype,
162                                int src, int tag, MPI_Comm comm);
163 MPI_Request smpi_mpi_ssend_init(void *buf, int count, MPI_Datatype datatype,
164                                int dst, int tag, MPI_Comm comm);
165 void smpi_mpi_start(MPI_Request request);
166 void smpi_mpi_startall(int count, MPI_Request * requests);
167 void smpi_mpi_request_free(MPI_Request * request);
168 MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype,
169                             int dst, int tag, MPI_Comm comm);
170 MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype,
171                            int dst, int tag, MPI_Comm comm);
172 MPI_Request smpi_mpi_issend(void *buf, int count, MPI_Datatype datatype,
173                            int dst, int tag, MPI_Comm comm);
174 MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype,
175                             int src, int tag, MPI_Comm comm);
176 MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype,
177                            int src, int tag, MPI_Comm comm);
178 void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src,
179                    int tag, MPI_Comm comm, MPI_Status * status);
180 void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst,
181                    int tag, MPI_Comm comm);
182 void smpi_mpi_ssend(void *buf, int count, MPI_Datatype datatype, int dst,
183                    int tag, MPI_Comm comm);
184 void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
185                        int dst, int sendtag, void *recvbuf, int recvcount,
186                        MPI_Datatype recvtype, int src, int recvtag,
187                        MPI_Comm comm, MPI_Status * status);
188 int smpi_mpi_test(MPI_Request * request, MPI_Status * status);
189 int smpi_mpi_testany(int count, MPI_Request requests[], int *index,
190                      MPI_Status * status);
191 int smpi_mpi_testall(int count, MPI_Request requests[],
192                      MPI_Status status[]);
193 void smpi_mpi_probe(int source, int tag, MPI_Comm comm, MPI_Status* status);
194 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag,
195                     MPI_Status* status);
196 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype);
197 void smpi_mpi_wait(MPI_Request * request, MPI_Status * status);
198 int smpi_mpi_waitany(int count, MPI_Request requests[],
199                      MPI_Status * status);
200 int smpi_mpi_waitall(int count, MPI_Request requests[],
201                       MPI_Status status[]);
202 int smpi_mpi_waitsome(int incount, MPI_Request requests[], int *indices,
203                       MPI_Status status[]);
204 int smpi_mpi_testsome(int incount, MPI_Request requests[], int *indices,
205                       MPI_Status status[]);
206 void smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root,
207                     MPI_Comm comm);
208 void smpi_mpi_barrier(MPI_Comm comm);
209 void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
210                      void *recvbuf, int recvcount, MPI_Datatype recvtype,
211                      int root, MPI_Comm comm);
212 void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
213                       void *recvbuf, int *recvcounts, int *displs,
214                       MPI_Datatype recvtype, int root, MPI_Comm comm);
215 void smpi_mpi_allgather(void *sendbuf, int sendcount,
216                         MPI_Datatype sendtype, void *recvbuf,
217                         int recvcount, MPI_Datatype recvtype,
218                         MPI_Comm comm);
219 void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
220                          MPI_Datatype sendtype, void *recvbuf,
221                          int *recvcounts, int *displs,
222                          MPI_Datatype recvtype, MPI_Comm comm);
223 void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
224                       void *recvbuf, int recvcount, MPI_Datatype recvtype,
225                       int root, MPI_Comm comm);
226 void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
227                        MPI_Datatype sendtype, void *recvbuf, int recvcount,
228                        MPI_Datatype recvtype, int root, MPI_Comm comm);
229 void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
230                      MPI_Datatype datatype, MPI_Op op, int root,
231                      MPI_Comm comm);
232 void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count,
233                         MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
234 void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
235                    MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
236
237 void nary_tree_bcast(void *buf, int count, MPI_Datatype datatype, int root,
238                      MPI_Comm comm, int arity);
239 void nary_tree_barrier(MPI_Comm comm, int arity);
240
241 int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount,
242                                    MPI_Datatype sendtype, void *recvbuf,
243                                    int recvcount, MPI_Datatype recvtype,
244                                    MPI_Comm comm);
245 int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount,
246                                           MPI_Datatype sendtype,
247                                           void *recvbuf, int recvcount,
248                                           MPI_Datatype recvtype,
249                                           MPI_Comm comm);
250 int smpi_coll_tuned_alltoall_pairwise(void *sendbuf, int sendcount,
251                                       MPI_Datatype sendtype, void *recvbuf,
252                                       int recvcount, MPI_Datatype recvtype,
253                                       MPI_Comm comm);
254 int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts,
255                               int *senddisps, MPI_Datatype sendtype,
256                               void *recvbuf, int *recvcounts,
257                               int *recvdisps, MPI_Datatype recvtype,
258                               MPI_Comm comm);
259
260 // utilities
261 void smpi_bench_destroy(void);
262 void smpi_bench_begin(void);
263 void smpi_bench_end(void);
264 void smpi_execute_flops(double flops);
265
266 // f77 wrappers
267 void mpi_init__(int*);
268 void mpi_finalize__(int*);
269 void mpi_abort__(int* comm, int* errorcode, int* ierr);
270 void mpi_comm_rank__(int* comm, int* rank, int* ierr);
271 void mpi_comm_size__(int* comm, int* size, int* ierr);
272 double mpi_wtime__(void);
273 double mpi_wtick__(void);
274 void mpi_initialized__(int* flag, int* ierr);
275
276 void mpi_comm_dup__(int* comm, int* newcomm, int* ierr);
277 void mpi_comm_create__(int* comm, int* group, int* newcomm, int* ierr);
278 void mpi_comm_free__(int* comm, int* ierr);
279 void mpi_comm_split__(int* comm, int* color, int* key, int* comm_out, int* ierr);
280 void mpi_group_incl__(int* group, int* n, int* key, int* group_out, int* ierr) ;
281 void mpi_comm_group__(int* comm, int* group_out,  int* ierr);
282 void mpi_send_init__(void *buf, int* count, int* datatype, int* dst, int* tag,
283                      int* comm, int* request, int* ierr);
284 void mpi_isend__(void *buf, int* count, int* datatype, int* dst,
285                  int* tag, int* comm, int* request, int* ierr);
286 void mpi_irsend__(void *buf, int* count, int* datatype, int* dst,
287                  int* tag, int* comm, int* request, int* ierr);
288 void mpi_send__(void* buf, int* count, int* datatype, int* dst,
289                 int* tag, int* comm, int* ierr);
290 void mpi_rsend__(void* buf, int* count, int* datatype, int* dst,
291                 int* tag, int* comm, int* ierr);
292 void mpi_recv_init__(void *buf, int* count, int* datatype, int* src, int* tag,
293                      int* comm, int* request, int* ierr);
294 void mpi_irecv__(void *buf, int* count, int* datatype, int* src, int* tag,
295                  int* comm, int* request, int* ierr);
296 void mpi_recv__(void* buf, int* count, int* datatype, int* src,
297                 int* tag, int* comm, MPI_Status* status, int* ierr);
298 void mpi_start__(int* request, int* ierr);
299 void mpi_startall__(int* count, int* requests, int* ierr);
300 void mpi_wait__(int* request, MPI_Status* status, int* ierr);
301 void mpi_waitany__(int* count, int* requests, int* index, MPI_Status* status, int* ierr);
302 void mpi_waitall__(int* count, int* requests, MPI_Status* status, int* ierr);
303
304 void mpi_barrier__(int* comm, int* ierr);
305 void mpi_bcast__(void* buf, int* count, int* datatype, int* root, int* comm, int* ierr);
306 void mpi_reduce__(void* sendbuf, void* recvbuf, int* count,
307                   int* datatype, int* op, int* root, int* comm, int* ierr);
308 void mpi_allreduce__(void* sendbuf, void* recvbuf, int* count, int* datatype,
309                      int* op, int* comm, int* ierr);
310 void mpi_reduce_scatter__(void* sendbuf, void* recvbuf, int* recvcounts, int* datatype,
311                      int* op, int* comm, int* ierr) ;
312 void mpi_scatter__(void* sendbuf, int* sendcount, int* sendtype,
313                    void* recvbuf, int* recvcount, int* recvtype,
314                    int* root, int* comm, int* ierr);
315 void mpi_scatterv__(void* sendbuf, int* sendcounts, int* displs, int* sendtype,
316                    void* recvbuf, int* recvcount, int* recvtype,
317                    int* root, int* comm, int* ierr);
318 void mpi_gather__(void* sendbuf, int* sendcount, int* sendtype,
319                   void* recvbuf, int* recvcount, int* recvtype,
320                   int* root, int* comm, int* ierr);
321 void mpi_gatherv__(void* sendbuf, int* sendcount, int* sendtype,
322                   void* recvbuf, int* recvcounts, int* displs, int* recvtype,
323                   int* root, int* comm, int* ierr);
324 void mpi_allgather__(void* sendbuf, int* sendcount, int* sendtype,
325                      void* recvbuf, int* recvcount, int* recvtype,
326                      int* comm, int* ierr);
327 void mpi_allgatherv__(void* sendbuf, int* sendcount, int* sendtype,
328                      void* recvbuf, int* recvcount,int* displs, int* recvtype,
329                      int* comm, int* ierr) ;
330 void mpi_type_size__(int* datatype, int *size, int* ierr);
331
332 void mpi_scan__(void* sendbuf, void* recvbuf, int* count, int* datatype,
333                 int* op, int* comm, int* ierr);
334 void mpi_alltoall__(void* sendbuf, int* sendcount, int* sendtype,
335                     void* recvbuf, int* recvcount, int* recvtype, int* comm, int* ierr);
336 void mpi_alltoallv__(void* sendbuf, int* sendcounts, int* senddisps, int* sendtype,
337                     void* recvbuf, int* recvcounts, int* recvdisps, int* recvtype, int* comm, int* ierr);
338 void mpi_get_processor_name__(char *name, int *resultlen, int* ierr);
339 void mpi_test__ (int * request, int *flag, MPI_Status * status, int* ierr);
340 void mpi_get_count__(MPI_Status * status, int* datatype, int *count, int* ierr);
341 void mpi_type_extent__(int* datatype, MPI_Aint * extent, int* ierr);
342 void mpi_attr_get__(int* comm, int* keyval, void* attr_value, int* flag, int* ierr );
343 void mpi_type_lb__(int* datatype, MPI_Aint * extent, int* ierr);
344 void mpi_type_ub__(int* datatype, MPI_Aint * extent, int* ierr);
345 void mpi_error_string__(int* errorcode, char* string, int* resultlen, int* ierr);
346 void mpi_sendrecv__(void* sendbuf, int* sendcount, int* sendtype, int* dst,
347                 int* sendtag, void *recvbuf, int* recvcount,
348                 int* recvtype, int* src, int* recvtag,
349                 int* comm, MPI_Status* status, int* ierr);
350
351 /********** Tracing **********/
352 /* from smpi_instr.c */
353 void TRACE_internal_smpi_set_category (const char *category);
354 const char *TRACE_internal_smpi_get_category (void);
355 void TRACE_smpi_collective_in(int rank, int root, const char *operation);
356 void TRACE_smpi_collective_out(int rank, int root, const char *operation);
357 void TRACE_smpi_computing_init(int rank);
358 void TRACE_smpi_computing_out(int rank);
359 void TRACE_smpi_computing_in(int rank);
360
361 #endif