Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c917e2a124480e3d5691962966b9014499801c0b
[simgrid.git] / src / smpi / bindings / 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 "private.h"
7 #include "smpi_comm.hpp"
8 #include "smpi_datatype.hpp"
9 #include "smpi_op.hpp"
10 #include "smpi_process.hpp"
11 #include "smpi_request.hpp"
12 #include "smpi_win.hpp"
13
14 static int running_processes = 0;
15
16 static void smpi_init_fortran_types(){
17    if(simgrid::smpi::F2C::lookup() == nullptr){
18      MPI_COMM_WORLD->add_f();
19      MPI_BYTE->add_f();//MPI_BYTE
20      MPI_CHAR->add_f();//MPI_CHARACTER
21 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
22      MPI_C_BOOL->add_f();//MPI_LOGICAL
23      MPI_INT->add_f();//MPI_INTEGER
24 #else
25      MPI_C_BOOL->add_f();//MPI_LOGICAL
26      MPI_LONG->add_f();//MPI_INTEGER
27 #endif
28      MPI_INT8_T->add_f();//MPI_INTEGER1
29      MPI_INT16_T->add_f();//MPI_INTEGER2
30      MPI_INT32_T->add_f();//MPI_INTEGER4
31      MPI_INT64_T->add_f();//MPI_INTEGER8
32      MPI_REAL->add_f();//MPI_REAL
33      MPI_REAL4->add_f();//MPI_REAL4
34      MPI_REAL8->add_f();//MPI_REAL8
35      MPI_DOUBLE->add_f();//MPI_DOUBLE_PRECISION
36      MPI_C_FLOAT_COMPLEX->add_f();//MPI_COMPLEX
37      MPI_C_DOUBLE_COMPLEX->add_f();//MPI_DOUBLE_COMPLEX
38 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
39      MPI_2INT->add_f();//MPI_2INTEGER
40 #else
41      MPI_2LONG->add_f();//MPI_2INTEGER
42 #endif
43      MPI_UINT8_T->add_f();//MPI_LOGICAL1
44      MPI_UINT16_T->add_f();//MPI_LOGICAL2
45      MPI_UINT32_T->add_f();//MPI_LOGICAL4
46      MPI_UINT64_T->add_f();//MPI_LOGICAL8
47      MPI_2FLOAT->add_f();//MPI_2REAL
48      MPI_2DOUBLE->add_f();//MPI_2DOUBLE_PRECISION
49      MPI_PTR->add_f();//MPI_AINT
50      MPI_OFFSET->add_f();//MPI_OFFSET
51      MPI_AINT->add_f();//MPI_COUNT
52      MPI_REAL16->add_f();//MPI_REAL16
53      MPI_PACKED->add_f();//MPI_PACKED
54
55      MPI_MAX->add_f();
56      MPI_MIN->add_f();
57      MPI_MAXLOC->add_f();
58      MPI_MINLOC->add_f();
59      MPI_SUM->add_f();
60      MPI_PROD->add_f();
61      MPI_LAND->add_f();
62      MPI_LOR->add_f();
63      MPI_LXOR->add_f();
64      MPI_BAND->add_f();
65      MPI_BOR->add_f();
66      MPI_BXOR->add_f();
67    }
68 }
69
70 extern "C" { // This should really use the C linkage to be usable from Fortran
71
72
73 void mpi_init_(int* ierr) {
74     smpi_init_fortran_types();
75    *ierr = MPI_Init(nullptr, nullptr);
76    running_processes++;
77 }
78
79 void mpi_finalize_(int* ierr) {
80    *ierr = MPI_Finalize();
81    running_processes--;
82    if(running_processes==0){
83       simgrid::smpi::F2C::delete_lookup();
84    }
85 }
86
87 void mpi_abort_(int* comm, int* errorcode, int* ierr) {
88   *ierr = MPI_Abort(simgrid::smpi::Comm::f2c(*comm), *errorcode);
89 }
90
91 double mpi_wtime_() {
92    return MPI_Wtime();
93 }
94
95 double mpi_wtick_() {
96   return MPI_Wtick();
97 }
98
99 void mpi_group_incl_(int* group, int* n, int* ranks, int* group_out, int* ierr) {
100   MPI_Group tmp;
101
102   *ierr = MPI_Group_incl(simgrid::smpi::Group::f2c(*group), *n, ranks, &tmp);
103   if(*ierr == MPI_SUCCESS) {
104     *group_out = tmp->add_f();
105   }
106 }
107
108 void mpi_initialized_(int* flag, int* ierr){
109   *ierr = MPI_Initialized(flag);
110 }
111
112 void mpi_get_processor_name_(char *name, int *resultlen, int* ierr){
113   *ierr = MPI_Get_processor_name(name, resultlen);
114 }
115
116 void mpi_get_count_(MPI_Status * status, int* datatype, int *count, int* ierr){
117   *ierr = MPI_Get_count(FORT_STATUS_IGNORE(status), simgrid::smpi::Datatype::f2c(*datatype), count);
118 }
119
120 void mpi_attr_get_(int* comm, int* keyval, void* attr_value, int* flag, int* ierr ){
121   *ierr = MPI_Attr_get(simgrid::smpi::Comm::f2c(*comm), *keyval, attr_value, flag);
122 }
123
124 void mpi_error_string_(int* errorcode, char* string, int* resultlen, int* ierr){
125   *ierr = MPI_Error_string(*errorcode, string, resultlen);
126 }
127
128 void mpi_win_fence_( int* assert,  int* win, int* ierr){
129   *ierr =  MPI_Win_fence(* assert, simgrid::smpi::Win::f2c(*win));
130 }
131
132 void mpi_win_free_( int* win, int* ierr){
133   MPI_Win tmp = simgrid::smpi::Win::f2c(*win);
134   *ierr =  MPI_Win_free(&tmp);
135   if(*ierr == MPI_SUCCESS) {
136     simgrid::smpi::F2C::free_f(*win);
137   }
138 }
139
140 void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr){
141   MPI_Win tmp;
142   *ierr =  MPI_Win_create( static_cast<void*>(base), *size, *disp_unit, simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),&tmp);
143  if(*ierr == MPI_SUCCESS) {
144    *win = tmp->add_f();
145  }
146 }
147
148 void mpi_win_post_(int* group, int assert, int* win, int* ierr){
149   *ierr =  MPI_Win_post(simgrid::smpi::Group::f2c(*group), assert, simgrid::smpi::Win::f2c(*win));
150 }
151
152 void mpi_win_start_(int* group, int assert, int* win, int* ierr){
153   *ierr =  MPI_Win_start(simgrid::smpi::Group::f2c(*group), assert, simgrid::smpi::Win::f2c(*win));
154 }
155
156 void mpi_win_complete_(int* win, int* ierr){
157   *ierr =  MPI_Win_complete(simgrid::smpi::Win::f2c(*win));
158 }
159
160 void mpi_win_wait_(int* win, int* ierr){
161   *ierr =  MPI_Win_wait(simgrid::smpi::Win::f2c(*win));
162 }
163
164 void mpi_win_set_name_ (int*  win, char * name, int* ierr, int size){
165   //handle trailing blanks
166   while(name[size-1]==' ')
167     size--;
168   while(*name==' '){//handle leading blanks
169     size--;
170     name++;
171   }
172   char* tname = xbt_new(char,size+1);
173   strncpy(tname, name, size);
174   tname[size]='\0';
175   *ierr = MPI_Win_set_name(simgrid::smpi::Win::f2c(*win), tname);
176   xbt_free(tname);
177 }
178
179 void mpi_win_get_name_ (int*  win, char * name, int* len, int* ierr){
180   *ierr = MPI_Win_get_name(simgrid::smpi::Win::f2c(*win),name,len);
181   if(*len>0)
182     name[*len]=' ';//blank padding, not \0
183 }
184
185 void mpi_info_create_( int *info, int* ierr){
186   MPI_Info tmp;
187   *ierr =  MPI_Info_create(&tmp);
188   if(*ierr == MPI_SUCCESS) {
189     *info = tmp->add_f();
190   }
191 }
192
193 void mpi_info_set_( int *info, char *key, char *value, int* ierr, unsigned int keylen, unsigned int valuelen){
194   //handle trailing blanks
195   while(key[keylen-1]==' ')
196     keylen--;
197   while(*key==' '){//handle leading blanks
198     keylen--;
199     key++;
200   }
201   char* tkey = xbt_new(char,keylen+1);
202   strncpy(tkey, key, keylen);
203   tkey[keylen]='\0';
204
205   while(value[valuelen-1]==' ')
206     valuelen--;
207   while(*value==' '){//handle leading blanks
208     valuelen--;
209     value++;
210   }
211   char* tvalue = xbt_new(char,valuelen+1);
212   strncpy(tvalue, value, valuelen);
213   tvalue[valuelen]='\0';
214
215   *ierr =  MPI_Info_set( simgrid::smpi::Info::f2c(*info), tkey, tvalue);
216   xbt_free(tkey);
217   xbt_free(tvalue);
218 }
219
220 void mpi_info_get_ (int* info,char *key,int* valuelen, char *value, int *flag, int* ierr, unsigned int keylen ){
221   while(key[keylen-1]==' ')
222     keylen--;
223   while(*key==' '){//handle leading blanks
224     keylen--;
225     key++;
226   }
227   char* tkey = xbt_new(char,keylen+1);
228   strncpy(tkey, key, keylen);
229   tkey[keylen]='\0';
230   *ierr = MPI_Info_get(simgrid::smpi::Info::f2c(*info),tkey,*valuelen, value, flag);
231   xbt_free(tkey);
232   if(*flag!=0){
233     int replace=0;
234     int i=0;
235     for (i=0; i<*valuelen; i++){
236       if(value[i]=='\0')
237         replace=1;
238       if(replace)
239         value[i]=' ';
240     }
241   }
242 }
243
244 void mpi_info_free_(int* info, int* ierr){
245   MPI_Info tmp = simgrid::smpi::Info::f2c(*info);
246   *ierr =  MPI_Info_free(&tmp);
247   if(*ierr == MPI_SUCCESS) {
248     simgrid::smpi::F2C::free_f(*info);
249   }
250 }
251
252 void mpi_get_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
253     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
254   *ierr =  MPI_Get( static_cast<void*>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
255       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win));
256 }
257
258 void mpi_accumulate_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
259     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* op, int* win, int* ierr){
260   *ierr =  MPI_Accumulate( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
261       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win));
262 }
263
264 void mpi_put_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
265     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
266   *ierr =  MPI_Put( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
267       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win));
268 }
269
270 //following are automatically generated, and have to be checked
271 void mpi_finalized_ (int * flag, int* ierr){
272
273  *ierr = MPI_Finalized(flag);
274 }
275
276 void mpi_init_thread_ (int* required, int *provided, int* ierr){
277   smpi_init_fortran_types();
278   *ierr = MPI_Init_thread(nullptr, nullptr,*required, provided);
279   running_processes++;
280 }
281
282 void mpi_query_thread_ (int *provided, int* ierr){
283
284  *ierr = MPI_Query_thread(provided);
285 }
286
287 void mpi_is_thread_main_ (int *flag, int* ierr){
288
289  *ierr = MPI_Is_thread_main(flag);
290 }
291
292 void mpi_address_ (void *location, MPI_Aint * address, int* ierr){
293
294  *ierr = MPI_Address(location, address);
295 }
296
297 void mpi_get_address_ (void *location, MPI_Aint * address, int* ierr){
298
299  *ierr = MPI_Get_address(location, address);
300 }
301
302 void mpi_pcontrol_ (int* level , int* ierr){
303  *ierr = MPI_Pcontrol(*static_cast<const int*>(level));
304 }
305
306 void mpi_op_create_ (void * function, int* commute, int* op, int* ierr){
307   MPI_Op tmp;
308  *ierr = MPI_Op_create(reinterpret_cast<MPI_User_function*>(function),*commute, &tmp);
309  if(*ierr == MPI_SUCCESS) {
310    tmp->set_fortran_op();
311    *op = tmp->add_f();
312  }
313 }
314
315 void mpi_op_free_ (int* op, int* ierr){
316   MPI_Op tmp= simgrid::smpi::Op::f2c(*op);
317   *ierr = MPI_Op_free(& tmp);
318   if(*ierr == MPI_SUCCESS) {
319     simgrid::smpi::F2C::free_f(*op);
320   }
321 }
322
323 void mpi_group_free_ (int* group, int* ierr){
324  MPI_Group tmp = simgrid::smpi::Group::f2c(*group);
325  *ierr = MPI_Group_free(&tmp);
326  if(*ierr == MPI_SUCCESS) {
327    simgrid::smpi::F2C::free_f(*group);
328  }
329 }
330
331 void mpi_group_size_ (int* group, int *size, int* ierr){
332
333  *ierr = MPI_Group_size(simgrid::smpi::Group::f2c(*group), size);
334 }
335
336 void mpi_group_rank_ (int* group, int *rank, int* ierr){
337
338  *ierr = MPI_Group_rank(simgrid::smpi::Group::f2c(*group), rank);
339 }
340
341 void mpi_group_translate_ranks_ (int* group1, int* n, int *ranks1, int* group2, int *ranks2, int* ierr)
342 {
343
344  *ierr = MPI_Group_translate_ranks(simgrid::smpi::Group::f2c(*group1), *n, ranks1, simgrid::smpi::Group::f2c(*group2), ranks2);
345 }
346
347 void mpi_group_compare_ (int* group1, int* group2, int *result, int* ierr){
348
349  *ierr = MPI_Group_compare(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), result);
350 }
351
352 void mpi_group_union_ (int* group1, int* group2, int* newgroup, int* ierr){
353  MPI_Group tmp;
354  *ierr = MPI_Group_union(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
355  if(*ierr == MPI_SUCCESS) {
356    *newgroup = tmp->add_f();
357  }
358 }
359
360 void mpi_group_intersection_ (int* group1, int* group2, int* newgroup, int* ierr){
361  MPI_Group tmp;
362  *ierr = MPI_Group_intersection(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
363  if(*ierr == MPI_SUCCESS) {
364    *newgroup = tmp->add_f();
365  }
366 }
367
368 void mpi_group_difference_ (int* group1, int* group2, int* newgroup, int* ierr){
369  MPI_Group tmp;
370  *ierr = MPI_Group_difference(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
371  if(*ierr == MPI_SUCCESS) {
372    *newgroup = tmp->add_f();
373  }
374 }
375
376 void mpi_group_excl_ (int* group, int* n, int *ranks, int* newgroup, int* ierr){
377   MPI_Group tmp;
378  *ierr = MPI_Group_excl(simgrid::smpi::Group::f2c(*group), *n, ranks, &tmp);
379  if(*ierr == MPI_SUCCESS) {
380    *newgroup = tmp->add_f();
381  }
382 }
383
384 void mpi_group_range_incl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
385 {
386   MPI_Group tmp;
387  *ierr = MPI_Group_range_incl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp);
388  if(*ierr == MPI_SUCCESS) {
389    *newgroup = tmp->add_f();
390  }
391 }
392
393 void mpi_group_range_excl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
394 {
395  MPI_Group tmp;
396  *ierr = MPI_Group_range_excl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp);
397  if(*ierr == MPI_SUCCESS) {
398    *newgroup = tmp->add_f();
399  }
400 }
401
402 void mpi_request_free_ (int* request, int* ierr){
403   MPI_Request tmp=simgrid::smpi::Request::f2c(*request);
404  *ierr = MPI_Request_free(&tmp);
405  if(*ierr == MPI_SUCCESS) {
406    simgrid::smpi::Request::free_f(*request);
407  }
408 }
409
410 void mpi_pack_size_ (int* incount, int* datatype, int* comm, int* size, int* ierr) {
411  *ierr = MPI_Pack_size(*incount, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Comm::f2c(*comm), size);
412 }
413
414 void mpi_cart_coords_ (int* comm, int* rank, int* maxdims, int* coords, int* ierr) {
415  *ierr = MPI_Cart_coords(simgrid::smpi::Comm::f2c(*comm), *rank, *maxdims, coords);
416 }
417
418 void mpi_cart_create_ (int* comm_old, int* ndims, int* dims, int* periods, int* reorder, int*  comm_cart, int* ierr) {
419   MPI_Comm tmp;
420  *ierr = MPI_Cart_create(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, *reorder, &tmp);
421  if(*ierr == MPI_SUCCESS) {
422    *comm_cart = tmp->add_f();
423  }
424 }
425
426 void mpi_cart_get_ (int* comm, int* maxdims, int* dims, int* periods, int* coords, int* ierr) {
427  *ierr = MPI_Cart_get(simgrid::smpi::Comm::f2c(*comm), *maxdims, dims, periods, coords);
428 }
429
430 void mpi_cart_map_ (int* comm_old, int* ndims, int* dims, int* periods, int* newrank, int* ierr) {
431  *ierr = MPI_Cart_map(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, newrank);
432 }
433
434 void mpi_cart_rank_ (int* comm, int* coords, int* rank, int* ierr) {
435  *ierr = MPI_Cart_rank(simgrid::smpi::Comm::f2c(*comm), coords, rank);
436 }
437
438 void mpi_cart_shift_ (int* comm, int* direction, int* displ, int* source, int* dest, int* ierr) {
439  *ierr = MPI_Cart_shift(simgrid::smpi::Comm::f2c(*comm), *direction, *displ, source, dest);
440 }
441
442 void mpi_cart_sub_ (int* comm, int* remain_dims, int*  comm_new, int* ierr) {
443  MPI_Comm tmp;
444  *ierr = MPI_Cart_sub(simgrid::smpi::Comm::f2c(*comm), remain_dims, &tmp);
445  if(*ierr == MPI_SUCCESS) {
446    *comm_new = tmp->add_f();
447  }
448 }
449
450 void mpi_cartdim_get_ (int* comm, int* ndims, int* ierr) {
451  *ierr = MPI_Cartdim_get(simgrid::smpi::Comm::f2c(*comm), ndims);
452 }
453
454 void mpi_graph_create_ (int* comm_old, int* nnodes, int* index, int* edges, int* reorder, int*  comm_graph, int* ierr) {
455   MPI_Comm tmp;
456  *ierr = MPI_Graph_create(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, *reorder, &tmp);
457  if(*ierr == MPI_SUCCESS) {
458    *comm_graph = tmp->add_f();
459  }
460 }
461
462 void mpi_graph_get_ (int* comm, int* maxindex, int* maxedges, int* index, int* edges, int* ierr) {
463  *ierr = MPI_Graph_get(simgrid::smpi::Comm::f2c(*comm), *maxindex, *maxedges, index, edges);
464 }
465
466 void mpi_graph_map_ (int* comm_old, int* nnodes, int* index, int* edges, int* newrank, int* ierr) {
467  *ierr = MPI_Graph_map(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, newrank);
468 }
469
470 void mpi_graph_neighbors_ (int* comm, int* rank, int* maxneighbors, int* neighbors, int* ierr) {
471  *ierr = MPI_Graph_neighbors(simgrid::smpi::Comm::f2c(*comm), *rank, *maxneighbors, neighbors);
472 }
473
474 void mpi_graph_neighbors_count_ (int* comm, int* rank, int* nneighbors, int* ierr) {
475  *ierr = MPI_Graph_neighbors_count(simgrid::smpi::Comm::f2c(*comm), *rank, nneighbors);
476 }
477
478 void mpi_graphdims_get_ (int* comm, int* nnodes, int* nedges, int* ierr) {
479  *ierr = MPI_Graphdims_get(simgrid::smpi::Comm::f2c(*comm), nnodes, nedges);
480 }
481
482 void mpi_topo_test_ (int* comm, int* top_type, int* ierr) {
483  *ierr = MPI_Topo_test(simgrid::smpi::Comm::f2c(*comm), top_type);
484 }
485
486 void mpi_error_class_ (int* errorcode, int* errorclass, int* ierr) {
487  *ierr = MPI_Error_class(*errorcode, errorclass);
488 }
489
490 void mpi_errhandler_create_ (void* function, void* errhandler, int* ierr) {
491  *ierr = MPI_Errhandler_create(reinterpret_cast<MPI_Handler_function*>(function), static_cast<MPI_Errhandler*>(errhandler));
492 }
493
494 void mpi_errhandler_free_ (void* errhandler, int* ierr) {
495  *ierr = MPI_Errhandler_free(static_cast<MPI_Errhandler*>(errhandler));
496 }
497
498 void mpi_errhandler_get_ (int* comm, void* errhandler, int* ierr) {
499  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
500 }
501
502 void mpi_errhandler_set_ (int* comm, void* errhandler, int* ierr) {
503  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
504 }
505
506 void mpi_cancel_ (int* request, int* ierr) {
507   MPI_Request tmp=simgrid::smpi::Request::f2c(*request);
508  *ierr = MPI_Cancel(&tmp);
509 }
510
511 void mpi_buffer_attach_ (void* buffer, int* size, int* ierr) {
512  *ierr = MPI_Buffer_attach(buffer, *size);
513 }
514
515 void mpi_buffer_detach_ (void* buffer, int* size, int* ierr) {
516  *ierr = MPI_Buffer_detach(buffer, size);
517 }
518
519
520
521 void mpi_intercomm_create_ (int* local_comm, int *local_leader, int* peer_comm, int* remote_leader, int* tag,
522                             int* comm_out, int* ierr) {
523   MPI_Comm tmp;
524   *ierr = MPI_Intercomm_create(simgrid::smpi::Comm::f2c(*local_comm), *local_leader, simgrid::smpi::Comm::f2c(*peer_comm), *remote_leader,
525                                *tag, &tmp);
526   if(*ierr == MPI_SUCCESS) {
527     *comm_out = tmp->add_f();
528   }
529 }
530
531 void mpi_intercomm_merge_ (int* comm, int* high, int*  comm_out, int* ierr) {
532  MPI_Comm tmp;
533  *ierr = MPI_Intercomm_merge(simgrid::smpi::Comm::f2c(*comm), *high, &tmp);
534  if(*ierr == MPI_SUCCESS) {
535    *comm_out = tmp->add_f();
536  }
537 }
538
539 void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) {
540  *ierr = MPI_Attr_delete(simgrid::smpi::Comm::f2c(*comm), *keyval);
541 }
542
543 void mpi_attr_put_ (int* comm, int* keyval, void* attr_value, int* ierr) {
544  *ierr = MPI_Attr_put(simgrid::smpi::Comm::f2c(*comm), *keyval, attr_value);
545 }
546
547 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
548  *ierr = MPI_Keyval_create(reinterpret_cast<MPI_Copy_function*>(copy_fn),reinterpret_cast<MPI_Delete_function*>(delete_fn), keyval, extra_state);
549 }
550
551 void mpi_keyval_free_ (int* keyval, int* ierr) {
552  *ierr = MPI_Keyval_free(keyval);
553 }
554
555 void mpi_test_cancelled_ (MPI_Status*  status, int* flag, int* ierr) {
556  *ierr = MPI_Test_cancelled(status, flag);
557 }
558
559 void mpi_get_elements_ (MPI_Status*  status, int* datatype, int* elements, int* ierr) {
560  *ierr = MPI_Get_elements(status, simgrid::smpi::Datatype::f2c(*datatype), elements);
561 }
562
563 void mpi_dims_create_ (int* nnodes, int* ndims, int* dims, int* ierr) {
564  *ierr = MPI_Dims_create(*nnodes, *ndims, dims);
565 }
566
567 void mpi_add_error_class_ ( int *errorclass, int* ierr){
568  *ierr = MPI_Add_error_class( errorclass);
569 }
570
571 void mpi_add_error_code_ (  int* errorclass, int *errorcode, int* ierr){
572  *ierr = MPI_Add_error_code(*errorclass, errorcode);
573 }
574
575 void mpi_add_error_string_ ( int* errorcode, char *string, int* ierr){
576  *ierr = MPI_Add_error_string(*errorcode, string);
577 }
578
579 void mpi_info_dup_ (int* info, int* newinfo, int* ierr){
580  MPI_Info tmp;
581  *ierr = MPI_Info_dup(simgrid::smpi::Info::f2c(*info), &tmp);
582  if(*ierr==MPI_SUCCESS){
583    *newinfo= tmp->add_f();
584  }
585 }
586
587 void mpi_info_get_valuelen_ ( int* info, char *key, int *valuelen, int *flag, int* ierr, unsigned int keylen){
588   while(key[keylen-1]==' ')
589     keylen--;
590   while(*key==' '){//handle leading blanks
591     keylen--;
592     key++;
593   }
594   char* tkey = xbt_new(char, keylen+1);
595   strncpy(tkey, key, keylen);
596   tkey[keylen]='\0';
597   *ierr = MPI_Info_get_valuelen( simgrid::smpi::Info::f2c(*info), tkey, valuelen, flag);
598   xbt_free(tkey);
599 }
600
601 void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){
602   while(key[keylen-1]==' ')
603     keylen--;
604   while(*key==' '){//handle leading blanks
605     keylen--;
606     key++;
607   }
608   char* tkey = xbt_new(char, keylen+1);
609   strncpy(tkey, key, keylen);
610   tkey[keylen]='\0';
611   *ierr = MPI_Info_delete(simgrid::smpi::Info::f2c(*info), tkey);
612   xbt_free(tkey);
613 }
614
615 void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
616  *ierr = MPI_Info_get_nkeys(  simgrid::smpi::Info::f2c(*info), nkeys);
617 }
618
619 void mpi_info_get_nthkey_ ( int* info, int* n, char *key, int* ierr, unsigned int keylen){
620   *ierr = MPI_Info_get_nthkey( simgrid::smpi::Info::f2c(*info), *n, key);
621   unsigned int i = 0;
622   for (i=strlen(key); i<keylen; i++)
623     key[i]=' ';
624 }
625
626 void mpi_get_version_ (int *version,int *subversion, int* ierr){
627  *ierr = MPI_Get_version (version,subversion);
628 }
629
630 void mpi_get_library_version_ (char *version,int *len, int* ierr){
631  *ierr = MPI_Get_library_version (version,len);
632 }
633
634 void mpi_request_get_status_ ( int* request, int *flag, MPI_Status* status, int* ierr){
635  *ierr = MPI_Request_get_status( simgrid::smpi::Request::f2c(*request), flag, status);
636 }
637
638 void mpi_grequest_start_ ( void *query_fn, void *free_fn, void *cancel_fn, void *extra_state, int*request, int* ierr){
639   MPI_Request tmp;
640   *ierr = MPI_Grequest_start( reinterpret_cast<MPI_Grequest_query_function*>(query_fn), reinterpret_cast<MPI_Grequest_free_function*>(free_fn),
641                               reinterpret_cast<MPI_Grequest_cancel_function*>(cancel_fn), extra_state, &tmp);
642  if(*ierr == MPI_SUCCESS) {
643    *request = tmp->add_f();
644  }
645 }
646
647 void mpi_grequest_complete_ ( int* request, int* ierr){
648  *ierr = MPI_Grequest_complete( simgrid::smpi::Request::f2c(*request));
649 }
650
651 void mpi_status_set_cancelled_ (MPI_Status* status,int* flag, int* ierr){
652  *ierr = MPI_Status_set_cancelled(status,*flag);
653 }
654
655 void mpi_status_set_elements_ ( MPI_Status* status, int* datatype, int* count, int* ierr){
656  *ierr = MPI_Status_set_elements( status, simgrid::smpi::Datatype::f2c(*datatype), *count);
657 }
658
659 void mpi_publish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
660  *ierr = MPI_Publish_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
661 }
662
663 void mpi_unpublish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
664  *ierr = MPI_Unpublish_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
665 }
666
667 void mpi_lookup_name_ ( char *service_name, int* info, char *port_name, int* ierr){
668  *ierr = MPI_Lookup_name( service_name, *reinterpret_cast<MPI_Info*>(info), port_name);
669 }
670
671 void mpi_open_port_ ( int* info, char *port_name, int* ierr){
672  *ierr = MPI_Open_port( *reinterpret_cast<MPI_Info*>(info),port_name);
673 }
674
675 void mpi_close_port_ ( char *port_name, int* ierr){
676  *ierr = MPI_Close_port( port_name);
677 }
678
679 void mpi_file_close_ ( int* file, int* ierr){
680   *ierr= MPI_File_close(reinterpret_cast<MPI_File*>(*file));
681 }
682
683 void mpi_file_delete_ ( char* filename, int* info, int* ierr){
684   *ierr= MPI_File_delete(filename, simgrid::smpi::Info::f2c(*info));
685 }
686
687 void mpi_file_open_ ( int* comm, char* filename, int* amode, int* info, int* fh, int* ierr){
688   *ierr= MPI_File_open(simgrid::smpi::Comm::f2c(*comm), filename, *amode, simgrid::smpi::Info::f2c(*info), reinterpret_cast<MPI_File*>(*fh));
689 }
690
691 void mpi_file_set_view_ ( int* fh, long long int* offset, int* etype, int* filetype, char* datarep, int* info, int* ierr){
692   *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));
693 }
694
695 void mpi_file_read_ ( int* fh, void* buf, int* count, int* datatype, MPI_Status* status, int* ierr){
696   *ierr=  MPI_File_read(reinterpret_cast<MPI_File>(*fh), buf, *count, simgrid::smpi::Datatype::f2c(*datatype), status);
697 }
698
699 void mpi_file_write_ ( int* fh, void* buf, int* count, int* datatype, MPI_Status* status, int* ierr){
700   *ierr=  MPI_File_write(reinterpret_cast<MPI_File>(*fh), buf, *count, simgrid::smpi::Datatype::f2c(*datatype), status);
701 }
702
703 } // extern "C"