Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill all trailling whitespaces
[simgrid.git] / src / smpi / smpi_f77.cpp
1 /* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/smpi/private.h"
7 #include "src/smpi/smpi_comm.hpp"
8 #include "src/smpi/smpi_datatype.hpp"
9 #include "src/smpi/smpi_op.hpp"
10 #include "src/smpi/smpi_process.hpp"
11 #include "src/smpi/smpi_request.hpp"
12 #include "src/smpi/smpi_win.hpp"
13
14 static int running_processes = 0;
15
16 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
17 typedef int integer;
18 #else
19 typedef long int integer;
20 #endif
21
22 /* Convert between Fortran and C */
23
24 #define FORT_BOTTOM(addr)          ((*(int*)addr) == -200 ? MPI_BOTTOM : (void*)addr)
25 #define FORT_IN_PLACE(addr)        ((*(int*)addr) == -100 ? MPI_IN_PLACE : (void*)addr)
26 #define FORT_STATUS_IGNORE(addr)   (static_cast<MPI_Status*>((*(int*)addr) == -300 ? MPI_STATUS_IGNORE : (void*)addr))
27 #define FORT_STATUSES_IGNORE(addr) (static_cast<MPI_Status*>((*(int*)addr) == -400 ? MPI_STATUSES_IGNORE : (void*)addr))
28
29 #define KEY_SIZE (sizeof(int) * 2 + 1)
30
31 static char* get_key(char* key, int id) {
32   snprintf(key, KEY_SIZE, "%x",id);
33   return key;
34 }
35
36 static char* get_key_id(char* key, int id) {
37   snprintf(key, KEY_SIZE, "%x_%d",id, smpi_process()->index());
38   return key;
39 }
40
41 static void smpi_init_fortran_types(){
42    if(simgrid::smpi::F2C::lookup() == nullptr){
43      MPI_COMM_WORLD->add_f();
44      MPI_BYTE->add_f();//MPI_BYTE
45      MPI_CHAR->add_f();//MPI_CHARACTER
46 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
47      MPI_C_BOOL->add_f();//MPI_LOGICAL
48      MPI_INT->add_f();//MPI_INTEGER
49 #else
50      MPI_C_BOOL->add_f();//MPI_LOGICAL
51      MPI_LONG->add_f();//MPI_INTEGER
52 #endif
53      MPI_INT8_T->add_f();//MPI_INTEGER1
54      MPI_INT16_T->add_f();//MPI_INTEGER2
55      MPI_INT32_T->add_f();//MPI_INTEGER4
56      MPI_INT64_T->add_f();//MPI_INTEGER8
57      MPI_REAL->add_f();//MPI_REAL
58      MPI_REAL4->add_f();//MPI_REAL4
59      MPI_REAL8->add_f();//MPI_REAL8
60      MPI_DOUBLE->add_f();//MPI_DOUBLE_PRECISION
61      MPI_C_FLOAT_COMPLEX->add_f();//MPI_COMPLEX
62      MPI_C_DOUBLE_COMPLEX->add_f();//MPI_DOUBLE_COMPLEX
63 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
64      MPI_2INT->add_f();//MPI_2INTEGER
65 #else
66      MPI_2LONG->add_f();//MPI_2INTEGER
67 #endif
68      MPI_UINT8_T->add_f();//MPI_LOGICAL1
69      MPI_UINT16_T->add_f();//MPI_LOGICAL2
70      MPI_UINT32_T->add_f();//MPI_LOGICAL4
71      MPI_UINT64_T->add_f();//MPI_LOGICAL8
72      MPI_2FLOAT->add_f();//MPI_2REAL
73      MPI_2DOUBLE->add_f();//MPI_2DOUBLE_PRECISION
74      MPI_PTR->add_f();//MPI_AINT
75      MPI_OFFSET->add_f();//MPI_OFFSET
76      MPI_AINT->add_f();//MPI_COUNT
77      MPI_REAL16->add_f();//MPI_REAL16
78      MPI_PACKED->add_f();//MPI_PACKED
79
80      MPI_MAX->add_f();
81      MPI_MIN->add_f();
82      MPI_MAXLOC->add_f();
83      MPI_MINLOC->add_f();
84      MPI_SUM->add_f();
85      MPI_PROD->add_f();
86      MPI_LAND->add_f();
87      MPI_LOR->add_f();
88      MPI_LXOR->add_f();
89      MPI_BAND->add_f();
90      MPI_BOR->add_f();
91      MPI_BXOR->add_f();
92    }
93 }
94
95 extern "C" { // This should really use the C linkage to be usable from Fortran
96
97
98 void mpi_init_(int* ierr) {
99     smpi_init_fortran_types();
100    *ierr = MPI_Init(nullptr, nullptr);
101    running_processes++;
102 }
103
104 void mpi_finalize_(int* ierr) {
105    *ierr = MPI_Finalize();
106    running_processes--;
107    if(running_processes==0){
108       simgrid::smpi::F2C::delete_lookup();
109    }
110 }
111
112 void mpi_abort_(int* comm, int* errorcode, int* ierr) {
113   *ierr = MPI_Abort(simgrid::smpi::Comm::f2c(*comm), *errorcode);
114 }
115
116 void mpi_comm_rank_(int* comm, int* rank, int* ierr) {
117    *ierr = MPI_Comm_rank(simgrid::smpi::Comm::f2c(*comm), rank);
118 }
119
120 void mpi_comm_size_(int* comm, int* size, int* ierr) {
121    *ierr = MPI_Comm_size(simgrid::smpi::Comm::f2c(*comm), size);
122 }
123
124 double mpi_wtime_() {
125    return MPI_Wtime();
126 }
127
128 double mpi_wtick_() {
129   return MPI_Wtick();
130 }
131
132 void mpi_comm_dup_(int* comm, int* newcomm, int* ierr) {
133   MPI_Comm tmp;
134
135   *ierr = MPI_Comm_dup(simgrid::smpi::Comm::f2c(*comm), &tmp);
136   if(*ierr == MPI_SUCCESS) {
137     *newcomm = tmp->add_f();
138   }
139 }
140
141 void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
142   MPI_Comm tmp;
143
144   *ierr = MPI_Comm_create(simgrid::smpi::Comm::f2c(*comm),simgrid::smpi::Group::f2c(*group), &tmp);
145   if(*ierr == MPI_SUCCESS) {
146     *newcomm = tmp->add_f();
147   }
148 }
149
150 void mpi_comm_free_(int* comm, int* ierr) {
151   MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
152
153   *ierr = MPI_Comm_free(&tmp);
154
155   if(*ierr == MPI_SUCCESS) {
156     simgrid::smpi::Comm::free_f(*comm);
157   }
158 }
159
160 void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr) {
161   MPI_Comm tmp;
162
163   *ierr = MPI_Comm_split(simgrid::smpi::Comm::f2c(*comm), *color, *key, &tmp);
164   if(*ierr == MPI_SUCCESS) {
165     *comm_out = tmp->add_f();
166   }
167 }
168
169 void mpi_group_incl_(int* group, int* n, int* ranks, int* group_out, int* ierr) {
170   MPI_Group tmp;
171
172   *ierr = MPI_Group_incl(simgrid::smpi::Group::f2c(*group), *n, ranks, &tmp);
173   if(*ierr == MPI_SUCCESS) {
174     *group_out = tmp->add_f();
175   }
176 }
177
178 void mpi_comm_group_(int* comm, int* group_out,  int* ierr) {
179   MPI_Group tmp;
180
181   *ierr = MPI_Comm_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
182   if(*ierr == MPI_SUCCESS) {
183     *group_out = tmp->c2f();
184   }
185 }
186
187 void mpi_initialized_(int* flag, int* ierr){
188   *ierr = MPI_Initialized(flag);
189 }
190
191 void mpi_send_init_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
192   MPI_Request req;
193   buf = static_cast<char *>(FORT_BOTTOM(buf));
194   *ierr = MPI_Send_init(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dst, *tag, simgrid::smpi::Comm::f2c(*comm), &req);
195   if(*ierr == MPI_SUCCESS) {
196     *request = req->add_f();
197   }
198 }
199
200 void mpi_isend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
201   MPI_Request req;
202   buf = static_cast<char *>(FORT_BOTTOM(buf));
203   *ierr = MPI_Isend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dst, *tag, simgrid::smpi::Comm::f2c(*comm), &req);
204   if(*ierr == MPI_SUCCESS) {
205     *request = req->add_f();
206   }
207 }
208
209 void mpi_irsend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
210   MPI_Request req;
211   buf = static_cast<char *>(FORT_BOTTOM(buf));
212   *ierr = MPI_Irsend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dst, *tag, simgrid::smpi::Comm::f2c(*comm), &req);
213   if(*ierr == MPI_SUCCESS) {
214     *request = req->add_f();
215   }
216 }
217
218 void mpi_send_(void* buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* ierr) {
219   buf = static_cast<char *>(FORT_BOTTOM(buf));
220    *ierr = MPI_Send(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dst, *tag, simgrid::smpi::Comm::f2c(*comm));
221 }
222
223 void mpi_rsend_(void* buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* ierr) {
224   buf = static_cast<char *>(FORT_BOTTOM(buf));
225    *ierr = MPI_Rsend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dst, *tag, simgrid::smpi::Comm::f2c(*comm));
226 }
227
228 void mpi_sendrecv_(void* sendbuf, int* sendcount, int* sendtype, int* dst, int* sendtag, void *recvbuf, int* recvcount,
229                    int* recvtype, int* src, int* recvtag, int* comm, MPI_Status* status, int* ierr) {
230   sendbuf = static_cast<char *>( FORT_BOTTOM(sendbuf));
231   recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
232    *ierr = MPI_Sendrecv(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype), *dst, *sendtag, recvbuf, *recvcount,
233                         simgrid::smpi::Datatype::f2c(*recvtype), *src, *recvtag, simgrid::smpi::Comm::f2c(*comm), FORT_STATUS_IGNORE(status));
234 }
235
236 void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) {
237   MPI_Request req;
238   buf = static_cast<char *>( FORT_BOTTOM(buf));
239   *ierr = MPI_Recv_init(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *src, *tag, simgrid::smpi::Comm::f2c(*comm), &req);
240   if(*ierr == MPI_SUCCESS) {
241     *request = req->add_f();
242   }
243 }
244
245 void mpi_irecv_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) {
246   MPI_Request req;
247   buf = static_cast<char *>( FORT_BOTTOM(buf));
248   *ierr = MPI_Irecv(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *src, *tag, simgrid::smpi::Comm::f2c(*comm), &req);
249   if(*ierr == MPI_SUCCESS) {
250     *request = req->add_f();
251   }
252 }
253
254 void mpi_recv_(void* buf, int* count, int* datatype, int* src, int* tag, int* comm, MPI_Status* status, int* ierr) {
255   buf = static_cast<char *>( FORT_BOTTOM(buf));
256   *ierr = MPI_Recv(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *src, *tag, simgrid::smpi::Comm::f2c(*comm), status);
257 }
258
259 void mpi_start_(int* request, int* ierr) {
260   MPI_Request req = simgrid::smpi::Request::f2c(*request);
261
262   *ierr = MPI_Start(&req);
263 }
264
265 void mpi_startall_(int* count, int* requests, int* ierr) {
266   MPI_Request* reqs;
267   int i;
268
269   reqs = xbt_new(MPI_Request, *count);
270   for(i = 0; i < *count; i++) {
271     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
272   }
273   *ierr = MPI_Startall(*count, reqs);
274   xbt_free(reqs);
275 }
276
277 void mpi_wait_(int* request, MPI_Status* status, int* ierr) {
278    MPI_Request req = simgrid::smpi::Request::f2c(*request);
279
280    *ierr = MPI_Wait(&req, FORT_STATUS_IGNORE(status));
281    if(req==MPI_REQUEST_NULL){
282      simgrid::smpi::Request::free_f(*request);
283      *request=MPI_FORTRAN_REQUEST_NULL;
284    }
285 }
286
287 void mpi_waitany_(int* count, int* requests, int* index, MPI_Status* status, int* ierr) {
288   MPI_Request* reqs;
289   int i;
290
291   reqs = xbt_new(MPI_Request, *count);
292   for(i = 0; i < *count; i++) {
293     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
294   }
295   *ierr = MPI_Waitany(*count, reqs, index, status);
296   if(reqs[*index]==MPI_REQUEST_NULL){
297       simgrid::smpi::Request::free_f(requests[*index]);
298       requests[*index]=MPI_FORTRAN_REQUEST_NULL;
299   }
300   xbt_free(reqs);
301 }
302
303 void mpi_waitall_(int* count, int* requests, MPI_Status* status, int* ierr) {
304   MPI_Request* reqs;
305   int i;
306
307   reqs = xbt_new(MPI_Request, *count);
308   for(i = 0; i < *count; i++) {
309     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
310   }
311   *ierr = MPI_Waitall(*count, reqs, FORT_STATUSES_IGNORE(status));
312   for(i = 0; i < *count; i++) {
313       if(reqs[i]==MPI_REQUEST_NULL){
314           simgrid::smpi::Request::free_f(requests[i]);
315           requests[i]=MPI_FORTRAN_REQUEST_NULL;
316       }
317   }
318
319   xbt_free(reqs);
320 }
321
322 void mpi_barrier_(int* comm, int* ierr) {
323   *ierr = MPI_Barrier(simgrid::smpi::Comm::f2c(*comm));
324 }
325
326 void mpi_bcast_(void *buf, int* count, int* datatype, int* root, int* comm, int* ierr) {
327   *ierr = MPI_Bcast(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *root, simgrid::smpi::Comm::f2c(*comm));
328 }
329
330 void mpi_reduce_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* root, int* comm, int* ierr) {
331   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
332   sendbuf = static_cast<char *>( FORT_BOTTOM(sendbuf));
333   recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
334   *ierr = MPI_Reduce(sendbuf, recvbuf, *count, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Op::f2c(*op), *root, simgrid::smpi::Comm::f2c(*comm));
335 }
336
337 void mpi_allreduce_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr) {
338   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
339   *ierr = MPI_Allreduce(sendbuf, recvbuf, *count, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Comm::f2c(*comm));
340 }
341
342 void mpi_reduce_scatter_(void* sendbuf, void* recvbuf, int* recvcounts, int* datatype, int* op, int* comm, int* ierr) {
343   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
344   *ierr = MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, simgrid::smpi::Datatype::f2c(*datatype),
345                         simgrid::smpi::Op::f2c(*op), simgrid::smpi::Comm::f2c(*comm));
346 }
347
348 void mpi_scatter_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype,
349                    int* root, int* comm, int* ierr) {
350   recvbuf = static_cast<char *>( FORT_IN_PLACE(recvbuf));
351   *ierr = MPI_Scatter(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype),
352                       recvbuf, *recvcount, simgrid::smpi::Datatype::f2c(*recvtype), *root, simgrid::smpi::Comm::f2c(*comm));
353 }
354
355 void mpi_scatterv_(void* sendbuf, int* sendcounts, int* displs, int* sendtype,
356                    void* recvbuf, int* recvcount, int* recvtype, int* root, int* comm, int* ierr) {
357   recvbuf = static_cast<char *>( FORT_IN_PLACE(recvbuf));
358   *ierr = MPI_Scatterv(sendbuf, sendcounts, displs, simgrid::smpi::Datatype::f2c(*sendtype),
359                       recvbuf, *recvcount, simgrid::smpi::Datatype::f2c(*recvtype), *root, simgrid::smpi::Comm::f2c(*comm));
360 }
361
362 void mpi_gather_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype,
363                   int* root, int* comm, int* ierr) {
364   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
365   sendbuf = sendbuf!=MPI_IN_PLACE ? static_cast<char *>( FORT_BOTTOM(sendbuf)) : MPI_IN_PLACE;
366   recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
367   *ierr = MPI_Gather(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype),
368                      recvbuf, *recvcount, simgrid::smpi::Datatype::f2c(*recvtype), *root, simgrid::smpi::Comm::f2c(*comm));
369 }
370
371 void mpi_gatherv_(void* sendbuf, int* sendcount, int* sendtype,
372                   void* recvbuf, int* recvcounts, int* displs, int* recvtype, int* root, int* comm, int* ierr) {
373   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
374   sendbuf = sendbuf!=MPI_IN_PLACE ? static_cast<char *>( FORT_BOTTOM(sendbuf)) : MPI_IN_PLACE;
375   recvbuf = static_cast<char *>( FORT_BOTTOM(recvbuf));
376   *ierr = MPI_Gatherv(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype),
377                      recvbuf, recvcounts, displs, simgrid::smpi::Datatype::f2c(*recvtype), *root, simgrid::smpi::Comm::f2c(*comm));
378 }
379
380 void mpi_allgather_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype,
381                      int* comm, int* ierr) {
382   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
383   *ierr = MPI_Allgather(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype),
384                         recvbuf, *recvcount, simgrid::smpi::Datatype::f2c(*recvtype), simgrid::smpi::Comm::f2c(*comm));
385 }
386
387 void mpi_allgatherv_(void* sendbuf, int* sendcount, int* sendtype,
388                      void* recvbuf, int* recvcounts,int* displs, int* recvtype, int* comm, int* ierr) {
389   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
390   *ierr = MPI_Allgatherv(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype),
391                         recvbuf, recvcounts, displs, simgrid::smpi::Datatype::f2c(*recvtype), simgrid::smpi::Comm::f2c(*comm));
392 }
393
394 void mpi_scan_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr) {
395   *ierr = MPI_Scan(sendbuf, recvbuf, *count, simgrid::smpi::Datatype::f2c(*datatype),
396                    simgrid::smpi::Op::f2c(*op), simgrid::smpi::Comm::f2c(*comm));
397 }
398
399 void mpi_alltoall_(void* sendbuf, int* sendcount, int* sendtype,
400                     void* recvbuf, int* recvcount, int* recvtype, int* comm, int* ierr) {
401   *ierr = MPI_Alltoall(sendbuf, *sendcount, simgrid::smpi::Datatype::f2c(*sendtype),
402                        recvbuf, *recvcount, simgrid::smpi::Datatype::f2c(*recvtype), simgrid::smpi::Comm::f2c(*comm));
403 }
404
405 void mpi_alltoallv_(void* sendbuf, int* sendcounts, int* senddisps, int* sendtype,
406                     void* recvbuf, int* recvcounts, int* recvdisps, int* recvtype, int* comm, int* ierr) {
407   *ierr = MPI_Alltoallv(sendbuf, sendcounts, senddisps, simgrid::smpi::Datatype::f2c(*sendtype),
408                        recvbuf, recvcounts, recvdisps, simgrid::smpi::Datatype::f2c(*recvtype), simgrid::smpi::Comm::f2c(*comm));
409 }
410
411 void mpi_test_ (int * request, int *flag, MPI_Status * status, int* ierr){
412   MPI_Request req = simgrid::smpi::Request::f2c(*request);
413   *ierr= MPI_Test(&req, flag, FORT_STATUS_IGNORE(status));
414   if(req==MPI_REQUEST_NULL){
415       simgrid::smpi::Request::free_f(*request);
416       *request=MPI_FORTRAN_REQUEST_NULL;
417   }
418 }
419
420 void mpi_testall_ (int* count, int * requests,  int *flag, MPI_Status * statuses, int* ierr){
421   int i;
422   MPI_Request* reqs = xbt_new(MPI_Request, *count);
423   for(i = 0; i < *count; i++) {
424     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
425   }
426   *ierr= MPI_Testall(*count, reqs, flag, FORT_STATUSES_IGNORE(statuses));
427   for(i = 0; i < *count; i++) {
428     if(reqs[i]==MPI_REQUEST_NULL){
429         simgrid::smpi::Request::free_f(requests[i]);
430         requests[i]=MPI_FORTRAN_REQUEST_NULL;
431     }
432   }
433   xbt_free(reqs);
434 }
435
436 void mpi_get_processor_name_(char *name, int *resultlen, int* ierr){
437   *ierr = MPI_Get_processor_name(name, resultlen);
438 }
439
440 void mpi_get_count_(MPI_Status * status, int* datatype, int *count, int* ierr){
441   *ierr = MPI_Get_count(FORT_STATUS_IGNORE(status), simgrid::smpi::Datatype::f2c(*datatype), count);
442 }
443
444 void mpi_attr_get_(int* comm, int* keyval, void* attr_value, int* flag, int* ierr ){
445   *ierr = MPI_Attr_get(simgrid::smpi::Comm::f2c(*comm), *keyval, attr_value, flag);
446 }
447
448 void mpi_type_extent_(int* datatype, MPI_Aint * extent, int* ierr){
449   *ierr= MPI_Type_extent(simgrid::smpi::Datatype::f2c(*datatype),  extent);
450 }
451
452 void mpi_type_commit_(int* datatype,  int* ierr){
453   MPI_Datatype tmp= simgrid::smpi::Datatype::f2c(*datatype);
454   *ierr= MPI_Type_commit(&tmp);
455 }
456
457 void mpi_type_vector_(int* count, int* blocklen, int* stride, int* old_type, int* newtype,  int* ierr){
458   MPI_Datatype tmp;
459   *ierr= MPI_Type_vector(*count, *blocklen, *stride, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
460   if(*ierr == MPI_SUCCESS) {
461     *newtype = tmp->add_f();
462   }
463 }
464
465 void mpi_type_create_vector_(int* count, int* blocklen, int* stride, int* old_type, int* newtype,  int* ierr){
466   MPI_Datatype tmp;
467   *ierr= MPI_Type_vector(*count, *blocklen, *stride, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
468   if(*ierr == MPI_SUCCESS) {
469     *newtype = tmp->add_f();
470   }
471 }
472
473 void mpi_type_hvector_(int* count, int* blocklen, MPI_Aint* stride, int* old_type, int* newtype,  int* ierr){
474   MPI_Datatype tmp;
475   *ierr= MPI_Type_hvector (*count, *blocklen, *stride, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
476   if(*ierr == MPI_SUCCESS) {
477     *newtype = tmp->add_f();
478   }
479 }
480
481 void mpi_type_create_hvector_(int* count, int* blocklen, MPI_Aint* stride, int* old_type, int* newtype,  int* ierr){
482   MPI_Datatype tmp;
483   *ierr= MPI_Type_hvector(*count, *blocklen, *stride, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
484   if(*ierr == MPI_SUCCESS) {
485     *newtype = tmp->add_f();
486   }
487 }
488
489 void mpi_type_free_(int* datatype, int* ierr){
490   MPI_Datatype tmp= simgrid::smpi::Datatype::f2c(*datatype);
491   *ierr= MPI_Type_free (&tmp);
492   if(*ierr == MPI_SUCCESS) {
493     simgrid::smpi::F2C::free_f(*datatype);
494   }
495 }
496
497 void mpi_type_ub_(int* datatype, MPI_Aint * disp, int* ierr){
498   *ierr= MPI_Type_ub(simgrid::smpi::Datatype::f2c(*datatype), disp);
499 }
500
501 void mpi_type_lb_(int* datatype, MPI_Aint * extent, int* ierr){
502   *ierr= MPI_Type_extent(simgrid::smpi::Datatype::f2c(*datatype), extent);
503 }
504
505 void mpi_type_size_(int* datatype, int *size, int* ierr)
506 {
507   *ierr = MPI_Type_size(simgrid::smpi::Datatype::f2c(*datatype), size);
508 }
509
510 void mpi_error_string_(int* errorcode, char* string, int* resultlen, int* ierr){
511   *ierr = MPI_Error_string(*errorcode, string, resultlen);
512 }
513
514 void mpi_win_fence_( int* assert,  int* win, int* ierr){
515   *ierr =  MPI_Win_fence(* assert, simgrid::smpi::Win::f2c(*win));
516 }
517
518 void mpi_win_free_( int* win, int* ierr){
519   MPI_Win tmp = simgrid::smpi::Win::f2c(*win);
520   *ierr =  MPI_Win_free(&tmp);
521   if(*ierr == MPI_SUCCESS) {
522     simgrid::smpi::F2C::free_f(*win);
523   }
524 }
525
526 void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr){
527   MPI_Win tmp;
528   *ierr =  MPI_Win_create( static_cast<void*>(base), *size, *disp_unit, simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),&tmp);
529  if(*ierr == MPI_SUCCESS) {
530    *win = tmp->add_f();
531  }
532 }
533
534 void mpi_win_post_(int* group, int assert, int* win, int* ierr){
535   *ierr =  MPI_Win_post(simgrid::smpi::Group::f2c(*group), assert, simgrid::smpi::Win::f2c(*win));
536 }
537
538 void mpi_win_start_(int* group, int assert, int* win, int* ierr){
539   *ierr =  MPI_Win_start(simgrid::smpi::Group::f2c(*group), assert, simgrid::smpi::Win::f2c(*win));
540 }
541
542 void mpi_win_complete_(int* win, int* ierr){
543   *ierr =  MPI_Win_complete(simgrid::smpi::Win::f2c(*win));
544 }
545
546 void mpi_win_wait_(int* win, int* ierr){
547   *ierr =  MPI_Win_wait(simgrid::smpi::Win::f2c(*win));
548 }
549
550 void mpi_win_set_name_ (int*  win, char * name, int* ierr, int size){
551   //handle trailing blanks
552   while(name[size-1]==' ')
553     size--;
554   while(*name==' '){//handle leading blanks
555     size--;
556     name++;
557   }
558   char* tname = xbt_new(char,size+1);
559   strncpy(tname, name, size);
560   tname[size]='\0';
561   *ierr = MPI_Win_set_name(simgrid::smpi::Win::f2c(*win), tname);
562   xbt_free(tname);
563 }
564
565 void mpi_win_get_name_ (int*  win, char * name, int* len, int* ierr){
566   *ierr = MPI_Win_get_name(simgrid::smpi::Win::f2c(*win),name,len);
567   if(*len>0)
568     name[*len]=' ';//blank padding, not \0
569 }
570
571 void mpi_info_create_( int *info, int* ierr){
572   MPI_Info tmp;
573   *ierr =  MPI_Info_create(&tmp);
574   if(*ierr == MPI_SUCCESS) {
575     *info = tmp->add_f();
576   }
577 }
578
579 void mpi_info_set_( int *info, char *key, char *value, int* ierr, unsigned int keylen, unsigned int valuelen){
580   //handle trailing blanks
581   while(key[keylen-1]==' ')
582     keylen--;
583   while(*key==' '){//handle leading blanks
584     keylen--;
585     key++;
586   }
587   char* tkey = xbt_new(char,keylen+1);
588   strncpy(tkey, key, keylen);
589   tkey[keylen]='\0';
590
591   while(value[valuelen-1]==' ')
592     valuelen--;
593   while(*value==' '){//handle leading blanks
594     valuelen--;
595     value++;
596   }
597   char* tvalue = xbt_new(char,valuelen+1);
598   strncpy(tvalue, value, valuelen);
599   tvalue[valuelen]='\0';
600
601   *ierr =  MPI_Info_set( simgrid::smpi::Info::f2c(*info), tkey, tvalue);
602   xbt_free(tkey);
603   xbt_free(tvalue);
604 }
605
606 void mpi_info_get_ (int* info,char *key,int* valuelen, char *value, int *flag, int* ierr, unsigned int keylen ){
607   while(key[keylen-1]==' ')
608     keylen--;
609   while(*key==' '){//handle leading blanks
610     keylen--;
611     key++;
612   }
613   char* tkey = xbt_new(char,keylen+1);
614   strncpy(tkey, key, keylen);
615   tkey[keylen]='\0';
616   *ierr = MPI_Info_get(simgrid::smpi::Info::f2c(*info),tkey,*valuelen, value, flag);
617   xbt_free(tkey);
618   if(*flag!=0){
619     int replace=0;
620     int i=0;
621     for (i=0; i<*valuelen; i++){
622       if(value[i]=='\0')
623         replace=1;
624       if(replace)
625         value[i]=' ';
626     }
627   }
628 }
629
630 void mpi_info_free_(int* info, int* ierr){
631   MPI_Info tmp = simgrid::smpi::Info::f2c(*info);
632   *ierr =  MPI_Info_free(&tmp);
633   if(*ierr == MPI_SUCCESS) {
634     simgrid::smpi::F2C::free_f(*info);
635   }
636 }
637
638 void mpi_get_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
639     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
640   *ierr =  MPI_Get( static_cast<void*>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
641       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win));
642 }
643
644 void mpi_accumulate_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
645     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* op, int* win, int* ierr){
646   *ierr =  MPI_Accumulate( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
647       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win));
648 }
649
650 void mpi_put_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
651     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
652   *ierr =  MPI_Put( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
653       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win));
654 }
655
656 //following are automatically generated, and have to be checked
657 void mpi_finalized_ (int * flag, int* ierr){
658
659  *ierr = MPI_Finalized(flag);
660 }
661
662 void mpi_init_thread_ (int* required, int *provided, int* ierr){
663   smpi_init_fortran_types();
664   *ierr = MPI_Init_thread(nullptr, nullptr,*required, provided);
665   running_processes++;
666 }
667
668 void mpi_query_thread_ (int *provided, int* ierr){
669
670  *ierr = MPI_Query_thread(provided);
671 }
672
673 void mpi_is_thread_main_ (int *flag, int* ierr){
674
675  *ierr = MPI_Is_thread_main(flag);
676 }
677
678 void mpi_address_ (void *location, MPI_Aint * address, int* ierr){
679
680  *ierr = MPI_Address(location, address);
681 }
682
683 void mpi_get_address_ (void *location, MPI_Aint * address, int* ierr){
684
685  *ierr = MPI_Get_address(location, address);
686 }
687
688 void mpi_type_dup_ (int*  datatype, int* newdatatype, int* ierr){
689  MPI_Datatype tmp;
690  *ierr = MPI_Type_dup(simgrid::smpi::Datatype::f2c(*datatype), &tmp);
691  if(*ierr == MPI_SUCCESS) {
692    *newdatatype = tmp->add_f();
693  }
694 }
695
696 void mpi_type_set_name_ (int*  datatype, char * name, int* ierr, int size){
697  char* tname = xbt_new(char, size+1);
698  strncpy(tname, name, size);
699  tname[size]='\0';
700  *ierr = MPI_Type_set_name(simgrid::smpi::Datatype::f2c(*datatype), tname);
701  xbt_free(tname);
702 }
703
704 void mpi_type_get_name_ (int*  datatype, char * name, int* len, int* ierr){
705  *ierr = MPI_Type_get_name(simgrid::smpi::Datatype::f2c(*datatype),name,len);
706   if(*len>0)
707     name[*len]=' ';
708 }
709
710 void mpi_type_get_attr_ (int* type, int* type_keyval, void *attribute_val, int* flag, int* ierr){
711
712  *ierr = MPI_Type_get_attr ( simgrid::smpi::Datatype::f2c(*type), *type_keyval, attribute_val,flag);
713 }
714
715 void mpi_type_set_attr_ (int* type, int* type_keyval, void *attribute_val, int* ierr){
716
717  *ierr = MPI_Type_set_attr ( simgrid::smpi::Datatype::f2c(*type), *type_keyval, attribute_val);
718 }
719
720 void mpi_type_delete_attr_ (int* type, int* type_keyval, int* ierr){
721
722  *ierr = MPI_Type_delete_attr ( simgrid::smpi::Datatype::f2c(*type),  *type_keyval);
723 }
724
725 void mpi_type_create_keyval_ (void* copy_fn, void*  delete_fn, int* keyval, void* extra_state, int* ierr){
726
727  *ierr = MPI_Type_create_keyval(reinterpret_cast<MPI_Type_copy_attr_function*>(copy_fn), reinterpret_cast<MPI_Type_delete_attr_function*>(delete_fn),
728                                 keyval,  extra_state) ;
729 }
730
731 void mpi_type_free_keyval_ (int* keyval, int* ierr) {
732  *ierr = MPI_Type_free_keyval( keyval);
733 }
734
735 void mpi_pcontrol_ (int* level , int* ierr){
736  *ierr = MPI_Pcontrol(*static_cast<const int*>(level));
737 }
738
739 void mpi_type_get_extent_ (int* datatype, MPI_Aint * lb, MPI_Aint * extent, int* ierr){
740
741  *ierr = MPI_Type_get_extent(simgrid::smpi::Datatype::f2c(*datatype), lb, extent);
742 }
743
744 void mpi_type_get_true_extent_ (int* datatype, MPI_Aint * lb, MPI_Aint * extent, int* ierr){
745
746  *ierr = MPI_Type_get_true_extent(simgrid::smpi::Datatype::f2c(*datatype), lb, extent);
747 }
748
749 void mpi_op_create_ (void * function, int* commute, int* op, int* ierr){
750   MPI_Op tmp;
751  *ierr = MPI_Op_create(reinterpret_cast<MPI_User_function*>(function),*commute, &tmp);
752  if(*ierr == MPI_SUCCESS) {
753    tmp->set_fortran_op();
754    *op = tmp->add_f();
755  }
756 }
757
758 void mpi_op_free_ (int* op, int* ierr){
759   MPI_Op tmp= simgrid::smpi::Op::f2c(*op);
760   *ierr = MPI_Op_free(& tmp);
761   if(*ierr == MPI_SUCCESS) {
762     simgrid::smpi::F2C::free_f(*op);
763   }
764 }
765
766 void mpi_group_free_ (int* group, int* ierr){
767  MPI_Group tmp = simgrid::smpi::Group::f2c(*group);
768  *ierr = MPI_Group_free(&tmp);
769  if(*ierr == MPI_SUCCESS) {
770    simgrid::smpi::F2C::free_f(*group);
771  }
772 }
773
774 void mpi_group_size_ (int* group, int *size, int* ierr){
775
776  *ierr = MPI_Group_size(simgrid::smpi::Group::f2c(*group), size);
777 }
778
779 void mpi_group_rank_ (int* group, int *rank, int* ierr){
780
781  *ierr = MPI_Group_rank(simgrid::smpi::Group::f2c(*group), rank);
782 }
783
784 void mpi_group_translate_ranks_ (int* group1, int* n, int *ranks1, int* group2, int *ranks2, int* ierr)
785 {
786
787  *ierr = MPI_Group_translate_ranks(simgrid::smpi::Group::f2c(*group1), *n, ranks1, simgrid::smpi::Group::f2c(*group2), ranks2);
788 }
789
790 void mpi_group_compare_ (int* group1, int* group2, int *result, int* ierr){
791
792  *ierr = MPI_Group_compare(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), result);
793 }
794
795 void mpi_group_union_ (int* group1, int* group2, int* newgroup, int* ierr){
796  MPI_Group tmp;
797  *ierr = MPI_Group_union(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
798  if(*ierr == MPI_SUCCESS) {
799    *newgroup = tmp->add_f();
800  }
801 }
802
803 void mpi_group_intersection_ (int* group1, int* group2, int* newgroup, int* ierr){
804  MPI_Group tmp;
805  *ierr = MPI_Group_intersection(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
806  if(*ierr == MPI_SUCCESS) {
807    *newgroup = tmp->add_f();
808  }
809 }
810
811 void mpi_group_difference_ (int* group1, int* group2, int* newgroup, int* ierr){
812  MPI_Group tmp;
813  *ierr = MPI_Group_difference(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
814  if(*ierr == MPI_SUCCESS) {
815    *newgroup = tmp->add_f();
816  }
817 }
818
819 void mpi_group_excl_ (int* group, int* n, int *ranks, int* newgroup, int* ierr){
820   MPI_Group tmp;
821  *ierr = MPI_Group_excl(simgrid::smpi::Group::f2c(*group), *n, ranks, &tmp);
822  if(*ierr == MPI_SUCCESS) {
823    *newgroup = tmp->add_f();
824  }
825 }
826
827 void mpi_group_range_incl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
828 {
829   MPI_Group tmp;
830  *ierr = MPI_Group_range_incl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp);
831  if(*ierr == MPI_SUCCESS) {
832    *newgroup = tmp->add_f();
833  }
834 }
835
836 void mpi_group_range_excl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
837 {
838  MPI_Group tmp;
839  *ierr = MPI_Group_range_excl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp);
840  if(*ierr == MPI_SUCCESS) {
841    *newgroup = tmp->add_f();
842  }
843 }
844
845 void mpi_comm_get_attr_ (int* comm, int* comm_keyval, void *attribute_val, int *flag, int* ierr){
846
847  *ierr = MPI_Comm_get_attr (simgrid::smpi::Comm::f2c(*comm), *comm_keyval, attribute_val, flag);
848 }
849
850 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, void *attribute_val, int* ierr){
851
852  *ierr = MPI_Comm_set_attr ( simgrid::smpi::Comm::f2c(*comm), *comm_keyval, attribute_val);
853 }
854
855 void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
856
857  *ierr = MPI_Comm_delete_attr (simgrid::smpi::Comm::f2c(*comm),  *comm_keyval);
858 }
859
860 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
861
862  *ierr = MPI_Comm_create_keyval(reinterpret_cast<MPI_Comm_copy_attr_function*>(copy_fn),  reinterpret_cast<MPI_Comm_delete_attr_function*>(delete_fn),
863          keyval,  extra_state) ;
864 }
865
866 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
867  *ierr = MPI_Comm_free_keyval( keyval);
868 }
869
870 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
871  *ierr = MPI_Comm_get_name(simgrid::smpi::Comm::f2c(*comm), name, len);
872   if(*len>0)
873     name[*len]=' ';
874 }
875
876 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
877
878  *ierr = MPI_Comm_compare(simgrid::smpi::Comm::f2c(*comm1), simgrid::smpi::Comm::f2c(*comm2), result);
879 }
880
881 void mpi_comm_disconnect_ (int* comm, int* ierr){
882  MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
883  *ierr = MPI_Comm_disconnect(&tmp);
884  if(*ierr == MPI_SUCCESS) {
885    simgrid::smpi::Comm::free_f(*comm);
886  }
887 }
888
889 void mpi_request_free_ (int* request, int* ierr){
890   MPI_Request tmp=simgrid::smpi::Request::f2c(*request);
891  *ierr = MPI_Request_free(&tmp);
892  if(*ierr == MPI_SUCCESS) {
893    simgrid::smpi::Request::free_f(*request);
894  }
895 }
896
897 void mpi_sendrecv_replace_ (void *buf, int* count, int* datatype, int* dst, int* sendtag, int* src, int* recvtag,
898                             int* comm, MPI_Status* status, int* ierr)
899 {
900  *ierr = MPI_Sendrecv_replace(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dst, *sendtag, *src,
901  *recvtag, simgrid::smpi::Comm::f2c(*comm), FORT_STATUS_IGNORE(status));
902 }
903
904 void mpi_testany_ (int* count, int* requests, int *index, int *flag, MPI_Status* status, int* ierr)
905 {
906   MPI_Request* reqs;
907   int i;
908
909   reqs = xbt_new(MPI_Request, *count);
910   for(i = 0; i < *count; i++) {
911     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
912   }
913   *ierr = MPI_Testany(*count, reqs, index, flag, FORT_STATUS_IGNORE(status));
914   if(*index!=MPI_UNDEFINED && reqs[*index]==MPI_REQUEST_NULL){
915     simgrid::smpi::Request::free_f(requests[*index]);
916     requests[*index]=MPI_FORTRAN_REQUEST_NULL;
917   }
918   xbt_free(reqs);
919 }
920
921 void mpi_waitsome_ (int* incount, int* requests, int *outcount, int *indices, MPI_Status* status, int* ierr)
922 {
923   MPI_Request* reqs;
924   int i;
925
926   reqs = xbt_new(MPI_Request, *incount);
927   for(i = 0; i < *incount; i++) {
928     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
929   }
930   *ierr = MPI_Waitsome(*incount, reqs, outcount, indices, status);
931   for(i=0;i<*outcount;i++){
932     if(reqs[indices[i]]==MPI_REQUEST_NULL){
933         simgrid::smpi::Request::free_f(requests[indices[i]]);
934         requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
935     }
936   }
937   xbt_free(reqs);
938 }
939
940 void mpi_reduce_local_ (void *inbuf, void *inoutbuf, int* count, int* datatype, int* op, int* ierr){
941
942  *ierr = MPI_Reduce_local(inbuf, inoutbuf, *count, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Op::f2c(*op));
943 }
944
945 void mpi_reduce_scatter_block_ (void *sendbuf, void *recvbuf, int* recvcount, int* datatype, int* op, int* comm,
946                                 int* ierr)
947 {
948   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
949  *ierr = MPI_Reduce_scatter_block(sendbuf, recvbuf, *recvcount, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Op::f2c(*op),
950                                   simgrid::smpi::Comm::f2c(*comm));
951 }
952
953 void mpi_pack_size_ (int* incount, int* datatype, int* comm, int* size, int* ierr) {
954  *ierr = MPI_Pack_size(*incount, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Comm::f2c(*comm), size);
955 }
956
957 void mpi_cart_coords_ (int* comm, int* rank, int* maxdims, int* coords, int* ierr) {
958  *ierr = MPI_Cart_coords(simgrid::smpi::Comm::f2c(*comm), *rank, *maxdims, coords);
959 }
960
961 void mpi_cart_create_ (int* comm_old, int* ndims, int* dims, int* periods, int* reorder, int*  comm_cart, int* ierr) {
962   MPI_Comm tmp;
963  *ierr = MPI_Cart_create(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, *reorder, &tmp);
964  if(*ierr == MPI_SUCCESS) {
965    *comm_cart = tmp->add_f();
966  }
967 }
968
969 void mpi_cart_get_ (int* comm, int* maxdims, int* dims, int* periods, int* coords, int* ierr) {
970  *ierr = MPI_Cart_get(simgrid::smpi::Comm::f2c(*comm), *maxdims, dims, periods, coords);
971 }
972
973 void mpi_cart_map_ (int* comm_old, int* ndims, int* dims, int* periods, int* newrank, int* ierr) {
974  *ierr = MPI_Cart_map(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, newrank);
975 }
976
977 void mpi_cart_rank_ (int* comm, int* coords, int* rank, int* ierr) {
978  *ierr = MPI_Cart_rank(simgrid::smpi::Comm::f2c(*comm), coords, rank);
979 }
980
981 void mpi_cart_shift_ (int* comm, int* direction, int* displ, int* source, int* dest, int* ierr) {
982  *ierr = MPI_Cart_shift(simgrid::smpi::Comm::f2c(*comm), *direction, *displ, source, dest);
983 }
984
985 void mpi_cart_sub_ (int* comm, int* remain_dims, int*  comm_new, int* ierr) {
986  MPI_Comm tmp;
987  *ierr = MPI_Cart_sub(simgrid::smpi::Comm::f2c(*comm), remain_dims, &tmp);
988  if(*ierr == MPI_SUCCESS) {
989    *comm_new = tmp->add_f();
990  }
991 }
992
993 void mpi_cartdim_get_ (int* comm, int* ndims, int* ierr) {
994  *ierr = MPI_Cartdim_get(simgrid::smpi::Comm::f2c(*comm), ndims);
995 }
996
997 void mpi_graph_create_ (int* comm_old, int* nnodes, int* index, int* edges, int* reorder, int*  comm_graph, int* ierr) {
998   MPI_Comm tmp;
999  *ierr = MPI_Graph_create(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, *reorder, &tmp);
1000  if(*ierr == MPI_SUCCESS) {
1001    *comm_graph = tmp->add_f();
1002  }
1003 }
1004
1005 void mpi_graph_get_ (int* comm, int* maxindex, int* maxedges, int* index, int* edges, int* ierr) {
1006  *ierr = MPI_Graph_get(simgrid::smpi::Comm::f2c(*comm), *maxindex, *maxedges, index, edges);
1007 }
1008
1009 void mpi_graph_map_ (int* comm_old, int* nnodes, int* index, int* edges, int* newrank, int* ierr) {
1010  *ierr = MPI_Graph_map(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, newrank);
1011 }
1012
1013 void mpi_graph_neighbors_ (int* comm, int* rank, int* maxneighbors, int* neighbors, int* ierr) {
1014  *ierr = MPI_Graph_neighbors(simgrid::smpi::Comm::f2c(*comm), *rank, *maxneighbors, neighbors);
1015 }
1016
1017 void mpi_graph_neighbors_count_ (int* comm, int* rank, int* nneighbors, int* ierr) {
1018  *ierr = MPI_Graph_neighbors_count(simgrid::smpi::Comm::f2c(*comm), *rank, nneighbors);
1019 }
1020
1021 void mpi_graphdims_get_ (int* comm, int* nnodes, int* nedges, int* ierr) {
1022  *ierr = MPI_Graphdims_get(simgrid::smpi::Comm::f2c(*comm), nnodes, nedges);
1023 }
1024
1025 void mpi_topo_test_ (int* comm, int* top_type, int* ierr) {
1026  *ierr = MPI_Topo_test(simgrid::smpi::Comm::f2c(*comm), top_type);
1027 }
1028
1029 void mpi_error_class_ (int* errorcode, int* errorclass, int* ierr) {
1030  *ierr = MPI_Error_class(*errorcode, errorclass);
1031 }
1032
1033 void mpi_errhandler_create_ (void* function, void* errhandler, int* ierr) {
1034  *ierr = MPI_Errhandler_create(reinterpret_cast<MPI_Handler_function*>(function), static_cast<MPI_Errhandler*>(errhandler));
1035 }
1036
1037 void mpi_errhandler_free_ (void* errhandler, int* ierr) {
1038  *ierr = MPI_Errhandler_free(static_cast<MPI_Errhandler*>(errhandler));
1039 }
1040
1041 void mpi_errhandler_get_ (int* comm, void* errhandler, int* ierr) {
1042  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
1043 }
1044
1045 void mpi_errhandler_set_ (int* comm, void* errhandler, int* ierr) {
1046  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
1047 }
1048
1049 void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
1050  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
1051 }
1052
1053 void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) {
1054  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
1055 }
1056
1057 void mpi_type_contiguous_ (int* count, int* old_type, int*  newtype, int* ierr) {
1058   MPI_Datatype tmp;
1059   *ierr = MPI_Type_contiguous(*count, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
1060   if(*ierr == MPI_SUCCESS) {
1061     *newtype = tmp->add_f();
1062   }
1063 }
1064
1065 void mpi_cancel_ (int* request, int* ierr) {
1066   MPI_Request tmp=simgrid::smpi::Request::f2c(*request);
1067  *ierr = MPI_Cancel(&tmp);
1068 }
1069
1070 void mpi_buffer_attach_ (void* buffer, int* size, int* ierr) {
1071  *ierr = MPI_Buffer_attach(buffer, *size);
1072 }
1073
1074 void mpi_buffer_detach_ (void* buffer, int* size, int* ierr) {
1075  *ierr = MPI_Buffer_detach(buffer, size);
1076 }
1077
1078 void mpi_testsome_ (int* incount, int*  requests, int* outcount, int* indices, MPI_Status*  statuses, int* ierr) {
1079   MPI_Request* reqs;
1080   int i;
1081
1082   reqs = xbt_new(MPI_Request, *incount);
1083   for(i = 0; i < *incount; i++) {
1084     reqs[i] = simgrid::smpi::Request::f2c(requests[i]);
1085     indices[i]=0;
1086   }
1087   *ierr = MPI_Testsome(*incount, reqs, outcount, indices, FORT_STATUSES_IGNORE(statuses));
1088   for(i=0;i<*incount;i++){
1089     if(indices[i] && reqs[indices[i]]==MPI_REQUEST_NULL){
1090       simgrid::smpi::Request::free_f(requests[indices[i]]);
1091       requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
1092     }
1093   }
1094   xbt_free(reqs);
1095 }
1096
1097 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
1098  *ierr = MPI_Comm_test_inter(simgrid::smpi::Comm::f2c(*comm), flag);
1099 }
1100
1101 void mpi_unpack_ (void* inbuf, int* insize, int* position, void* outbuf, int* outcount, int* type, int* comm,
1102                   int* ierr) {
1103  *ierr = MPI_Unpack(inbuf, *insize, position, outbuf, *outcount, simgrid::smpi::Datatype::f2c(*type), simgrid::smpi::Comm::f2c(*comm));
1104 }
1105
1106 void mpi_pack_external_size_ (char *datarep, int* incount, int* datatype, MPI_Aint *size, int* ierr){
1107  *ierr = MPI_Pack_external_size(datarep, *incount, simgrid::smpi::Datatype::f2c(*datatype), size);
1108 }
1109
1110 void mpi_pack_external_ (char *datarep, void *inbuf, int* incount, int* datatype, void *outbuf, MPI_Aint* outcount,
1111                          MPI_Aint *position, int* ierr){
1112  *ierr = MPI_Pack_external(datarep, inbuf, *incount, simgrid::smpi::Datatype::f2c(*datatype), outbuf, *outcount, position);
1113 }
1114
1115 void mpi_unpack_external_ ( char *datarep, void *inbuf, MPI_Aint* insize, MPI_Aint *position, void *outbuf,
1116                             int* outcount, int* datatype, int* ierr){
1117  *ierr = MPI_Unpack_external( datarep, inbuf, *insize, position, outbuf, *outcount, simgrid::smpi::Datatype::f2c(*datatype));
1118 }
1119
1120 void mpi_type_hindexed_ (int* count, int* blocklens, MPI_Aint* indices, int* old_type, int*  newtype, int* ierr) {
1121   MPI_Datatype tmp;
1122   *ierr = MPI_Type_hindexed(*count, blocklens, indices, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
1123   if(*ierr == MPI_SUCCESS) {
1124     *newtype = tmp->add_f();
1125   }
1126 }
1127
1128 void mpi_type_create_hindexed_(int* count, int* blocklens, MPI_Aint* indices, int* old_type, int*  newtype, int* ierr){
1129   MPI_Datatype tmp;
1130   *ierr = MPI_Type_create_hindexed(*count, blocklens, indices, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
1131   if(*ierr == MPI_SUCCESS) {
1132     *newtype = tmp->add_f();
1133   }
1134 }
1135
1136 void mpi_type_create_hindexed_block_ (int* count, int* blocklength, MPI_Aint* indices, int* old_type, int*  newtype,
1137                                       int* ierr) {
1138   MPI_Datatype tmp;
1139   *ierr = MPI_Type_create_hindexed_block(*count, *blocklength, indices, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
1140   if(*ierr == MPI_SUCCESS) {
1141     *newtype = tmp->add_f();
1142   }
1143 }
1144
1145 void mpi_type_indexed_ (int* count, int* blocklens, int* indices, int* old_type, int*  newtype, int* ierr) {
1146   MPI_Datatype tmp;
1147   *ierr = MPI_Type_indexed(*count, blocklens, indices, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
1148   if(*ierr == MPI_SUCCESS) {
1149     *newtype = tmp->add_f();
1150   }
1151 }
1152
1153 void mpi_type_create_indexed_block_ (int* count, int* blocklength, int* indices,  int* old_type,  int*newtype,
1154                                      int* ierr){
1155   MPI_Datatype tmp;
1156   *ierr = MPI_Type_create_indexed_block(*count, *blocklength, indices, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
1157   if(*ierr == MPI_SUCCESS) {
1158     *newtype = tmp->add_f();
1159   }
1160 }
1161
1162 void mpi_type_struct_ (int* count, int* blocklens, MPI_Aint* indices, int* old_types, int*  newtype, int* ierr) {
1163   MPI_Datatype tmp;
1164   int i=0;
1165   MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
1166   for(i=0; i< *count; i++){
1167     types[i] = simgrid::smpi::Datatype::f2c(old_types[i]);
1168   }
1169   *ierr = MPI_Type_struct(*count, blocklens, indices, types, &tmp);
1170   if(*ierr == MPI_SUCCESS) {
1171     *newtype = tmp->add_f();
1172   }
1173   xbt_free(types);
1174 }
1175
1176 void mpi_type_create_struct_(int* count, int* blocklens, MPI_Aint* indices, int*  old_types, int*  newtype, int* ierr){
1177   MPI_Datatype tmp;
1178   int i=0;
1179   MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
1180   for(i=0; i< *count; i++){
1181     types[i] = simgrid::smpi::Datatype::f2c(old_types[i]);
1182   }
1183   *ierr = MPI_Type_create_struct(*count, blocklens, indices, types, &tmp);
1184   if(*ierr == MPI_SUCCESS) {
1185     *newtype = tmp->add_f();
1186   }
1187   xbt_free(types);
1188 }
1189
1190 void mpi_ssend_ (void* buf, int* count, int* datatype, int* dest, int* tag, int* comm, int* ierr) {
1191  *ierr = MPI_Ssend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm));
1192 }
1193
1194 void mpi_ssend_init_ (void* buf, int* count, int* datatype, int* dest, int* tag, int* comm, int* request, int* ierr) {
1195   MPI_Request tmp;
1196  *ierr = MPI_Ssend_init(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm), &tmp);
1197  if(*ierr == MPI_SUCCESS) {
1198    *request = tmp->add_f();
1199  }
1200 }
1201
1202 void mpi_intercomm_create_ (int* local_comm, int *local_leader, int* peer_comm, int* remote_leader, int* tag,
1203                             int* comm_out, int* ierr) {
1204   MPI_Comm tmp;
1205   *ierr = MPI_Intercomm_create(simgrid::smpi::Comm::f2c(*local_comm), *local_leader, simgrid::smpi::Comm::f2c(*peer_comm), *remote_leader,
1206                                *tag, &tmp);
1207   if(*ierr == MPI_SUCCESS) {
1208     *comm_out = tmp->add_f();
1209   }
1210 }
1211
1212 void mpi_intercomm_merge_ (int* comm, int* high, int*  comm_out, int* ierr) {
1213  MPI_Comm tmp;
1214  *ierr = MPI_Intercomm_merge(simgrid::smpi::Comm::f2c(*comm), *high, &tmp);
1215  if(*ierr == MPI_SUCCESS) {
1216    *comm_out = tmp->add_f();
1217  }
1218 }
1219
1220 void mpi_bsend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int* ierr) {
1221  *ierr = MPI_Bsend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm));
1222 }
1223
1224 void mpi_bsend_init_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int*  request, int* ierr) {
1225   MPI_Request tmp;
1226   *ierr = MPI_Bsend_init(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm), &tmp);
1227  if(*ierr == MPI_SUCCESS) {
1228    *request = tmp->add_f();
1229  }
1230 }
1231
1232 void mpi_ibsend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int*  request, int* ierr) {
1233   MPI_Request tmp;
1234   *ierr = MPI_Ibsend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm), &tmp);
1235  if(*ierr == MPI_SUCCESS) {
1236    *request = tmp->add_f();
1237  }
1238 }
1239
1240 void mpi_comm_remote_group_ (int* comm, int*  group, int* ierr) {
1241   MPI_Group tmp;
1242  *ierr = MPI_Comm_remote_group(simgrid::smpi::Comm::f2c(*comm), &tmp);
1243  if(*ierr == MPI_SUCCESS) {
1244    *group = tmp->c2f();
1245  }
1246 }
1247
1248 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
1249  *ierr = MPI_Comm_remote_size(simgrid::smpi::Comm::f2c(*comm), size);
1250 }
1251
1252 void mpi_issend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int*  request, int* ierr) {
1253   MPI_Request tmp;
1254   *ierr = MPI_Issend(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm), &tmp);
1255  if(*ierr == MPI_SUCCESS) {
1256    *request = tmp->add_f();
1257  }
1258 }
1259
1260 void mpi_probe_ (int* source, int* tag, int* comm, MPI_Status*  status, int* ierr) {
1261  *ierr = MPI_Probe(*source, *tag, simgrid::smpi::Comm::f2c(*comm), FORT_STATUS_IGNORE(status));
1262 }
1263
1264 void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) {
1265  *ierr = MPI_Attr_delete(simgrid::smpi::Comm::f2c(*comm), *keyval);
1266 }
1267
1268 void mpi_attr_put_ (int* comm, int* keyval, void* attr_value, int* ierr) {
1269  *ierr = MPI_Attr_put(simgrid::smpi::Comm::f2c(*comm), *keyval, attr_value);
1270 }
1271
1272 void mpi_rsend_init_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int*  request, int* ierr) {
1273   MPI_Request tmp;
1274   *ierr = MPI_Rsend_init(buf, *count, simgrid::smpi::Datatype::f2c(*datatype), *dest, *tag, simgrid::smpi::Comm::f2c(*comm), &tmp);
1275  if(*ierr == MPI_SUCCESS) {
1276    *request = tmp->add_f();
1277  }
1278 }
1279
1280 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
1281  *ierr = MPI_Keyval_create(reinterpret_cast<MPI_Copy_function*>(copy_fn),reinterpret_cast<MPI_Delete_function*>(delete_fn), keyval, extra_state);
1282 }
1283
1284 void mpi_keyval_free_ (int* keyval, int* ierr) {
1285  *ierr = MPI_Keyval_free(keyval);
1286 }
1287
1288 void mpi_test_cancelled_ (MPI_Status*  status, int* flag, int* ierr) {
1289  *ierr = MPI_Test_cancelled(status, flag);
1290 }
1291
1292 void mpi_pack_ (void* inbuf, int* incount, int* type, void* outbuf, int* outcount, int* position, int* comm, int* ierr) {
1293  *ierr = MPI_Pack(inbuf, *incount, simgrid::smpi::Datatype::f2c(*type), outbuf, *outcount, position, simgrid::smpi::Comm::f2c(*comm));
1294 }
1295
1296 void mpi_get_elements_ (MPI_Status*  status, int* datatype, int* elements, int* ierr) {
1297  *ierr = MPI_Get_elements(status, simgrid::smpi::Datatype::f2c(*datatype), elements);
1298 }
1299
1300 void mpi_dims_create_ (int* nnodes, int* ndims, int* dims, int* ierr) {
1301  *ierr = MPI_Dims_create(*nnodes, *ndims, dims);
1302 }
1303
1304 void mpi_iprobe_ (int* source, int* tag, int* comm, int* flag, MPI_Status*  status, int* ierr) {
1305  *ierr = MPI_Iprobe(*source, *tag, simgrid::smpi::Comm::f2c(*comm), flag, status);
1306 }
1307
1308 void mpi_type_get_envelope_ ( int* datatype, int *num_integers, int *num_addresses, int *num_datatypes, int *combiner,
1309                               int* ierr){
1310  *ierr = MPI_Type_get_envelope(  simgrid::smpi::Datatype::f2c(*datatype), num_integers,
1311  num_addresses, num_datatypes, combiner);
1312 }
1313
1314 void mpi_type_get_contents_ (int* datatype, int* max_integers, int* max_addresses, int* max_datatypes,
1315                              int* array_of_integers, MPI_Aint* array_of_addresses,
1316  int* array_of_datatypes, int* ierr){
1317  *ierr = MPI_Type_get_contents(simgrid::smpi::Datatype::f2c(*datatype), *max_integers, *max_addresses,*max_datatypes,
1318                                array_of_integers, array_of_addresses, reinterpret_cast<MPI_Datatype*>(array_of_datatypes));
1319 }
1320
1321 void mpi_type_create_darray_ (int* size, int* rank, int* ndims, int* array_of_gsizes, int* array_of_distribs,
1322                               int* array_of_dargs, int* array_of_psizes,
1323  int* order, int* oldtype, int*newtype, int* ierr) {
1324   MPI_Datatype tmp;
1325   *ierr = MPI_Type_create_darray(*size, *rank, *ndims,  array_of_gsizes,
1326   array_of_distribs,  array_of_dargs,  array_of_psizes,
1327   *order,  simgrid::smpi::Datatype::f2c(*oldtype), &tmp) ;
1328   if(*ierr == MPI_SUCCESS) {
1329     *newtype = tmp->add_f();
1330   }
1331 }
1332
1333 void mpi_type_create_resized_ (int* oldtype,MPI_Aint* lb, MPI_Aint* extent, int*newtype, int* ierr){
1334   MPI_Datatype tmp;
1335   *ierr = MPI_Type_create_resized(simgrid::smpi::Datatype::f2c(*oldtype),*lb, *extent, &tmp);
1336   if(*ierr == MPI_SUCCESS) {
1337     *newtype = tmp->add_f();
1338   }
1339 }
1340
1341 void mpi_type_create_subarray_ (int* ndims,int *array_of_sizes, int *array_of_subsizes, int *array_of_starts,
1342                                 int* order, int* oldtype, int*newtype, int* ierr){
1343   MPI_Datatype tmp;
1344   *ierr = MPI_Type_create_subarray(*ndims,array_of_sizes, array_of_subsizes, array_of_starts, *order,
1345                                    simgrid::smpi::Datatype::f2c(*oldtype), &tmp);
1346   if(*ierr == MPI_SUCCESS) {
1347     *newtype = tmp->add_f();
1348   }
1349 }
1350
1351 void mpi_type_match_size_ (int* typeclass,int* size,int* datatype, int* ierr){
1352   MPI_Datatype tmp;
1353   *ierr = MPI_Type_match_size(*typeclass,*size,&tmp);
1354   if(*ierr == MPI_SUCCESS) {
1355     *datatype = tmp->c2f();
1356   }
1357 }
1358
1359 void mpi_alltoallw_ ( void *sendbuf, int *sendcnts, int *sdispls, int* sendtypes, void *recvbuf, int *recvcnts,
1360                       int *rdispls, int* recvtypes, int* comm, int* ierr){
1361  *ierr = MPI_Alltoallw( sendbuf, sendcnts, sdispls, reinterpret_cast<MPI_Datatype*>(sendtypes), recvbuf, recvcnts, rdispls,
1362                         reinterpret_cast<MPI_Datatype*>(recvtypes), simgrid::smpi::Comm::f2c(*comm));
1363 }
1364
1365 void mpi_exscan_ (void *sendbuf, void *recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr){
1366  *ierr = MPI_Exscan(sendbuf, recvbuf, *count, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Comm::f2c(*comm));
1367 }
1368
1369 void mpi_comm_set_name_ (int* comm, char* name, int* ierr, int size){
1370  char* tname = xbt_new(char, size+1);
1371  strncpy(tname, name, size);
1372  tname[size]='\0';
1373  *ierr = MPI_Comm_set_name (simgrid::smpi::Comm::f2c(*comm), tname);
1374  xbt_free(tname);
1375 }
1376
1377 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
1378   MPI_Comm tmp;
1379   *ierr = MPI_Comm_dup_with_info(simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info),&tmp);
1380   if(*ierr == MPI_SUCCESS) {
1381     *newcomm = tmp->add_f();
1382   }
1383 }
1384
1385 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
1386   MPI_Comm tmp;
1387   *ierr = MPI_Comm_split_type(simgrid::smpi::Comm::f2c(*comm), *split_type, *key, simgrid::smpi::Info::f2c(*info), &tmp);
1388   if(*ierr == MPI_SUCCESS) {
1389     *newcomm = tmp->add_f();
1390   }
1391 }
1392
1393 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
1394  *ierr = MPI_Comm_set_info (simgrid::smpi::Comm::f2c(*comm), simgrid::smpi::Info::f2c(*info));
1395 }
1396
1397 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
1398  MPI_Info tmp;
1399  *ierr = MPI_Comm_get_info (simgrid::smpi::Comm::f2c(*comm), &tmp);
1400  if(*ierr==MPI_SUCCESS){
1401    *info = tmp->c2f();
1402  }
1403 }
1404
1405 void mpi_comm_create_errhandler_ ( void *function, void *errhandler, int* ierr){
1406  *ierr = MPI_Comm_create_errhandler( reinterpret_cast<MPI_Comm_errhandler_fn*>(function), static_cast<MPI_Errhandler*>(errhandler));
1407 }
1408
1409 void mpi_add_error_class_ ( int *errorclass, int* ierr){
1410  *ierr = MPI_Add_error_class( errorclass);
1411 }
1412
1413 void mpi_add_error_code_ (  int* errorclass, int *errorcode, int* ierr){
1414  *ierr = MPI_Add_error_code(*errorclass, errorcode);
1415 }
1416
1417 void mpi_add_error_string_ ( int* errorcode, char *string, int* ierr){
1418  *ierr = MPI_Add_error_string(*errorcode, string);
1419 }
1420
1421 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
1422  *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode);
1423 }
1424
1425 void mpi_info_dup_ (int* info, int* newinfo, int* ierr){
1426  MPI_Info tmp;
1427  *ierr = MPI_Info_dup(simgrid::smpi::Info::f2c(*info), &tmp);
1428  if(*ierr==MPI_SUCCESS){
1429    *newinfo= tmp->add_f();
1430  }
1431 }
1432
1433 void mpi_info_get_valuelen_ ( int* info, char *key, int *valuelen, int *flag, int* ierr, unsigned int keylen){
1434   while(key[keylen-1]==' ')
1435     keylen--;
1436   while(*key==' '){//handle leading blanks
1437     keylen--;
1438     key++;
1439   }
1440   char* tkey = xbt_new(char, keylen+1);
1441   strncpy(tkey, key, keylen);
1442   tkey[keylen]='\0';
1443   *ierr = MPI_Info_get_valuelen( simgrid::smpi::Info::f2c(*info), tkey, valuelen, flag);
1444   xbt_free(tkey);
1445 }
1446
1447 void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){
1448   while(key[keylen-1]==' ')
1449     keylen--;
1450   while(*key==' '){//handle leading blanks
1451     keylen--;
1452     key++;
1453   }
1454   char* tkey = xbt_new(char, keylen+1);
1455   strncpy(tkey, key, keylen);
1456   tkey[keylen]='\0';
1457   *ierr = MPI_Info_delete(simgrid::smpi::Info::f2c(*info), tkey);
1458   xbt_free(tkey);
1459 }
1460
1461 void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
1462  *ierr = MPI_Info_get_nkeys(  simgrid::smpi::Info::f2c(*info), nkeys);
1463 }
1464
1465 void mpi_info_get_nthkey_ ( int* info, int* n, char *key, int* ierr, unsigned int keylen){
1466   *ierr = MPI_Info_get_nthkey( simgrid::smpi::Info::f2c(*info), *n, key);
1467   unsigned int i = 0;
1468   for (i=strlen(key); i<keylen; i++)
1469     key[i]=' ';
1470 }
1471
1472 void mpi_get_version_ (int *version,int *subversion, int* ierr){
1473  *ierr = MPI_Get_version (version,subversion);
1474 }
1475
1476 void mpi_get_library_version_ (char *version,int *len, int* ierr){
1477  *ierr = MPI_Get_library_version (version,len);
1478 }
1479
1480 void mpi_request_get_status_ ( int* request, int *flag, MPI_Status* status, int* ierr){
1481  *ierr = MPI_Request_get_status( simgrid::smpi::Request::f2c(*request), flag, status);
1482 }
1483
1484 void mpi_grequest_start_ ( void *query_fn, void *free_fn, void *cancel_fn, void *extra_state, int*request, int* ierr){
1485   MPI_Request tmp;
1486   *ierr = MPI_Grequest_start( reinterpret_cast<MPI_Grequest_query_function*>(query_fn), reinterpret_cast<MPI_Grequest_free_function*>(free_fn),
1487                               reinterpret_cast<MPI_Grequest_cancel_function*>(cancel_fn), extra_state, &tmp);
1488  if(*ierr == MPI_SUCCESS) {
1489    *request = tmp->add_f();
1490  }
1491 }
1492
1493 void mpi_grequest_complete_ ( int* request, int* ierr){
1494  *ierr = MPI_Grequest_complete( simgrid::smpi::Request::f2c(*request));
1495 }
1496
1497 void mpi_status_set_cancelled_ (MPI_Status* status,int* flag, int* ierr){
1498  *ierr = MPI_Status_set_cancelled(status,*flag);
1499 }
1500
1501 void mpi_status_set_elements_ ( MPI_Status* status, int* datatype, int* count, int* ierr){
1502  *ierr = MPI_Status_set_elements( status, simgrid::smpi::Datatype::f2c(*datatype), *count);
1503 }
1504
1505 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
1506   MPI_Comm tmp;
1507   *ierr = MPI_Comm_connect( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
1508   if(*ierr == MPI_SUCCESS) {
1509     *newcomm = tmp->add_f();
1510   }
1511 }
1512
1513 void mpi_publish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
1514  *ierr = MPI_Publish_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
1515 }
1516
1517 void mpi_unpublish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
1518  *ierr = MPI_Unpublish_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
1519 }
1520
1521 void mpi_lookup_name_ ( char *service_name, int* info, char *port_name, int* ierr){
1522  *ierr = MPI_Lookup_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
1523 }
1524
1525 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
1526   MPI_Comm tmp;
1527   *ierr = MPI_Comm_join( *fd, &tmp);
1528   if(*ierr == MPI_SUCCESS) {
1529     *intercomm = tmp->add_f();
1530   }
1531 }
1532
1533 void mpi_open_port_ ( int* info, char *port_name, int* ierr){
1534  *ierr = MPI_Open_port( *reinterpret_cast<MPI_Info*>(info),port_name);
1535 }
1536
1537 void mpi_close_port_ ( char *port_name, int* ierr){
1538  *ierr = MPI_Close_port( port_name);
1539 }
1540
1541 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
1542   MPI_Comm tmp;
1543   *ierr = MPI_Comm_accept( port_name, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp);
1544   if(*ierr == MPI_SUCCESS) {
1545     *newcomm = tmp->add_f();
1546   }
1547 }
1548
1549 void mpi_comm_spawn_ ( char *command, char *argv, int* maxprocs, int* info, int* root, int* comm, int* intercomm,
1550                        int* array_of_errcodes, int* ierr){
1551   MPI_Comm tmp;
1552   *ierr = MPI_Comm_spawn( command, nullptr, *maxprocs, *reinterpret_cast<MPI_Info*>(info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp,
1553                           array_of_errcodes);
1554   if(*ierr == MPI_SUCCESS) {
1555     *intercomm = tmp->add_f();
1556   }
1557 }
1558
1559 void mpi_comm_spawn_multiple_ ( int* count, char *array_of_commands, char** array_of_argv, int* array_of_maxprocs,
1560                                 int* array_of_info, int* root,
1561  int* comm, int* intercomm, int* array_of_errcodes, int* ierr){
1562  MPI_Comm tmp;
1563  *ierr = MPI_Comm_spawn_multiple(* count, &array_of_commands, &array_of_argv, array_of_maxprocs,
1564  reinterpret_cast<MPI_Info*>(array_of_info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp, array_of_errcodes);
1565  if(*ierr == MPI_SUCCESS) {
1566    *intercomm = tmp->add_f();
1567  }
1568 }
1569
1570 void mpi_comm_get_parent_ ( int* parent, int* ierr){
1571   MPI_Comm tmp;
1572   *ierr = MPI_Comm_get_parent( &tmp);
1573   if(*ierr == MPI_SUCCESS) {
1574     *parent = tmp->c2f();
1575   }
1576 }
1577
1578 void mpi_file_close_ ( int* file, int* ierr){
1579   *ierr= MPI_File_close(reinterpret_cast<MPI_File*>(*file));
1580 }
1581
1582 void mpi_file_delete_ ( char* filename, int* info, int* ierr){
1583   *ierr= MPI_File_delete(filename, simgrid::smpi::Info::f2c(*info));
1584 }
1585
1586 void mpi_file_open_ ( int* comm, char* filename, int* amode, int* info, int* fh, int* ierr){
1587   *ierr= MPI_File_open(simgrid::smpi::Comm::f2c(*comm), filename, *amode, simgrid::smpi::Info::f2c(*info), reinterpret_cast<MPI_File*>(*fh));
1588 }
1589
1590 void mpi_file_set_view_ ( int* fh, long long int* offset, int* etype, int* filetype, char* datarep, int* info, int* ierr){
1591   *ierr= MPI_File_set_view(reinterpret_cast<MPI_File>(*fh) , reinterpret_cast<MPI_Offset>(*offset), simgrid::smpi::Datatype::f2c(*etype), simgrid::smpi::Datatype::f2c(*filetype), datarep, simgrid::smpi::Info::f2c(*info));
1592 }
1593
1594 void mpi_file_read_ ( int* fh, void* buf, int* count, int* datatype, MPI_Status* status, int* ierr){
1595   *ierr=  MPI_File_read(reinterpret_cast<MPI_File>(*fh), buf, *count, simgrid::smpi::Datatype::f2c(*datatype), status);
1596 }
1597
1598 void mpi_file_write_ ( int* fh, void* buf, int* count, int* datatype, MPI_Status* status, int* ierr){
1599   *ierr=  MPI_File_write(reinterpret_cast<MPI_File>(*fh), buf, *count, simgrid::smpi::Datatype::f2c(*datatype), status);
1600 }
1601
1602 } // extern "C"