Logo AND Algorithmique Numérique Distribuée

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