1 /* Copyright (c) 2010-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
12 static int running_processes = 0;
14 #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
17 typedef long int integer;
20 /* Convert between Fortran and C */
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))
27 #define KEY_SIZE (sizeof(int) * 2 + 1)
29 static char* get_key(char* key, int id) {
30 snprintf(key, KEY_SIZE, "%x",id);
34 static char* get_key_id(char* key, int id) {
35 snprintf(key, KEY_SIZE, "%x_%d",id, smpi_process()->index());
39 static void smpi_init_fortran_types(){
40 if(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
48 MPI_C_BOOL->add_f();//MPI_LOGICAL
49 MPI_LONG->add_f();//MPI_INTEGER
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
64 MPI_2LONG->add_f();//MPI_2INTEGER
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
93 extern "C" { // This should really use the C linkage to be usable from Fortran
96 void mpi_init_(int* ierr) {
97 smpi_init_fortran_types();
98 *ierr = MPI_Init(nullptr, nullptr);
102 void mpi_finalize_(int* ierr) {
103 *ierr = MPI_Finalize();
105 if(running_processes==0){
106 F2C::delete_lookup();
110 void mpi_abort_(int* comm, int* errorcode, int* ierr) {
111 *ierr = MPI_Abort(Comm::f2c(*comm), *errorcode);
114 void mpi_comm_rank_(int* comm, int* rank, int* ierr) {
115 *ierr = MPI_Comm_rank(Comm::f2c(*comm), rank);
118 void mpi_comm_size_(int* comm, int* size, int* ierr) {
119 *ierr = MPI_Comm_size(Comm::f2c(*comm), size);
122 double mpi_wtime_() {
126 double mpi_wtick_() {
130 void mpi_comm_dup_(int* comm, int* newcomm, int* ierr) {
133 *ierr = MPI_Comm_dup(Comm::f2c(*comm), &tmp);
134 if(*ierr == MPI_SUCCESS) {
135 *newcomm = tmp->add_f();
139 void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
142 *ierr = MPI_Comm_create(Comm::f2c(*comm),Group::f2c(*group), &tmp);
143 if(*ierr == MPI_SUCCESS) {
144 *newcomm = tmp->add_f();
148 void mpi_comm_free_(int* comm, int* ierr) {
149 MPI_Comm tmp = Comm::f2c(*comm);
151 *ierr = MPI_Comm_free(&tmp);
153 if(*ierr == MPI_SUCCESS) {
158 void mpi_comm_split_(int* comm, int* color, int* key, int* comm_out, int* ierr) {
161 *ierr = MPI_Comm_split(Comm::f2c(*comm), *color, *key, &tmp);
162 if(*ierr == MPI_SUCCESS) {
163 *comm_out = tmp->add_f();
167 void mpi_group_incl_(int* group, int* n, int* ranks, int* group_out, int* ierr) {
170 *ierr = MPI_Group_incl(Group::f2c(*group), *n, ranks, &tmp);
171 if(*ierr == MPI_SUCCESS) {
172 *group_out = tmp->add_f();
176 void mpi_comm_group_(int* comm, int* group_out, int* ierr) {
179 *ierr = MPI_Comm_group(Comm::f2c(*comm), &tmp);
180 if(*ierr == MPI_SUCCESS) {
181 *group_out = tmp->c2f();
185 void mpi_initialized_(int* flag, int* ierr){
186 *ierr = MPI_Initialized(flag);
189 void mpi_send_init_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
191 buf = static_cast<char *>(FORT_BOTTOM(buf));
192 *ierr = MPI_Send_init(buf, *count, Datatype::f2c(*datatype), *dst, *tag, Comm::f2c(*comm), &req);
193 if(*ierr == MPI_SUCCESS) {
194 *request = req->add_f();
198 void mpi_isend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
200 buf = static_cast<char *>(FORT_BOTTOM(buf));
201 *ierr = MPI_Isend(buf, *count, Datatype::f2c(*datatype), *dst, *tag, Comm::f2c(*comm), &req);
202 if(*ierr == MPI_SUCCESS) {
203 *request = req->add_f();
207 void mpi_irsend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) {
209 buf = static_cast<char *>(FORT_BOTTOM(buf));
210 *ierr = MPI_Irsend(buf, *count, Datatype::f2c(*datatype), *dst, *tag, Comm::f2c(*comm), &req);
211 if(*ierr == MPI_SUCCESS) {
212 *request = req->add_f();
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, Datatype::f2c(*datatype), *dst, *tag, Comm::f2c(*comm));
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, Datatype::f2c(*datatype), *dst, *tag, Comm::f2c(*comm));
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, Datatype::f2c(*sendtype), *dst, *sendtag, recvbuf, *recvcount,
231 Datatype::f2c(*recvtype), *src, *recvtag, Comm::f2c(*comm), FORT_STATUS_IGNORE(status));
234 void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) {
236 buf = static_cast<char *>( FORT_BOTTOM(buf));
237 *ierr = MPI_Recv_init(buf, *count, Datatype::f2c(*datatype), *src, *tag, Comm::f2c(*comm), &req);
238 if(*ierr == MPI_SUCCESS) {
239 *request = req->add_f();
243 void mpi_irecv_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) {
245 buf = static_cast<char *>( FORT_BOTTOM(buf));
246 *ierr = MPI_Irecv(buf, *count, Datatype::f2c(*datatype), *src, *tag, Comm::f2c(*comm), &req);
247 if(*ierr == MPI_SUCCESS) {
248 *request = req->add_f();
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, Datatype::f2c(*datatype), *src, *tag, Comm::f2c(*comm), status);
257 void mpi_start_(int* request, int* ierr) {
258 MPI_Request req = Request::f2c(*request);
260 *ierr = MPI_Start(&req);
263 void mpi_startall_(int* count, int* requests, int* ierr) {
267 reqs = xbt_new(MPI_Request, *count);
268 for(i = 0; i < *count; i++) {
269 reqs[i] = Request::f2c(requests[i]);
271 *ierr = MPI_Startall(*count, reqs);
275 void mpi_wait_(int* request, MPI_Status* status, int* ierr) {
276 MPI_Request req = Request::f2c(*request);
278 *ierr = MPI_Wait(&req, FORT_STATUS_IGNORE(status));
279 if(req==MPI_REQUEST_NULL){
280 Request::free_f(*request);
281 *request=MPI_FORTRAN_REQUEST_NULL;
285 void mpi_waitany_(int* count, int* requests, int* index, MPI_Status* status, int* ierr) {
289 reqs = xbt_new(MPI_Request, *count);
290 for(i = 0; i < *count; i++) {
291 reqs[i] = Request::f2c(requests[i]);
293 *ierr = MPI_Waitany(*count, reqs, index, status);
294 if(reqs[*index]==MPI_REQUEST_NULL){
295 Request::free_f(requests[*index]);
296 requests[*index]=MPI_FORTRAN_REQUEST_NULL;
301 void mpi_waitall_(int* count, int* requests, MPI_Status* status, int* ierr) {
305 reqs = xbt_new(MPI_Request, *count);
306 for(i = 0; i < *count; i++) {
307 reqs[i] = Request::f2c(requests[i]);
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 Request::free_f(requests[i]);
313 requests[i]=MPI_FORTRAN_REQUEST_NULL;
320 void mpi_barrier_(int* comm, int* ierr) {
321 *ierr = MPI_Barrier(Comm::f2c(*comm));
324 void mpi_bcast_(void *buf, int* count, int* datatype, int* root, int* comm, int* ierr) {
325 *ierr = MPI_Bcast(buf, *count, Datatype::f2c(*datatype), *root, Comm::f2c(*comm));
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, Datatype::f2c(*datatype), Op::f2c(*op), *root, Comm::f2c(*comm));
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, Datatype::f2c(*datatype), Op::f2c(*op), Comm::f2c(*comm));
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, Datatype::f2c(*datatype),
343 Op::f2c(*op), Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
350 recvbuf, *recvcount, Datatype::f2c(*recvtype), *root, Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
357 recvbuf, *recvcount, Datatype::f2c(*recvtype), *root, Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
366 recvbuf, *recvcount, Datatype::f2c(*recvtype), *root, Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
375 recvbuf, recvcounts, displs, Datatype::f2c(*recvtype), *root, Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
382 recvbuf, *recvcount, Datatype::f2c(*recvtype), Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
389 recvbuf, recvcounts, displs, Datatype::f2c(*recvtype), Comm::f2c(*comm));
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, Datatype::f2c(*datatype),
394 Op::f2c(*op), Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
400 recvbuf, *recvcount, Datatype::f2c(*recvtype), Comm::f2c(*comm));
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, Datatype::f2c(*sendtype),
406 recvbuf, recvcounts, recvdisps, Datatype::f2c(*recvtype), Comm::f2c(*comm));
409 void mpi_test_ (int * request, int *flag, MPI_Status * status, int* ierr){
410 MPI_Request req = Request::f2c(*request);
411 *ierr= MPI_Test(&req, flag, FORT_STATUS_IGNORE(status));
412 if(req==MPI_REQUEST_NULL){
413 Request::free_f(*request);
414 *request=MPI_FORTRAN_REQUEST_NULL;
418 void mpi_testall_ (int* count, int * requests, int *flag, MPI_Status * statuses, int* ierr){
420 MPI_Request* reqs = xbt_new(MPI_Request, *count);
421 for(i = 0; i < *count; i++) {
422 reqs[i] = Request::f2c(requests[i]);
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 Request::free_f(requests[i]);
428 requests[i]=MPI_FORTRAN_REQUEST_NULL;
434 void mpi_get_processor_name_(char *name, int *resultlen, int* ierr){
435 *ierr = MPI_Get_processor_name(name, resultlen);
438 void mpi_get_count_(MPI_Status * status, int* datatype, int *count, int* ierr){
439 *ierr = MPI_Get_count(FORT_STATUS_IGNORE(status), Datatype::f2c(*datatype), count);
442 void mpi_attr_get_(int* comm, int* keyval, void* attr_value, int* flag, int* ierr ){
443 *ierr = MPI_Attr_get(Comm::f2c(*comm), *keyval, attr_value, flag);
446 void mpi_type_extent_(int* datatype, MPI_Aint * extent, int* ierr){
447 *ierr= MPI_Type_extent(Datatype::f2c(*datatype), extent);
450 void mpi_type_commit_(int* datatype, int* ierr){
451 MPI_Datatype tmp= Datatype::f2c(*datatype);
452 *ierr= MPI_Type_commit(&tmp);
455 void mpi_type_vector_(int* count, int* blocklen, int* stride, int* old_type, int* newtype, int* ierr){
457 *ierr= MPI_Type_vector(*count, *blocklen, *stride, Datatype::f2c(*old_type), &tmp);
458 if(*ierr == MPI_SUCCESS) {
459 *newtype = tmp->add_f();
463 void mpi_type_create_vector_(int* count, int* blocklen, int* stride, int* old_type, int* newtype, int* ierr){
465 *ierr= MPI_Type_vector(*count, *blocklen, *stride, Datatype::f2c(*old_type), &tmp);
466 if(*ierr == MPI_SUCCESS) {
467 *newtype = tmp->add_f();
471 void mpi_type_hvector_(int* count, int* blocklen, MPI_Aint* stride, int* old_type, int* newtype, int* ierr){
473 *ierr= MPI_Type_hvector (*count, *blocklen, *stride, Datatype::f2c(*old_type), &tmp);
474 if(*ierr == MPI_SUCCESS) {
475 *newtype = tmp->add_f();
479 void mpi_type_create_hvector_(int* count, int* blocklen, MPI_Aint* stride, int* old_type, int* newtype, int* ierr){
481 *ierr= MPI_Type_hvector(*count, *blocklen, *stride, Datatype::f2c(*old_type), &tmp);
482 if(*ierr == MPI_SUCCESS) {
483 *newtype = tmp->add_f();
487 void mpi_type_free_(int* datatype, int* ierr){
488 MPI_Datatype tmp= Datatype::f2c(*datatype);
489 *ierr= MPI_Type_free (&tmp);
490 if(*ierr == MPI_SUCCESS) {
491 F2C::free_f(*datatype);
495 void mpi_type_ub_(int* datatype, MPI_Aint * disp, int* ierr){
496 *ierr= MPI_Type_ub(Datatype::f2c(*datatype), disp);
499 void mpi_type_lb_(int* datatype, MPI_Aint * extent, int* ierr){
500 *ierr= MPI_Type_extent(Datatype::f2c(*datatype), extent);
503 void mpi_type_size_(int* datatype, int *size, int* ierr)
505 *ierr = MPI_Type_size(Datatype::f2c(*datatype), size);
508 void mpi_error_string_(int* errorcode, char* string, int* resultlen, int* ierr){
509 *ierr = MPI_Error_string(*errorcode, string, resultlen);
512 void mpi_win_fence_( int* assert, int* win, int* ierr){
513 *ierr = MPI_Win_fence(* assert, Win::f2c(*win));
516 void mpi_win_free_( int* win, int* ierr){
517 MPI_Win tmp = Win::f2c(*win);
518 *ierr = MPI_Win_free(&tmp);
519 if(*ierr == MPI_SUCCESS) {
524 void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr){
526 *ierr = MPI_Win_create( static_cast<void*>(base), *size, *disp_unit, Info::f2c(*info), Comm::f2c(*comm),&tmp);
527 if(*ierr == MPI_SUCCESS) {
532 void mpi_win_post_(int* group, int assert, int* win, int* ierr){
533 *ierr = MPI_Win_post(Group::f2c(*group), assert, Win::f2c(*win));
536 void mpi_win_start_(int* group, int assert, int* win, int* ierr){
537 *ierr = MPI_Win_start(Group::f2c(*group), assert, Win::f2c(*win));
540 void mpi_win_complete_(int* win, int* ierr){
541 *ierr = MPI_Win_complete(Win::f2c(*win));
544 void mpi_win_wait_(int* win, int* ierr){
545 *ierr = MPI_Win_wait(Win::f2c(*win));
548 void mpi_win_set_name_ (int* win, char * name, int* ierr, int size){
549 //handle trailing blanks
550 while(name[size-1]==' ')
552 while(*name==' '){//handle leading blanks
556 char* tname = xbt_new(char,size+1);
557 strncpy(tname, name, size);
559 *ierr = MPI_Win_set_name(Win::f2c(*win), tname);
563 void mpi_win_get_name_ (int* win, char * name, int* len, int* ierr){
564 *ierr = MPI_Win_get_name(Win::f2c(*win),name,len);
566 name[*len]=' ';//blank padding, not \0
569 void mpi_info_create_( int *info, int* ierr){
571 *ierr = MPI_Info_create(&tmp);
572 if(*ierr == MPI_SUCCESS) {
573 *info = tmp->add_f();
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]==' ')
581 while(*key==' '){//handle leading blanks
585 char* tkey = xbt_new(char,keylen+1);
586 strncpy(tkey, key, keylen);
589 while(value[valuelen-1]==' ')
591 while(*value==' '){//handle leading blanks
595 char* tvalue = xbt_new(char,valuelen+1);
596 strncpy(tvalue, value, valuelen);
597 tvalue[valuelen]='\0';
599 *ierr = MPI_Info_set( Info::f2c(*info), tkey, tvalue);
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]==' ')
607 while(*key==' '){//handle leading blanks
611 char* tkey = xbt_new(char,keylen+1);
612 strncpy(tkey, key, keylen);
614 *ierr = MPI_Info_get(Info::f2c(*info),tkey,*valuelen, value, flag);
619 for (i=0; i<*valuelen; i++){
628 void mpi_info_free_(int* info, int* ierr){
629 MPI_Info tmp = Info::f2c(*info);
630 *ierr = MPI_Info_free(&tmp);
631 if(*ierr == MPI_SUCCESS) {
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, Datatype::f2c(*origin_datatype),*target_rank,
639 *target_disp, *target_count,Datatype::f2c(*tarsmpi_type_f2c), Win::f2c(*win));
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, Datatype::f2c(*origin_datatype),*target_rank,
645 *target_disp, *target_count,Datatype::f2c(*tarsmpi_type_f2c), Op::f2c(*op), Win::f2c(*win));
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, Datatype::f2c(*origin_datatype),*target_rank,
651 *target_disp, *target_count,Datatype::f2c(*tarsmpi_type_f2c), Win::f2c(*win));
654 //following are automatically generated, and have to be checked
655 void mpi_finalized_ (int * flag, int* ierr){
657 *ierr = MPI_Finalized(flag);
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);
666 void mpi_query_thread_ (int *provided, int* ierr){
668 *ierr = MPI_Query_thread(provided);
671 void mpi_is_thread_main_ (int *flag, int* ierr){
673 *ierr = MPI_Is_thread_main(flag);
676 void mpi_address_ (void *location, MPI_Aint * address, int* ierr){
678 *ierr = MPI_Address(location, address);
681 void mpi_get_address_ (void *location, MPI_Aint * address, int* ierr){
683 *ierr = MPI_Get_address(location, address);
686 void mpi_type_dup_ (int* datatype, int* newdatatype, int* ierr){
688 *ierr = MPI_Type_dup(Datatype::f2c(*datatype), &tmp);
689 if(*ierr == MPI_SUCCESS) {
690 *newdatatype = tmp->add_f();
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);
698 *ierr = MPI_Type_set_name(Datatype::f2c(*datatype), tname);
702 void mpi_type_get_name_ (int* datatype, char * name, int* len, int* ierr){
703 *ierr = MPI_Type_get_name(Datatype::f2c(*datatype),name,len);
708 void mpi_type_get_attr_ (int* type, int* type_keyval, void *attribute_val, int* flag, int* ierr){
710 *ierr = MPI_Type_get_attr ( Datatype::f2c(*type), *type_keyval, attribute_val,flag);
713 void mpi_type_set_attr_ (int* type, int* type_keyval, void *attribute_val, int* ierr){
715 *ierr = MPI_Type_set_attr ( Datatype::f2c(*type), *type_keyval, attribute_val);
718 void mpi_type_delete_attr_ (int* type, int* type_keyval, int* ierr){
720 *ierr = MPI_Type_delete_attr ( Datatype::f2c(*type), *type_keyval);
723 void mpi_type_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
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) ;
729 void mpi_type_free_keyval_ (int* keyval, int* ierr) {
730 *ierr = MPI_Type_free_keyval( keyval);
733 void mpi_pcontrol_ (int* level , int* ierr){
734 *ierr = MPI_Pcontrol(*static_cast<const int*>(level));
737 void mpi_type_get_extent_ (int* datatype, MPI_Aint * lb, MPI_Aint * extent, int* ierr){
739 *ierr = MPI_Type_get_extent(Datatype::f2c(*datatype), lb, extent);
742 void mpi_type_get_true_extent_ (int* datatype, MPI_Aint * lb, MPI_Aint * extent, int* ierr){
744 *ierr = MPI_Type_get_true_extent(Datatype::f2c(*datatype), lb, extent);
747 void mpi_op_create_ (void * function, int* commute, int* op, int* ierr){
749 *ierr = MPI_Op_create(reinterpret_cast<MPI_User_function*>(function),*commute, &tmp);
750 if(*ierr == MPI_SUCCESS) {
751 tmp->set_fortran_op();
756 void mpi_op_free_ (int* op, int* ierr){
757 MPI_Op tmp=Op::f2c(*op);
758 *ierr = MPI_Op_free(& tmp);
759 if(*ierr == MPI_SUCCESS) {
764 void mpi_group_free_ (int* group, int* ierr){
765 MPI_Group tmp=Group::f2c(*group);
766 *ierr = MPI_Group_free(&tmp);
767 if(*ierr == MPI_SUCCESS) {
772 void mpi_group_size_ (int* group, int *size, int* ierr){
774 *ierr = MPI_Group_size(Group::f2c(*group), size);
777 void mpi_group_rank_ (int* group, int *rank, int* ierr){
779 *ierr = MPI_Group_rank(Group::f2c(*group), rank);
782 void mpi_group_translate_ranks_ (int* group1, int* n, int *ranks1, int* group2, int *ranks2, int* ierr)
785 *ierr = MPI_Group_translate_ranks(Group::f2c(*group1), *n, ranks1, Group::f2c(*group2), ranks2);
788 void mpi_group_compare_ (int* group1, int* group2, int *result, int* ierr){
790 *ierr = MPI_Group_compare(Group::f2c(*group1), Group::f2c(*group2), result);
793 void mpi_group_union_ (int* group1, int* group2, int* newgroup, int* ierr){
795 *ierr = MPI_Group_union(Group::f2c(*group1), Group::f2c(*group2), &tmp);
796 if(*ierr == MPI_SUCCESS) {
797 *newgroup = tmp->add_f();
801 void mpi_group_intersection_ (int* group1, int* group2, int* newgroup, int* ierr){
803 *ierr = MPI_Group_intersection(Group::f2c(*group1), Group::f2c(*group2), &tmp);
804 if(*ierr == MPI_SUCCESS) {
805 *newgroup = tmp->add_f();
809 void mpi_group_difference_ (int* group1, int* group2, int* newgroup, int* ierr){
811 *ierr = MPI_Group_difference(Group::f2c(*group1), Group::f2c(*group2), &tmp);
812 if(*ierr == MPI_SUCCESS) {
813 *newgroup = tmp->add_f();
817 void mpi_group_excl_ (int* group, int* n, int *ranks, int* newgroup, int* ierr){
819 *ierr = MPI_Group_excl(Group::f2c(*group), *n, ranks, &tmp);
820 if(*ierr == MPI_SUCCESS) {
821 *newgroup = tmp->add_f();
825 void mpi_group_range_incl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
828 *ierr = MPI_Group_range_incl(Group::f2c(*group), *n, ranges, &tmp);
829 if(*ierr == MPI_SUCCESS) {
830 *newgroup = tmp->add_f();
834 void mpi_group_range_excl_ (int* group, int* n, int ranges[][3], int* newgroup, int* ierr)
837 *ierr = MPI_Group_range_excl(Group::f2c(*group), *n, ranges, &tmp);
838 if(*ierr == MPI_SUCCESS) {
839 *newgroup = tmp->add_f();
843 void mpi_comm_get_attr_ (int* comm, int* comm_keyval, void *attribute_val, int *flag, int* ierr){
845 *ierr = MPI_Comm_get_attr (Comm::f2c(*comm), *comm_keyval, attribute_val, flag);
848 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, void *attribute_val, int* ierr){
850 *ierr = MPI_Comm_set_attr ( Comm::f2c(*comm), *comm_keyval, attribute_val);
853 void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
855 *ierr = MPI_Comm_delete_attr (Comm::f2c(*comm), *comm_keyval);
858 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
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) ;
864 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
865 *ierr = MPI_Comm_free_keyval( keyval);
868 void mpi_comm_get_name_ (int* comm, char* name, int* len, int* ierr){
869 *ierr = MPI_Comm_get_name(Comm::f2c(*comm), name, len);
874 void mpi_comm_compare_ (int* comm1, int* comm2, int *result, int* ierr){
876 *ierr = MPI_Comm_compare(Comm::f2c(*comm1), Comm::f2c(*comm2), result);
879 void mpi_comm_disconnect_ (int* comm, int* ierr){
880 MPI_Comm tmp=Comm::f2c(*comm);
881 *ierr = MPI_Comm_disconnect(&tmp);
882 if(*ierr == MPI_SUCCESS) {
887 void mpi_request_free_ (int* request, int* ierr){
888 MPI_Request tmp=Request::f2c(*request);
889 *ierr = MPI_Request_free(&tmp);
890 if(*ierr == MPI_SUCCESS) {
891 Request::free_f(*request);
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)
898 *ierr = MPI_Sendrecv_replace(buf, *count, Datatype::f2c(*datatype), *dst, *sendtag, *src,
899 *recvtag, Comm::f2c(*comm), FORT_STATUS_IGNORE(status));
902 void mpi_testany_ (int* count, int* requests, int *index, int *flag, MPI_Status* status, int* ierr)
907 reqs = xbt_new(MPI_Request, *count);
908 for(i = 0; i < *count; i++) {
909 reqs[i] = Request::f2c(requests[i]);
911 *ierr = MPI_Testany(*count, reqs, index, flag, FORT_STATUS_IGNORE(status));
912 if(*index!=MPI_UNDEFINED && reqs[*index]==MPI_REQUEST_NULL){
913 Request::free_f(requests[*index]);
914 requests[*index]=MPI_FORTRAN_REQUEST_NULL;
919 void mpi_waitsome_ (int* incount, int* requests, int *outcount, int *indices, MPI_Status* status, int* ierr)
924 reqs = xbt_new(MPI_Request, *incount);
925 for(i = 0; i < *incount; i++) {
926 reqs[i] = Request::f2c(requests[i]);
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 Request::free_f(requests[indices[i]]);
932 requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
938 void mpi_reduce_local_ (void *inbuf, void *inoutbuf, int* count, int* datatype, int* op, int* ierr){
940 *ierr = MPI_Reduce_local(inbuf, inoutbuf, *count, Datatype::f2c(*datatype), Op::f2c(*op));
943 void mpi_reduce_scatter_block_ (void *sendbuf, void *recvbuf, int* recvcount, int* datatype, int* op, int* comm,
946 sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
947 *ierr = MPI_Reduce_scatter_block(sendbuf, recvbuf, *recvcount, Datatype::f2c(*datatype), Op::f2c(*op),
951 void mpi_pack_size_ (int* incount, int* datatype, int* comm, int* size, int* ierr) {
952 *ierr = MPI_Pack_size(*incount, Datatype::f2c(*datatype), Comm::f2c(*comm), size);
955 void mpi_cart_coords_ (int* comm, int* rank, int* maxdims, int* coords, int* ierr) {
956 *ierr = MPI_Cart_coords(Comm::f2c(*comm), *rank, *maxdims, coords);
959 void mpi_cart_create_ (int* comm_old, int* ndims, int* dims, int* periods, int* reorder, int* comm_cart, int* ierr) {
961 *ierr = MPI_Cart_create(Comm::f2c(*comm_old), *ndims, dims, periods, *reorder, &tmp);
962 if(*ierr == MPI_SUCCESS) {
963 *comm_cart = tmp->add_f();
967 void mpi_cart_get_ (int* comm, int* maxdims, int* dims, int* periods, int* coords, int* ierr) {
968 *ierr = MPI_Cart_get(Comm::f2c(*comm), *maxdims, dims, periods, coords);
971 void mpi_cart_map_ (int* comm_old, int* ndims, int* dims, int* periods, int* newrank, int* ierr) {
972 *ierr = MPI_Cart_map(Comm::f2c(*comm_old), *ndims, dims, periods, newrank);
975 void mpi_cart_rank_ (int* comm, int* coords, int* rank, int* ierr) {
976 *ierr = MPI_Cart_rank(Comm::f2c(*comm), coords, rank);
979 void mpi_cart_shift_ (int* comm, int* direction, int* displ, int* source, int* dest, int* ierr) {
980 *ierr = MPI_Cart_shift(Comm::f2c(*comm), *direction, *displ, source, dest);
983 void mpi_cart_sub_ (int* comm, int* remain_dims, int* comm_new, int* ierr) {
985 *ierr = MPI_Cart_sub(Comm::f2c(*comm), remain_dims, &tmp);
986 if(*ierr == MPI_SUCCESS) {
987 *comm_new = tmp->add_f();
991 void mpi_cartdim_get_ (int* comm, int* ndims, int* ierr) {
992 *ierr = MPI_Cartdim_get(Comm::f2c(*comm), ndims);
995 void mpi_graph_create_ (int* comm_old, int* nnodes, int* index, int* edges, int* reorder, int* comm_graph, int* ierr) {
997 *ierr = MPI_Graph_create(Comm::f2c(*comm_old), *nnodes, index, edges, *reorder, &tmp);
998 if(*ierr == MPI_SUCCESS) {
999 *comm_graph = tmp->add_f();
1003 void mpi_graph_get_ (int* comm, int* maxindex, int* maxedges, int* index, int* edges, int* ierr) {
1004 *ierr = MPI_Graph_get(Comm::f2c(*comm), *maxindex, *maxedges, index, edges);
1007 void mpi_graph_map_ (int* comm_old, int* nnodes, int* index, int* edges, int* newrank, int* ierr) {
1008 *ierr = MPI_Graph_map(Comm::f2c(*comm_old), *nnodes, index, edges, newrank);
1011 void mpi_graph_neighbors_ (int* comm, int* rank, int* maxneighbors, int* neighbors, int* ierr) {
1012 *ierr = MPI_Graph_neighbors(Comm::f2c(*comm), *rank, *maxneighbors, neighbors);
1015 void mpi_graph_neighbors_count_ (int* comm, int* rank, int* nneighbors, int* ierr) {
1016 *ierr = MPI_Graph_neighbors_count(Comm::f2c(*comm), *rank, nneighbors);
1019 void mpi_graphdims_get_ (int* comm, int* nnodes, int* nedges, int* ierr) {
1020 *ierr = MPI_Graphdims_get(Comm::f2c(*comm), nnodes, nedges);
1023 void mpi_topo_test_ (int* comm, int* top_type, int* ierr) {
1024 *ierr = MPI_Topo_test(Comm::f2c(*comm), top_type);
1027 void mpi_error_class_ (int* errorcode, int* errorclass, int* ierr) {
1028 *ierr = MPI_Error_class(*errorcode, errorclass);
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));
1035 void mpi_errhandler_free_ (void* errhandler, int* ierr) {
1036 *ierr = MPI_Errhandler_free(static_cast<MPI_Errhandler*>(errhandler));
1039 void mpi_errhandler_get_ (int* comm, void* errhandler, int* ierr) {
1040 *ierr = MPI_Errhandler_get(Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
1043 void mpi_errhandler_set_ (int* comm, void* errhandler, int* ierr) {
1044 *ierr = MPI_Errhandler_set(Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
1047 void mpi_comm_set_errhandler_ (int* comm, void* errhandler, int* ierr) {
1048 *ierr = MPI_Errhandler_set(Comm::f2c(*comm), *static_cast<MPI_Errhandler*>(errhandler));
1051 void mpi_comm_get_errhandler_ (int* comm, void* errhandler, int* ierr) {
1052 *ierr = MPI_Errhandler_set(Comm::f2c(*comm), static_cast<MPI_Errhandler*>(errhandler));
1055 void mpi_type_contiguous_ (int* count, int* old_type, int* newtype, int* ierr) {
1057 *ierr = MPI_Type_contiguous(*count, Datatype::f2c(*old_type), &tmp);
1058 if(*ierr == MPI_SUCCESS) {
1059 *newtype = tmp->add_f();
1063 void mpi_cancel_ (int* request, int* ierr) {
1064 MPI_Request tmp=Request::f2c(*request);
1065 *ierr = MPI_Cancel(&tmp);
1068 void mpi_buffer_attach_ (void* buffer, int* size, int* ierr) {
1069 *ierr = MPI_Buffer_attach(buffer, *size);
1072 void mpi_buffer_detach_ (void* buffer, int* size, int* ierr) {
1073 *ierr = MPI_Buffer_detach(buffer, size);
1076 void mpi_testsome_ (int* incount, int* requests, int* outcount, int* indices, MPI_Status* statuses, int* ierr) {
1080 reqs = xbt_new(MPI_Request, *incount);
1081 for(i = 0; i < *incount; i++) {
1082 reqs[i] = Request::f2c(requests[i]);
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 Request::free_f(requests[indices[i]]);
1089 requests[indices[i]]=MPI_FORTRAN_REQUEST_NULL;
1095 void mpi_comm_test_inter_ (int* comm, int* flag, int* ierr) {
1096 *ierr = MPI_Comm_test_inter(Comm::f2c(*comm), flag);
1099 void mpi_unpack_ (void* inbuf, int* insize, int* position, void* outbuf, int* outcount, int* type, int* comm,
1101 *ierr = MPI_Unpack(inbuf, *insize, position, outbuf, *outcount, Datatype::f2c(*type), Comm::f2c(*comm));
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, Datatype::f2c(*datatype), size);
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, Datatype::f2c(*datatype), outbuf, *outcount, position);
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, Datatype::f2c(*datatype));
1118 void mpi_type_hindexed_ (int* count, int* blocklens, MPI_Aint* indices, int* old_type, int* newtype, int* ierr) {
1120 *ierr = MPI_Type_hindexed(*count, blocklens, indices, Datatype::f2c(*old_type), &tmp);
1121 if(*ierr == MPI_SUCCESS) {
1122 *newtype = tmp->add_f();
1126 void mpi_type_create_hindexed_(int* count, int* blocklens, MPI_Aint* indices, int* old_type, int* newtype, int* ierr){
1128 *ierr = MPI_Type_create_hindexed(*count, blocklens, indices, Datatype::f2c(*old_type), &tmp);
1129 if(*ierr == MPI_SUCCESS) {
1130 *newtype = tmp->add_f();
1134 void mpi_type_create_hindexed_block_ (int* count, int* blocklength, MPI_Aint* indices, int* old_type, int* newtype,
1137 *ierr = MPI_Type_create_hindexed_block(*count, *blocklength, indices, Datatype::f2c(*old_type), &tmp);
1138 if(*ierr == MPI_SUCCESS) {
1139 *newtype = tmp->add_f();
1143 void mpi_type_indexed_ (int* count, int* blocklens, int* indices, int* old_type, int* newtype, int* ierr) {
1145 *ierr = MPI_Type_indexed(*count, blocklens, indices, Datatype::f2c(*old_type), &tmp);
1146 if(*ierr == MPI_SUCCESS) {
1147 *newtype = tmp->add_f();
1151 void mpi_type_create_indexed_block_ (int* count, int* blocklength, int* indices, int* old_type, int*newtype,
1154 *ierr = MPI_Type_create_indexed_block(*count, *blocklength, indices, Datatype::f2c(*old_type), &tmp);
1155 if(*ierr == MPI_SUCCESS) {
1156 *newtype = tmp->add_f();
1160 void mpi_type_struct_ (int* count, int* blocklens, MPI_Aint* indices, int* old_types, int* newtype, int* ierr) {
1163 MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
1164 for(i=0; i< *count; i++){
1165 types[i] = Datatype::f2c(old_types[i]);
1167 *ierr = MPI_Type_struct(*count, blocklens, indices, types, &tmp);
1168 if(*ierr == MPI_SUCCESS) {
1169 *newtype = tmp->add_f();
1174 void mpi_type_create_struct_(int* count, int* blocklens, MPI_Aint* indices, int* old_types, int* newtype, int* ierr){
1177 MPI_Datatype* types = static_cast<MPI_Datatype*>(xbt_malloc(*count*sizeof(MPI_Datatype)));
1178 for(i=0; i< *count; i++){
1179 types[i] = Datatype::f2c(old_types[i]);
1181 *ierr = MPI_Type_create_struct(*count, blocklens, indices, types, &tmp);
1182 if(*ierr == MPI_SUCCESS) {
1183 *newtype = tmp->add_f();
1188 void mpi_ssend_ (void* buf, int* count, int* datatype, int* dest, int* tag, int* comm, int* ierr) {
1189 *ierr = MPI_Ssend(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm));
1192 void mpi_ssend_init_ (void* buf, int* count, int* datatype, int* dest, int* tag, int* comm, int* request, int* ierr) {
1194 *ierr = MPI_Ssend_init(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm), &tmp);
1195 if(*ierr == MPI_SUCCESS) {
1196 *request = tmp->add_f();
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) {
1203 *ierr = MPI_Intercomm_create(Comm::f2c(*local_comm), *local_leader,Comm::f2c(*peer_comm), *remote_leader,
1205 if(*ierr == MPI_SUCCESS) {
1206 *comm_out = tmp->add_f();
1210 void mpi_intercomm_merge_ (int* comm, int* high, int* comm_out, int* ierr) {
1212 *ierr = MPI_Intercomm_merge(Comm::f2c(*comm), *high, &tmp);
1213 if(*ierr == MPI_SUCCESS) {
1214 *comm_out = tmp->add_f();
1218 void mpi_bsend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int* ierr) {
1219 *ierr = MPI_Bsend(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm));
1222 void mpi_bsend_init_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int* request, int* ierr) {
1224 *ierr = MPI_Bsend_init(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm), &tmp);
1225 if(*ierr == MPI_SUCCESS) {
1226 *request = tmp->add_f();
1230 void mpi_ibsend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int* request, int* ierr) {
1232 *ierr = MPI_Ibsend(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm), &tmp);
1233 if(*ierr == MPI_SUCCESS) {
1234 *request = tmp->add_f();
1238 void mpi_comm_remote_group_ (int* comm, int* group, int* ierr) {
1240 *ierr = MPI_Comm_remote_group(Comm::f2c(*comm), &tmp);
1241 if(*ierr == MPI_SUCCESS) {
1242 *group = tmp->c2f();
1246 void mpi_comm_remote_size_ (int* comm, int* size, int* ierr) {
1247 *ierr = MPI_Comm_remote_size(Comm::f2c(*comm), size);
1250 void mpi_issend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int* request, int* ierr) {
1252 *ierr = MPI_Issend(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm), &tmp);
1253 if(*ierr == MPI_SUCCESS) {
1254 *request = tmp->add_f();
1258 void mpi_probe_ (int* source, int* tag, int* comm, MPI_Status* status, int* ierr) {
1259 *ierr = MPI_Probe(*source, *tag, Comm::f2c(*comm), FORT_STATUS_IGNORE(status));
1262 void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) {
1263 *ierr = MPI_Attr_delete(Comm::f2c(*comm), *keyval);
1266 void mpi_attr_put_ (int* comm, int* keyval, void* attr_value, int* ierr) {
1267 *ierr = MPI_Attr_put(Comm::f2c(*comm), *keyval, attr_value);
1270 void mpi_rsend_init_ (void* buf, int* count, int* datatype, int *dest, int* tag, int* comm, int* request, int* ierr) {
1272 *ierr = MPI_Rsend_init(buf, *count, Datatype::f2c(*datatype), *dest, *tag, Comm::f2c(*comm), &tmp);
1273 if(*ierr == MPI_SUCCESS) {
1274 *request = tmp->add_f();
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);
1282 void mpi_keyval_free_ (int* keyval, int* ierr) {
1283 *ierr = MPI_Keyval_free(keyval);
1286 void mpi_test_cancelled_ (MPI_Status* status, int* flag, int* ierr) {
1287 *ierr = MPI_Test_cancelled(status, flag);
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, Datatype::f2c(*type), outbuf, *outcount, position, Comm::f2c(*comm));
1294 void mpi_get_elements_ (MPI_Status* status, int* datatype, int* elements, int* ierr) {
1295 *ierr = MPI_Get_elements(status, Datatype::f2c(*datatype), elements);
1298 void mpi_dims_create_ (int* nnodes, int* ndims, int* dims, int* ierr) {
1299 *ierr = MPI_Dims_create(*nnodes, *ndims, dims);
1302 void mpi_iprobe_ (int* source, int* tag, int* comm, int* flag, MPI_Status* status, int* ierr) {
1303 *ierr = MPI_Iprobe(*source, *tag, Comm::f2c(*comm), flag, status);
1306 void mpi_type_get_envelope_ ( int* datatype, int *num_integers, int *num_addresses, int *num_datatypes, int *combiner,
1308 *ierr = MPI_Type_get_envelope( Datatype::f2c(*datatype), num_integers,
1309 num_addresses, num_datatypes, combiner);
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(Datatype::f2c(*datatype), *max_integers, *max_addresses,*max_datatypes,
1316 array_of_integers, array_of_addresses, reinterpret_cast<MPI_Datatype*>(array_of_datatypes));
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) {
1323 *ierr = MPI_Type_create_darray(*size, *rank, *ndims, array_of_gsizes,
1324 array_of_distribs, array_of_dargs, array_of_psizes,
1325 *order, Datatype::f2c(*oldtype), &tmp) ;
1326 if(*ierr == MPI_SUCCESS) {
1327 *newtype = tmp->add_f();
1331 void mpi_type_create_resized_ (int* oldtype,MPI_Aint* lb, MPI_Aint* extent, int*newtype, int* ierr){
1333 *ierr = MPI_Type_create_resized(Datatype::f2c(*oldtype),*lb, *extent, &tmp);
1334 if(*ierr == MPI_SUCCESS) {
1335 *newtype = tmp->add_f();
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){
1342 *ierr = MPI_Type_create_subarray(*ndims,array_of_sizes, array_of_subsizes, array_of_starts, *order,
1343 Datatype::f2c(*oldtype), &tmp);
1344 if(*ierr == MPI_SUCCESS) {
1345 *newtype = tmp->add_f();
1349 void mpi_type_match_size_ (int* typeclass,int* size,int* datatype, int* ierr){
1351 *ierr = MPI_Type_match_size(*typeclass,*size,&tmp);
1352 if(*ierr == MPI_SUCCESS) {
1353 *datatype = tmp->c2f();
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), Comm::f2c(*comm));
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, Datatype::f2c(*datatype), Op::f2c(*op), Comm::f2c(*comm));
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);
1371 *ierr = MPI_Comm_set_name (Comm::f2c(*comm), tname);
1375 void mpi_comm_dup_with_info_ (int* comm, int* info, int* newcomm, int* ierr){
1377 *ierr = MPI_Comm_dup_with_info(Comm::f2c(*comm),Info::f2c(*info),&tmp);
1378 if(*ierr == MPI_SUCCESS) {
1379 *newcomm = tmp->add_f();
1383 void mpi_comm_split_type_ (int* comm, int* split_type, int* key, int* info, int* newcomm, int* ierr){
1385 *ierr = MPI_Comm_split_type(Comm::f2c(*comm), *split_type, *key, Info::f2c(*info), &tmp);
1386 if(*ierr == MPI_SUCCESS) {
1387 *newcomm = tmp->add_f();
1391 void mpi_comm_set_info_ (int* comm, int* info, int* ierr){
1392 *ierr = MPI_Comm_set_info (Comm::f2c(*comm), Info::f2c(*info));
1395 void mpi_comm_get_info_ (int* comm, int* info, int* ierr){
1397 *ierr = MPI_Comm_get_info (Comm::f2c(*comm), &tmp);
1398 if(*ierr==MPI_SUCCESS){
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));
1407 void mpi_add_error_class_ ( int *errorclass, int* ierr){
1408 *ierr = MPI_Add_error_class( errorclass);
1411 void mpi_add_error_code_ ( int* errorclass, int *errorcode, int* ierr){
1412 *ierr = MPI_Add_error_code(*errorclass, errorcode);
1415 void mpi_add_error_string_ ( int* errorcode, char *string, int* ierr){
1416 *ierr = MPI_Add_error_string(*errorcode, string);
1419 void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){
1420 *ierr = MPI_Comm_call_errhandler(Comm::f2c(*comm), *errorcode);
1423 void mpi_info_dup_ (int* info, int* newinfo, int* ierr){
1425 *ierr = MPI_Info_dup(Info::f2c(*info), &tmp);
1426 if(*ierr==MPI_SUCCESS){
1427 *newinfo= tmp->add_f();
1431 void mpi_info_get_valuelen_ ( int* info, char *key, int *valuelen, int *flag, int* ierr, unsigned int keylen){
1432 while(key[keylen-1]==' ')
1434 while(*key==' '){//handle leading blanks
1438 char* tkey = xbt_new(char, keylen+1);
1439 strncpy(tkey, key, keylen);
1441 *ierr = MPI_Info_get_valuelen( Info::f2c(*info), tkey, valuelen, flag);
1445 void mpi_info_delete_ (int* info, char *key, int* ierr, unsigned int keylen){
1446 while(key[keylen-1]==' ')
1448 while(*key==' '){//handle leading blanks
1452 char* tkey = xbt_new(char, keylen+1);
1453 strncpy(tkey, key, keylen);
1455 *ierr = MPI_Info_delete(Info::f2c(*info), tkey);
1459 void mpi_info_get_nkeys_ ( int* info, int *nkeys, int* ierr){
1460 *ierr = MPI_Info_get_nkeys( Info::f2c(*info), nkeys);
1463 void mpi_info_get_nthkey_ ( int* info, int* n, char *key, int* ierr, unsigned int keylen){
1464 *ierr = MPI_Info_get_nthkey( Info::f2c(*info), *n, key);
1466 for (i=strlen(key); i<keylen; i++)
1470 void mpi_get_version_ (int *version,int *subversion, int* ierr){
1471 *ierr = MPI_Get_version (version,subversion);
1474 void mpi_get_library_version_ (char *version,int *len, int* ierr){
1475 *ierr = MPI_Get_library_version (version,len);
1478 void mpi_request_get_status_ ( int* request, int *flag, MPI_Status* status, int* ierr){
1479 *ierr = MPI_Request_get_status( Request::f2c(*request), flag, status);
1482 void mpi_grequest_start_ ( void *query_fn, void *free_fn, void *cancel_fn, void *extra_state, int*request, int* ierr){
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();
1491 void mpi_grequest_complete_ ( int* request, int* ierr){
1492 *ierr = MPI_Grequest_complete( Request::f2c(*request));
1495 void mpi_status_set_cancelled_ (MPI_Status* status,int* flag, int* ierr){
1496 *ierr = MPI_Status_set_cancelled(status,*flag);
1499 void mpi_status_set_elements_ ( MPI_Status* status, int* datatype, int* count, int* ierr){
1500 *ierr = MPI_Status_set_elements( status, Datatype::f2c(*datatype), *count);
1503 void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
1505 *ierr = MPI_Comm_connect( port_name, *reinterpret_cast<MPI_Info*>(info), *root, Comm::f2c(*comm), &tmp);
1506 if(*ierr == MPI_SUCCESS) {
1507 *newcomm = tmp->add_f();
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);
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);
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);
1523 void mpi_comm_join_ ( int* fd, int* intercomm, int* ierr){
1525 *ierr = MPI_Comm_join( *fd, &tmp);
1526 if(*ierr == MPI_SUCCESS) {
1527 *intercomm = tmp->add_f();
1531 void mpi_open_port_ ( int* info, char *port_name, int* ierr){
1532 *ierr = MPI_Open_port( *reinterpret_cast<MPI_Info*>(info),port_name);
1535 void mpi_close_port_ ( char *port_name, int* ierr){
1536 *ierr = MPI_Close_port( port_name);
1539 void mpi_comm_accept_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){
1541 *ierr = MPI_Comm_accept( port_name, *reinterpret_cast<MPI_Info*>(info), *root, Comm::f2c(*comm), &tmp);
1542 if(*ierr == MPI_SUCCESS) {
1543 *newcomm = tmp->add_f();
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){
1550 *ierr = MPI_Comm_spawn( command, nullptr, *maxprocs, *reinterpret_cast<MPI_Info*>(info), *root, Comm::f2c(*comm), &tmp,
1552 if(*ierr == MPI_SUCCESS) {
1553 *intercomm = tmp->add_f();
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){
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, Comm::f2c(*comm), &tmp, array_of_errcodes);
1563 if(*ierr == MPI_SUCCESS) {
1564 *intercomm = tmp->add_f();
1568 void mpi_comm_get_parent_ ( int* parent, int* ierr){
1570 *ierr = MPI_Comm_get_parent( &tmp);
1571 if(*ierr == MPI_SUCCESS) {
1572 *parent = tmp->c2f();
1576 void mpi_file_close_ ( int* file, int* ierr){
1577 *ierr= MPI_File_close(reinterpret_cast<MPI_File*>(*file));
1580 void mpi_file_delete_ ( char* filename, int* info, int* ierr){
1581 *ierr= MPI_File_delete(filename, Info::f2c(*info));
1584 void mpi_file_open_ ( int* comm, char* filename, int* amode, int* info, int* fh, int* ierr){
1585 *ierr= MPI_File_open(Comm::f2c(*comm), filename, *amode, Info::f2c(*info), reinterpret_cast<MPI_File*>(*fh));
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), Datatype::f2c(*etype), Datatype::f2c(*filetype), datarep, Info::f2c(*info));
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, Datatype::f2c(*datatype), status);
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, Datatype::f2c(*datatype), status);