Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpicxx: obey the VERBOSE environment variable and display what we do
[simgrid.git] / src / smpi / bindings / smpi_f77.cpp
1 /* Copyright (c) 2010-2019. 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.hpp"
7 #include "smpi_comm.hpp"
8 #include "smpi_datatype.hpp"
9 #include "smpi_op.hpp"
10 #include "smpi_request.hpp"
11 #include "smpi_win.hpp"
12 #include "src/smpi/include/smpi_actor.hpp"
13
14 static int running_processes = 0;
15
16 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_COMPLEX8->add_f();//MPI_COMPLEX
37      MPI_COMPLEX16->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      MPI_COMPLEX8->add_f();//MPI_COMPLEX8
55      MPI_COMPLEX16->add_f();//MPI_COMPLEX16
56      MPI_COMPLEX32->add_f();//MPI_COMPLEX32
57
58      MPI_MAX->add_f();
59      MPI_MIN->add_f();
60      MPI_MAXLOC->add_f();
61      MPI_MINLOC->add_f();
62      MPI_SUM->add_f();
63      MPI_PROD->add_f();
64      MPI_LAND->add_f();
65      MPI_LOR->add_f();
66      MPI_LXOR->add_f();
67      MPI_BAND->add_f();
68      MPI_BOR->add_f();
69      MPI_BXOR->add_f();
70    }
71 }
72
73 extern "C" { // This should really use the C linkage to be usable from Fortran
74
75
76 void mpi_init_(int* ierr) {
77     smpi_init_fortran_types();
78    *ierr = MPI_Init(nullptr, nullptr);
79    running_processes++;
80 }
81
82 void mpi_finalize_(int* ierr) {
83    *ierr = MPI_Finalize();
84    running_processes--;
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->c2f();
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   //fortran does not handle string endings cleanly, so initialize everything before
114   memset(name, 0, MPI_MAX_PROCESSOR_NAME);
115   *ierr = MPI_Get_processor_name(name, resultlen);
116 }
117
118 void mpi_get_count_(MPI_Status * status, int* datatype, int *count, int* ierr){
119   *ierr = MPI_Get_count(FORT_STATUS_IGNORE(status), simgrid::smpi::Datatype::f2c(*datatype), count);
120 }
121
122 void mpi_attr_get_(int* comm, int* keyval, int* attr_value, int* flag, int* ierr ){
123   int* value = nullptr;
124   *ierr = MPI_Attr_get(simgrid::smpi::Comm::f2c(*comm), *keyval, &value, flag);
125   if(*flag == 1)
126     *attr_value=*value;
127 }
128
129 void mpi_error_string_(int* errorcode, char* string, int* resultlen, int* ierr){
130   *ierr = MPI_Error_string(*errorcode, string, resultlen);
131 }
132
133 void mpi_win_fence_( int* assert,  int* win, int* ierr){
134   *ierr =  MPI_Win_fence(* assert, simgrid::smpi::Win::f2c(*win));
135 }
136
137 void mpi_win_free_( int* win, int* ierr){
138   MPI_Win tmp = simgrid::smpi::Win::f2c(*win);
139   *ierr =  MPI_Win_free(&tmp);
140   if(*ierr == MPI_SUCCESS) {
141     simgrid::smpi::F2C::free_f(*win);
142   }
143 }
144
145 void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr){
146   MPI_Win tmp;
147   *ierr =  MPI_Win_create( static_cast<void*>(base), *size, *disp_unit, simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),&tmp);
148  if(*ierr == MPI_SUCCESS) {
149    *win = tmp->add_f();
150  }
151 }
152
153 void mpi_win_post_(int* group, int assert, int* win, int* ierr){
154   *ierr =  MPI_Win_post(simgrid::smpi::Group::f2c(*group), assert, simgrid::smpi::Win::f2c(*win));
155 }
156
157 void mpi_win_start_(int* group, int assert, int* win, int* ierr){
158   *ierr =  MPI_Win_start(simgrid::smpi::Group::f2c(*group), assert, simgrid::smpi::Win::f2c(*win));
159 }
160
161 void mpi_win_complete_(int* win, int* ierr){
162   *ierr =  MPI_Win_complete(simgrid::smpi::Win::f2c(*win));
163 }
164
165 void mpi_win_wait_(int* win, int* ierr){
166   *ierr =  MPI_Win_wait(simgrid::smpi::Win::f2c(*win));
167 }
168
169 void mpi_win_set_name_ (int*  win, char * name, int* ierr, int size){
170   //handle trailing blanks
171   while(name[size-1]==' ')
172     size--;
173   while(*name==' '){//handle leading blanks
174     size--;
175     name++;
176   }
177   char* tname = xbt_new(char,size+1);
178   strncpy(tname, name, size);
179   tname[size]='\0';
180   *ierr = MPI_Win_set_name(simgrid::smpi::Win::f2c(*win), tname);
181   xbt_free(tname);
182 }
183
184 void mpi_win_get_name_ (int*  win, char * name, int* len, int* ierr){
185   *ierr = MPI_Win_get_name(simgrid::smpi::Win::f2c(*win),name,len);
186   if(*len>0)
187     name[*len]=' ';//blank padding, not \0
188 }
189
190 void mpi_win_allocate_( MPI_Aint* size, int* disp_unit, int* info, int* comm, void* base, int* win, int* ierr){
191   MPI_Win tmp;
192   *ierr =  MPI_Win_allocate( *size, *disp_unit, simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),static_cast<void*>(base),&tmp);
193  if(*ierr == MPI_SUCCESS) {
194    *win = tmp->add_f();
195  }
196 }
197
198 void mpi_win_attach_(int* win, int* base, MPI_Aint* size, int* ierr){
199   *ierr =  MPI_Win_attach(simgrid::smpi::Win::f2c(*win), static_cast<void*>(base), *size);
200 }
201
202 void mpi_win_create_dynamic_( int* info, int* comm, int *win, int* ierr){
203   MPI_Win tmp;
204   *ierr =  MPI_Win_create_dynamic( simgrid::smpi::Info::f2c(*info), simgrid::smpi::Comm::f2c(*comm),&tmp);
205  if(*ierr == MPI_SUCCESS) {
206    *win = tmp->add_f();
207  }
208 }
209
210 void mpi_win_detach_(int* win, int* base, int* ierr){
211   *ierr =  MPI_Win_detach(simgrid::smpi::Win::f2c(*win), static_cast<void*>(base));
212 }
213
214 void mpi_win_set_info_(int*  win, int* info, int* ierr){
215   *ierr =  MPI_Win_set_info(simgrid::smpi::Win::f2c(*win), simgrid::smpi::Info::f2c(*info));
216 }
217
218 void mpi_win_get_info_(int*  win, int* info, int* ierr){
219   MPI_Info tmp;
220   *ierr =  MPI_Win_get_info(simgrid::smpi::Win::f2c(*win), &tmp);
221  if(*ierr == MPI_SUCCESS) {
222    *info = tmp->add_f();
223  }
224 }
225
226 void mpi_win_get_group_(int*  win, int* group, int* ierr){
227   MPI_Group tmp;
228   *ierr =  MPI_Win_get_group(simgrid::smpi::Win::f2c(*win), &tmp);
229  if(*ierr == MPI_SUCCESS) {
230    *group = tmp->add_f();
231  }
232 }
233
234 void mpi_win_get_attr_(int* win, int* type_keyval, MPI_Aint* attribute_val, int* flag, int* ierr){
235    MPI_Aint* value = nullptr;
236   *ierr = MPI_Win_get_attr(simgrid::smpi::Win::f2c(*win), *type_keyval, &value, flag);
237   if (*flag == 1)
238     *attribute_val = *value;
239 }
240
241 void mpi_win_set_attr_(int* win, int* type_keyval, MPI_Aint* att, int* ierr){
242  MPI_Aint* val = (MPI_Aint*)xbt_malloc(sizeof(MPI_Aint));
243  *val=*att;
244   *ierr = MPI_Win_set_attr(simgrid::smpi::Win::f2c(*win), *type_keyval, val);
245 }
246
247 void mpi_win_delete_attr_(int* win, int* comm_keyval, int* ierr){
248   *ierr = MPI_Win_delete_attr (simgrid::smpi::Win::f2c(*win),  *comm_keyval);
249 }
250
251 void mpi_win_create_keyval_(void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
252   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_copy_attr_function_fort*>(copy_fn)};
253   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_delete_attr_function_fort*>(delete_fn)};
254   *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
255 }
256
257 void mpi_win_free_keyval_(int* keyval, int* ierr){
258   *ierr = MPI_Win_free_keyval( keyval);
259 }
260
261 void mpi_win_lock_(int* lock_type, int* rank, int* assert, int* win, int* ierr){
262   *ierr = MPI_Win_lock(*lock_type, *rank, *assert, simgrid::smpi::Win::f2c(*win));
263 }
264
265 void mpi_win_lock_all_(int* assert, int* win, int* ierr){
266   *ierr = MPI_Win_lock_all(*assert, simgrid::smpi::Win::f2c(*win));
267 }
268
269 void mpi_win_unlock_(int* rank, int* win, int* ierr){
270   *ierr = MPI_Win_unlock(*rank, simgrid::smpi::Win::f2c(*win));
271 }
272
273 void mpi_win_unlock_all_(int* win, int* ierr){
274   *ierr = MPI_Win_unlock_all(simgrid::smpi::Win::f2c(*win));
275 }
276
277 void mpi_win_flush_(int* rank, int* win, int* ierr){
278   *ierr = MPI_Win_flush(*rank, simgrid::smpi::Win::f2c(*win));
279 }
280
281 void mpi_win_flush_local_(int* rank, int* win, int* ierr){
282   *ierr = MPI_Win_flush_local(*rank, simgrid::smpi::Win::f2c(*win));
283 }
284 void mpi_win_flush_all_(int* win, int* ierr){
285   *ierr = MPI_Win_flush_all(simgrid::smpi::Win::f2c(*win));
286 }
287
288 void mpi_win_flush_local_all_(int* win, int* ierr){
289   *ierr = MPI_Win_flush_local_all(simgrid::smpi::Win::f2c(*win));
290 }
291
292 void mpi_win_null_copy_fn_(int* /*win*/, int* /*keyval*/, int* /*extrastate*/, MPI_Aint* /*valin*/,
293                            MPI_Aint* /*valout*/, int* flag, int* ierr)
294 {
295   *flag=0;
296   *ierr=MPI_SUCCESS;
297 }
298
299 void mpi_win_dup_fn_(int* /*win*/, int* /*keyval*/, int* /*extrastate*/, MPI_Aint* valin, MPI_Aint* valout, int* flag,
300                      int* ierr)
301 {
302   *flag=1;
303   *valout=*valin;
304   *ierr=MPI_SUCCESS;
305 }
306
307 void mpi_info_create_( int *info, int* ierr){
308   MPI_Info tmp;
309   *ierr =  MPI_Info_create(&tmp);
310   if(*ierr == MPI_SUCCESS) {
311     *info = tmp->add_f();
312   }
313 }
314
315 void mpi_info_set_( int *info, char *key, char *value, int* ierr, unsigned int keylen, unsigned int valuelen){
316   //handle trailing blanks
317   while(key[keylen-1]==' ')
318     keylen--;
319   while(*key==' '){//handle leading blanks
320     keylen--;
321     key++;
322   }
323   char* tkey = xbt_new(char,keylen+1);
324   strncpy(tkey, key, keylen);
325   tkey[keylen]='\0';
326
327   while(value[valuelen-1]==' ')
328     valuelen--;
329   while(*value==' '){//handle leading blanks
330     valuelen--;
331     value++;
332   }
333   char* tvalue = xbt_new(char,valuelen+1);
334   strncpy(tvalue, value, valuelen);
335   tvalue[valuelen]='\0';
336
337   *ierr =  MPI_Info_set( simgrid::smpi::Info::f2c(*info), tkey, tvalue);
338   xbt_free(tkey);
339   xbt_free(tvalue);
340 }
341
342 void mpi_info_get_ (int* info,char *key,int* valuelen, char *value, int *flag, int* ierr, unsigned int keylen ){
343   while(key[keylen-1]==' ')
344     keylen--;
345   while(*key==' '){//handle leading blanks
346     keylen--;
347     key++;
348   }
349   char* tkey = xbt_new(char,keylen+1);
350   strncpy(tkey, key, keylen);
351   tkey[keylen]='\0';
352   *ierr = MPI_Info_get(simgrid::smpi::Info::f2c(*info),tkey,*valuelen, value, flag);
353   xbt_free(tkey);
354   if(*flag!=0){
355     int replace=0;
356     int i=0;
357     for (i=0; i<*valuelen; i++){
358       if(value[i]=='\0')
359         replace=1;
360       if(replace)
361         value[i]=' ';
362     }
363   }
364 }
365
366 void mpi_info_free_(int* info, int* ierr){
367   MPI_Info tmp = simgrid::smpi::Info::f2c(*info);
368   *ierr =  MPI_Info_free(&tmp);
369   if(*ierr == MPI_SUCCESS) {
370     simgrid::smpi::F2C::free_f(*info);
371   }
372 }
373
374 void mpi_get_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
375     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
376   *ierr =  MPI_Get( static_cast<void*>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
377       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win));
378 }
379
380 void mpi_rget_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
381     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* request, int* ierr){
382   MPI_Request req;
383   *ierr =  MPI_Rget( static_cast<void*>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
384       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win), &req);
385   if(*ierr == MPI_SUCCESS) {
386     *request = req->add_f();
387   }
388 }
389
390 void mpi_accumulate_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
391     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* op, int* win, int* ierr){
392   *ierr =  MPI_Accumulate( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
393       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win));
394 }
395
396 void mpi_raccumulate_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
397     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* op, int* win, int* request, int* ierr){
398   MPI_Request req;
399   *ierr =  MPI_Raccumulate( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
400       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win),&req);
401   if(*ierr == MPI_SUCCESS) {
402     *request = req->add_f();
403   }
404 }
405
406 void mpi_put_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
407     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* ierr){
408   *ierr =  MPI_Put( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
409       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win));
410 }
411
412 void mpi_rput_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank,
413     MPI_Aint* target_disp, int *target_count, int* tarsmpi_type_f2c, int* win, int* request, int* ierr){
414   MPI_Request req;
415   *ierr =  MPI_Rput( static_cast<void *>(origin_addr),*origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),*target_rank,
416       *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*tarsmpi_type_f2c), simgrid::smpi::Win::f2c(*win),&req);
417   if(*ierr == MPI_SUCCESS) {
418     *request = req->add_f();
419   }
420 }
421
422 void mpi_fetch_and_op_( int *origin_addr, int* result_addr, int* datatype, int* target_rank, MPI_Aint* target_disp, int* op, int* win, int* ierr){
423   *ierr =  MPI_Fetch_and_op( static_cast<void *>(origin_addr),
424               static_cast<void *>(result_addr), simgrid::smpi::Datatype::f2c(*datatype),*target_rank,
425               *target_disp, simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win));
426 }
427
428 void mpi_compare_and_swap_(int* origin_addr, int* compare_addr, int* result_addr, int* datatype, int* target_rank,
429                            MPI_Aint* target_disp, int* win, int* ierr)
430 {
431   *ierr =  MPI_Compare_and_swap( static_cast<void *>(origin_addr),static_cast<void *>(compare_addr),
432               static_cast<void *>(result_addr), simgrid::smpi::Datatype::f2c(*datatype),*target_rank,
433               *target_disp, simgrid::smpi::Win::f2c(*win));
434 }
435
436 void mpi_get_accumulate_(int *origin_addr, int* origin_count, int* origin_datatype, int* result_addr,
437                         int* result_count, int* result_datatype, int* target_rank, MPI_Aint* target_disp, int* target_count,
438                         int* target_datatype, int* op, int* win, int* ierr){
439   *ierr =
440       MPI_Get_accumulate(static_cast<void*>(origin_addr), *origin_count, simgrid::smpi::Datatype::f2c(*origin_datatype),
441                          static_cast<void*>(result_addr), *result_count, simgrid::smpi::Datatype::f2c(*result_datatype),
442                          *target_rank, *target_disp, *target_count, simgrid::smpi::Datatype::f2c(*target_datatype),
443                          simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win));
444 }
445
446 void mpi_rget_accumulate_(int *origin_addr, int* origin_count, int* origin_datatype, int* result_addr,
447                         int* result_count, int* result_datatype, int* target_rank, MPI_Aint* target_disp, int* target_count,
448                         int* target_datatype, int* op, int* win, int* request, int* ierr){
449   MPI_Request req;
450   *ierr = MPI_Rget_accumulate(static_cast<void*>(origin_addr), *origin_count,
451                               simgrid::smpi::Datatype::f2c(*origin_datatype), static_cast<void*>(result_addr),
452                               *result_count, simgrid::smpi::Datatype::f2c(*result_datatype), *target_rank, *target_disp,
453                               *target_count, simgrid::smpi::Datatype::f2c(*target_datatype),
454                               simgrid::smpi::Op::f2c(*op), simgrid::smpi::Win::f2c(*win), &req);
455   if(*ierr == MPI_SUCCESS) {
456     *request = req->add_f();
457   }
458 }
459
460 //following are automatically generated, and have to be checked
461 void mpi_finalized_ (int * flag, int* ierr){
462  *ierr = MPI_Finalized(flag);
463 }
464
465 void mpi_init_thread_ (int* required, int *provided, int* ierr){
466   smpi_init_fortran_types();
467   *ierr = MPI_Init_thread(nullptr, nullptr,*required, provided);
468   running_processes++;
469 }
470
471 void mpi_query_thread_ (int *provided, int* ierr){
472  *ierr = MPI_Query_thread(provided);
473 }
474
475 void mpi_is_thread_main_ (int *flag, int* ierr){
476
477  *ierr = MPI_Is_thread_main(flag);
478 }
479
480 void mpi_address_ (void *location, MPI_Aint * address, int* ierr){
481
482  *ierr = MPI_Address(location, address);
483 }
484
485 void mpi_get_address_ (void *location, MPI_Aint * address, int* ierr){
486
487  *ierr = MPI_Get_address(location, address);
488 }
489
490 void mpi_pcontrol_ (int* level , int* ierr){
491  *ierr = MPI_Pcontrol(*static_cast<const int*>(level));
492 }
493
494 void mpi_op_create_ (void * function, int* commute, int* op, int* ierr){
495   MPI_Op tmp;
496  *ierr = MPI_Op_create(reinterpret_cast<MPI_User_function*>(function),*commute, &tmp);
497  if(*ierr == MPI_SUCCESS) {
498    tmp->set_fortran_op();
499    *op = tmp->add_f();
500  }
501 }
502
503 void mpi_op_free_ (int* op, int* ierr){
504   MPI_Op tmp= simgrid::smpi::Op::f2c(*op);
505   *ierr = MPI_Op_free(& tmp);
506   if(*ierr == MPI_SUCCESS) {
507     simgrid::smpi::F2C::free_f(*op);
508   }
509 }
510
511 void mpi_op_commutative_ (int* op, int* commute, int* ierr){
512   *ierr = MPI_Op_commutative(simgrid::smpi::Op::f2c(*op), commute);
513 }
514
515 void mpi_group_free_ (int* group, int* ierr){
516   MPI_Group tmp = simgrid::smpi::Group::f2c(*group);
517   if(tmp != MPI_COMM_WORLD->group() && tmp != MPI_GROUP_EMPTY){
518     simgrid::smpi::Group::unref(tmp);
519     simgrid::smpi::F2C::free_f(*group);
520   }
521   *ierr = MPI_SUCCESS;
522 }
523
524 void mpi_group_size_ (int* group, int *size, int* ierr){
525
526  *ierr = MPI_Group_size(simgrid::smpi::Group::f2c(*group), size);
527 }
528
529 void mpi_group_rank_ (int* group, int *rank, int* ierr){
530
531  *ierr = MPI_Group_rank(simgrid::smpi::Group::f2c(*group), rank);
532 }
533
534 void mpi_group_translate_ranks_ (int* group1, int* n, int *ranks1, int* group2, int *ranks2, int* ierr)
535 {
536
537  *ierr = MPI_Group_translate_ranks(simgrid::smpi::Group::f2c(*group1), *n, ranks1, simgrid::smpi::Group::f2c(*group2), ranks2);
538 }
539
540 void mpi_group_compare_ (int* group1, int* group2, int *result, int* ierr){
541
542  *ierr = MPI_Group_compare(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), result);
543 }
544
545 void mpi_group_union_ (int* group1, int* group2, int* newgroup, int* ierr){
546  MPI_Group tmp;
547  *ierr = MPI_Group_union(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
548  if(*ierr == MPI_SUCCESS) {
549    *newgroup = tmp->add_f();
550  }
551 }
552
553 void mpi_group_intersection_ (int* group1, int* group2, int* newgroup, int* ierr){
554  MPI_Group tmp;
555  *ierr = MPI_Group_intersection(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
556  if(*ierr == MPI_SUCCESS) {
557    *newgroup = tmp->add_f();
558  }
559 }
560
561 void mpi_group_difference_ (int* group1, int* group2, int* newgroup, int* ierr){
562  MPI_Group tmp;
563  *ierr = MPI_Group_difference(simgrid::smpi::Group::f2c(*group1), simgrid::smpi::Group::f2c(*group2), &tmp);
564  if(*ierr == MPI_SUCCESS) {
565    *newgroup = tmp->add_f();
566  }
567 }
568
569 void mpi_group_excl_ (int* group, int* n, int *ranks, int* newgroup, int* ierr){
570   MPI_Group tmp;
571  *ierr = MPI_Group_excl(simgrid::smpi::Group::f2c(*group), *n, ranks, &tmp);
572  if(*ierr == MPI_SUCCESS) {
573    *newgroup = tmp->add_f();
574  }
575 }
576
577 void mpi_group_range_incl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
578 {
579   MPI_Group tmp;
580  *ierr = MPI_Group_range_incl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp);
581  if(*ierr == MPI_SUCCESS) {
582    *newgroup = tmp->add_f();
583  }
584 }
585
586 void mpi_group_range_excl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
587 {
588  MPI_Group tmp;
589  *ierr = MPI_Group_range_excl(simgrid::smpi::Group::f2c(*group), *n, ranges, &tmp);
590  if(*ierr == MPI_SUCCESS) {
591    *newgroup = tmp->add_f();
592  }
593 }
594
595 void mpi_request_free_ (int* request, int* ierr){
596   MPI_Request tmp=simgrid::smpi::Request::f2c(*request);
597  *ierr = MPI_Request_free(&tmp);
598  if(*ierr == MPI_SUCCESS) {
599    simgrid::smpi::Request::free_f(*request);
600  }
601 }
602
603 void mpi_pack_size_ (int* incount, int* datatype, int* comm, int* size, int* ierr) {
604  *ierr = MPI_Pack_size(*incount, simgrid::smpi::Datatype::f2c(*datatype), simgrid::smpi::Comm::f2c(*comm), size);
605 }
606
607 void mpi_cart_coords_ (int* comm, int* rank, int* maxdims, int* coords, int* ierr) {
608  *ierr = MPI_Cart_coords(simgrid::smpi::Comm::f2c(*comm), *rank, *maxdims, coords);
609 }
610
611 void mpi_cart_create_ (int* comm_old, int* ndims, int* dims, int* periods, int* reorder, int*  comm_cart, int* ierr) {
612   MPI_Comm tmp;
613  *ierr = MPI_Cart_create(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, *reorder, &tmp);
614  if(*ierr == MPI_SUCCESS) {
615    *comm_cart = tmp->add_f();
616  }
617 }
618
619 void mpi_cart_get_ (int* comm, int* maxdims, int* dims, int* periods, int* coords, int* ierr) {
620  *ierr = MPI_Cart_get(simgrid::smpi::Comm::f2c(*comm), *maxdims, dims, periods, coords);
621 }
622
623 void mpi_cart_map_ (int* comm_old, int* ndims, int* dims, int* periods, int* newrank, int* ierr) {
624  *ierr = MPI_Cart_map(simgrid::smpi::Comm::f2c(*comm_old), *ndims, dims, periods, newrank);
625 }
626
627 void mpi_cart_rank_ (int* comm, int* coords, int* rank, int* ierr) {
628  *ierr = MPI_Cart_rank(simgrid::smpi::Comm::f2c(*comm), coords, rank);
629 }
630
631 void mpi_cart_shift_ (int* comm, int* direction, int* displ, int* source, int* dest, int* ierr) {
632  *ierr = MPI_Cart_shift(simgrid::smpi::Comm::f2c(*comm), *direction, *displ, source, dest);
633 }
634
635 void mpi_cart_sub_ (int* comm, int* remain_dims, int*  comm_new, int* ierr) {
636  MPI_Comm tmp;
637  *ierr = MPI_Cart_sub(simgrid::smpi::Comm::f2c(*comm), remain_dims, &tmp);
638  if(*ierr == MPI_SUCCESS) {
639    *comm_new = tmp->add_f();
640  }
641 }
642
643 void mpi_cartdim_get_ (int* comm, int* ndims, int* ierr) {
644  *ierr = MPI_Cartdim_get(simgrid::smpi::Comm::f2c(*comm), ndims);
645 }
646
647 void mpi_graph_create_ (int* comm_old, int* nnodes, int* index, int* edges, int* reorder, int*  comm_graph, int* ierr) {
648   MPI_Comm tmp;
649  *ierr = MPI_Graph_create(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, *reorder, &tmp);
650  if(*ierr == MPI_SUCCESS) {
651    *comm_graph = tmp->add_f();
652  }
653 }
654
655 void mpi_graph_get_ (int* comm, int* maxindex, int* maxedges, int* index, int* edges, int* ierr) {
656  *ierr = MPI_Graph_get(simgrid::smpi::Comm::f2c(*comm), *maxindex, *maxedges, index, edges);
657 }
658
659 void mpi_graph_map_ (int* comm_old, int* nnodes, int* index, int* edges, int* newrank, int* ierr) {
660  *ierr = MPI_Graph_map(simgrid::smpi::Comm::f2c(*comm_old), *nnodes, index, edges, newrank);
661 }
662
663 void mpi_graph_neighbors_ (int* comm, int* rank, int* maxneighbors, int* neighbors, int* ierr) {
664  *ierr = MPI_Graph_neighbors(simgrid::smpi::Comm::f2c(*comm), *rank, *maxneighbors, neighbors);
665 }
666
667 void mpi_graph_neighbors_count_ (int* comm, int* rank, int* nneighbors, int* ierr) {
668  *ierr = MPI_Graph_neighbors_count(simgrid::smpi::Comm::f2c(*comm), *rank, nneighbors);
669 }
670
671 void mpi_graphdims_get_ (int* comm, int* nnodes, int* nedges, int* ierr) {
672  *ierr = MPI_Graphdims_get(simgrid::smpi::Comm::f2c(*comm), nnodes, nedges);
673 }
674
675 void mpi_topo_test_ (int* comm, int* top_type, int* ierr) {
676  *ierr = MPI_Topo_test(simgrid::smpi::Comm::f2c(*comm), top_type);
677 }
678
679 void mpi_error_class_ (int* errorcode, int* errorclass, int* ierr) {
680  *ierr = MPI_Error_class(*errorcode, errorclass);
681 }
682
683 void mpi_errhandler_create_ (void* function, void* errhandler, int* ierr) {
684  *ierr = MPI_Errhandler_create(reinterpret_cast<MPI_Handler_function*>(function), static_cast<MPI_Errhandler*>(errhandler));
685 }
686
687 void mpi_errhandler_free_ (void* errhandler, int* ierr) {
688  *ierr = MPI_Errhandler_free(static_cast<MPI_Errhandler*>(errhandler));
689 }
690
691 void mpi_errhandler_get_ (int* comm, void* errhandler, int* ierr) {
692  *ierr = MPI_Errhandler_get(simgrid::smpi::Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
693 }
694
695 void mpi_errhandler_set_ (int* comm, void* errhandler, int* ierr) {
696  *ierr = MPI_Errhandler_set(simgrid::smpi::Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
697 }
698
699 void mpi_cancel_ (int* request, int* ierr) {
700   MPI_Request tmp=simgrid::smpi::Request::f2c(*request);
701  *ierr = MPI_Cancel(&tmp);
702 }
703
704 void mpi_buffer_attach_ (void* buffer, int* size, int* ierr) {
705  *ierr = MPI_Buffer_attach(buffer, *size);
706 }
707
708 void mpi_buffer_detach_ (void* buffer, int* size, int* ierr) {
709  *ierr = MPI_Buffer_detach(buffer, size);
710 }
711
712
713
714 void mpi_intercomm_create_ (int* local_comm, int *local_leader, int* peer_comm, int* remote_leader, int* tag,
715                             int* comm_out, int* ierr) {
716   MPI_Comm tmp;
717   *ierr = MPI_Intercomm_create(simgrid::smpi::Comm::f2c(*local_comm), *local_leader, simgrid::smpi::Comm::f2c(*peer_comm), *remote_leader,
718                                *tag, &tmp);
719   if(*ierr == MPI_SUCCESS) {
720     *comm_out = tmp->add_f();
721   }
722 }
723
724 void mpi_intercomm_merge_ (int* comm, int* high, int*  comm_out, int* ierr) {
725  MPI_Comm tmp;
726  *ierr = MPI_Intercomm_merge(simgrid::smpi::Comm::f2c(*comm), *high, &tmp);
727  if(*ierr == MPI_SUCCESS) {
728    *comm_out = tmp->add_f();
729  }
730 }
731
732 void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) {
733  *ierr = MPI_Attr_delete(simgrid::smpi::Comm::f2c(*comm), *keyval);
734 }
735
736 void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) {
737  int* val = (int*)xbt_malloc(sizeof(int));
738  *val=*attr_value;
739  *ierr = MPI_Attr_put(simgrid::smpi::Comm::f2c(*comm), *keyval, val);
740 }
741
742 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
743   smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Copy_function_fort*>(copy_fn),nullptr,nullptr};
744   smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Delete_function_fort*>(delete_fn),nullptr,nullptr};
745   *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
746 }
747
748 void mpi_keyval_free_ (int* keyval, int* ierr) {
749  *ierr = MPI_Keyval_free(keyval);
750 }
751
752 void mpi_test_cancelled_ (MPI_Status*  status, int* flag, int* ierr) {
753  *ierr = MPI_Test_cancelled(status, flag);
754 }
755
756 void mpi_get_elements_ (MPI_Status*  status, int* datatype, int* elements, int* ierr) {
757  *ierr = MPI_Get_elements(status, simgrid::smpi::Datatype::f2c(*datatype), elements);
758 }
759
760 void mpi_dims_create_ (int* nnodes, int* ndims, int* dims, int* ierr) {
761  *ierr = MPI_Dims_create(*nnodes, *ndims, dims);
762 }
763
764 void mpi_add_error_class_ ( int *errorclass, int* ierr){
765  *ierr = MPI_Add_error_class( errorclass);
766 }
767
768 void mpi_add_error_code_ (  int* errorclass, int *errorcode, int* ierr){
769  *ierr = MPI_Add_error_code(*errorclass, errorcode);
770 }
771
772 void mpi_add_error_string_ ( int* errorcode, char *string, int* ierr){
773  *ierr = MPI_Add_error_string(*errorcode, string);
774 }
775
776 void mpi_info_dup_ (int* info, int* newinfo, int* ierr){
777  MPI_Info tmp;
778  *ierr = MPI_Info_dup(simgrid::smpi::Info::f2c(*info), &tmp);
779  if(*ierr==MPI_SUCCESS){
780    *newinfo= tmp->add_f();
781  }
782 }
783
784 void mpi_info_get_valuelen_ ( int* info, char *key, int *valuelen, int *flag, int* ierr, unsigned int keylen){
785   while(key[keylen-1]==' ')
786     keylen--;
787   while(*key==' '){//handle leading blanks
788     keylen--;
789     key++;
790   }
791   char* tkey = xbt_new(char, keylen+1);
792   strncpy(tkey, key, keylen);
793   tkey[keylen]='\0';
794   *ierr = MPI_Info_get_valuelen( simgrid::smpi::Info::f2c(*info), tkey, valuelen, flag);
795   xbt_free(tkey);
796 }
797
798 void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){
799   while(key[keylen-1]==' ')
800     keylen--;
801   while(*key==' '){//handle leading blanks
802     keylen--;
803     key++;
804   }
805   char* tkey = xbt_new(char, keylen+1);
806   strncpy(tkey, key, keylen);
807   tkey[keylen]='\0';
808   *ierr = MPI_Info_delete(simgrid::smpi::Info::f2c(*info), tkey);
809   xbt_free(tkey);
810 }
811
812 void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
813  *ierr = MPI_Info_get_nkeys(  simgrid::smpi::Info::f2c(*info), nkeys);
814 }
815
816 void mpi_info_get_nthkey_ ( int* info, int* n, char *key, int* ierr, unsigned int keylen){
817   *ierr = MPI_Info_get_nthkey( simgrid::smpi::Info::f2c(*info), *n, key);
818   unsigned int i = 0;
819   for (i=strlen(key); i<keylen; i++)
820     key[i]=' ';
821 }
822
823 void mpi_get_version_ (int *version,int *subversion, int* ierr){
824  *ierr = MPI_Get_version (version,subversion);
825 }
826
827 void mpi_get_library_version_ (char *version,int *len, int* ierr){
828  *ierr = MPI_Get_library_version (version,len);
829 }
830
831 void mpi_request_get_status_ ( int* request, int *flag, MPI_Status* status, int* ierr){
832  *ierr = MPI_Request_get_status( simgrid::smpi::Request::f2c(*request), flag, status);
833 }
834
835 void mpi_grequest_start_ ( void *query_fn, void *free_fn, void *cancel_fn, void *extra_state, int*request, int* ierr){
836   MPI_Request tmp;
837   *ierr = MPI_Grequest_start( reinterpret_cast<MPI_Grequest_query_function*>(query_fn), reinterpret_cast<MPI_Grequest_free_function*>(free_fn),
838                               reinterpret_cast<MPI_Grequest_cancel_function*>(cancel_fn), extra_state, &tmp);
839  if(*ierr == MPI_SUCCESS) {
840    *request = tmp->add_f();
841  }
842 }
843
844 void mpi_grequest_complete_ ( int* request, int* ierr){
845  *ierr = MPI_Grequest_complete( simgrid::smpi::Request::f2c(*request));
846 }
847
848 void mpi_status_set_cancelled_ (MPI_Status* status,int* flag, int* ierr){
849  *ierr = MPI_Status_set_cancelled(status,*flag);
850 }
851
852 void mpi_status_set_elements_ ( MPI_Status* status, int* datatype, int* count, int* ierr){
853  *ierr = MPI_Status_set_elements( status, simgrid::smpi::Datatype::f2c(*datatype), *count);
854 }
855
856 void mpi_publish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
857  *ierr = MPI_Publish_name( service_name, simgrid::smpi::Info::f2c(*info), port_name);
858 }
859
860 void mpi_unpublish_name_ ( char *service_name, int* info, char *port_name, int* ierr){
861  *ierr = MPI_Unpublish_name( service_name, simgrid::smpi::Info::f2c(*info), port_name);
862 }
863
864 void mpi_lookup_name_ ( char *service_name, int* info, char *port_name, int* ierr){
865  *ierr = MPI_Lookup_name( service_name, simgrid::smpi::Info::f2c(*info), port_name);
866 }
867
868 void mpi_open_port_ ( int* info, char *port_name, int* ierr){
869  *ierr = MPI_Open_port( simgrid::smpi::Info::f2c(*info),port_name);
870 }
871
872 void mpi_close_port_ ( char *port_name, int* ierr){
873  *ierr = MPI_Close_port( port_name);
874 }
875
876 void mpi_file_close_ ( int* file, int* ierr){
877   *ierr= MPI_File_close(reinterpret_cast<MPI_File*>(*file));
878 }
879
880 void mpi_file_delete_ ( char* filename, int* info, int* ierr){
881   *ierr= MPI_File_delete(filename, simgrid::smpi::Info::f2c(*info));
882 }
883
884 void mpi_file_open_ ( int* comm, char* filename, int* amode, int* info, int* fh, int* ierr){
885   *ierr= MPI_File_open(simgrid::smpi::Comm::f2c(*comm), filename, *amode, simgrid::smpi::Info::f2c(*info), reinterpret_cast<MPI_File*>(*fh));
886 }
887
888 void mpi_file_set_view_ ( int* fh, long long int* offset, int* etype, int* filetype, char* datarep, int* info, int* ierr){
889   *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));
890 }
891
892 void mpi_file_read_ ( int* fh, void* buf, int* count, int* datatype, MPI_Status* status, int* ierr){
893   *ierr=  MPI_File_read(reinterpret_cast<MPI_File>(*fh), buf, *count, simgrid::smpi::Datatype::f2c(*datatype), status);
894 }
895
896 void mpi_file_write_ ( int* fh, void* buf, int* count, int* datatype, MPI_Status* status, int* ierr){
897   *ierr=  MPI_File_write(reinterpret_cast<MPI_File>(*fh), buf, *count, simgrid::smpi::Datatype::f2c(*datatype), status);
898 }
899
900 } // extern "C"