Logo AND Algorithmique Numérique Distribuée

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