Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add MPI_Comm_*keyval and MPI_Comm*attr functions
[simgrid.git] / src / smpi / smpi_pmpi.c
1
2 /* Copyright (c) 2007-2014. The SimGrid Team.
3  * All rights reserved.                                                     */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "private.h"
9 #include "smpi_mpi_dt_private.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
12                                 "Logging specific to SMPI (pmpi)");
13
14 #ifdef HAVE_TRACING
15 //this function need to be here because of the calls to smpi_bench
16 void TRACE_smpi_set_category(const char *category)
17 {
18   //need to end bench otherwise categories for execution tasks are wrong
19   smpi_bench_end();
20   TRACE_internal_smpi_set_category (category);
21   //begin bench after changing process's category
22   smpi_bench_begin();
23 }
24 #endif
25
26 /* PMPI User level calls */
27
28 int PMPI_Init(int *argc, char ***argv)
29 {
30   smpi_process_init(argc, argv);
31   smpi_process_mark_as_initialized();
32 #ifdef HAVE_TRACING
33   int rank = smpi_process_index();
34   TRACE_smpi_init(rank);
35   TRACE_smpi_computing_init(rank);
36   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
37   extra->type = TRACING_INIT;
38   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
39   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
40 #endif
41   smpi_bench_begin();
42   return MPI_SUCCESS;
43 }
44
45 int PMPI_Finalize(void)
46 {
47   smpi_bench_end();
48 #ifdef HAVE_TRACING
49   int rank = smpi_process_index();
50   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
51   extra->type = TRACING_FINALIZE;
52   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
53 #endif
54   smpi_process_finalize();
55 #ifdef HAVE_TRACING
56   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
57   TRACE_smpi_finalize(smpi_process_index());
58 #endif
59   smpi_process_destroy();
60   return MPI_SUCCESS;
61 }
62
63 int PMPI_Finalized(int* flag)
64 {
65   *flag=smpi_process_finalized();
66   return MPI_SUCCESS;
67 }
68
69 int PMPI_Get_version (int *version,int *subversion){
70   *version = MPI_VERSION;
71   *subversion= MPI_SUBVERSION;
72   return MPI_SUCCESS;
73 }
74
75 int PMPI_Get_library_version (char *version,int *len){
76   int retval = MPI_SUCCESS;
77   smpi_bench_end();
78   snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2014",SIMGRID_VERSION_MAJOR,
79           SIMGRID_VERSION_MINOR);
80   *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
81   smpi_bench_begin();
82   return retval;
83 }
84
85 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
86 {
87   if (provided != NULL) {
88     *provided = MPI_THREAD_MULTIPLE;
89   }
90   return MPI_Init(argc, argv);
91 }
92
93 int PMPI_Query_thread(int *provided)
94 {
95   int retval = 0;
96
97   if (provided == NULL) {
98     retval = MPI_ERR_ARG;
99   } else {
100     *provided = MPI_THREAD_MULTIPLE;
101     retval = MPI_SUCCESS;
102   }
103   return retval;
104 }
105
106 int PMPI_Is_thread_main(int *flag)
107 {
108   int retval = 0;
109
110   if (flag == NULL) {
111     retval = MPI_ERR_ARG;
112   } else {
113     *flag = smpi_process_index() == 0;
114     retval = MPI_SUCCESS;
115   }
116   return retval;
117 }
118
119 int PMPI_Abort(MPI_Comm comm, int errorcode)
120 {
121   smpi_bench_end();
122   smpi_process_destroy();
123   // FIXME: should kill all processes in comm instead
124   simcall_process_kill(SIMIX_process_self());
125   return MPI_SUCCESS;
126 }
127
128 double PMPI_Wtime(void)
129 {
130   return smpi_mpi_wtime();
131 }
132
133 extern double sg_maxmin_precision;
134 double PMPI_Wtick(void)
135 {
136   return sg_maxmin_precision;
137 }
138
139 int PMPI_Address(void *location, MPI_Aint * address)
140 {
141   int retval = 0;
142
143   if (!address) {
144     retval = MPI_ERR_ARG;
145   } else {
146     *address = (MPI_Aint) location;
147     retval = MPI_SUCCESS;
148   }
149   return retval;
150 }
151
152 int PMPI_Get_address(void *location, MPI_Aint * address)
153 {
154   return PMPI_Address(location, address);
155 }
156
157 int PMPI_Type_free(MPI_Datatype * datatype)
158 {
159   int retval = 0;
160   /* Free a predefined datatype is an error according to the standard, and
161      should be checked for */
162   if (*datatype == MPI_DATATYPE_NULL) {
163     retval = MPI_ERR_ARG;
164   } else {
165     smpi_datatype_free(datatype);
166     retval = MPI_SUCCESS;
167   }
168   return retval;
169 }
170
171 int PMPI_Type_size(MPI_Datatype datatype, int *size)
172 {
173   int retval = 0;
174
175   if (datatype == MPI_DATATYPE_NULL) {
176     retval = MPI_ERR_TYPE;
177   } else if (size == NULL) {
178     retval = MPI_ERR_ARG;
179   } else {
180     *size = (int) smpi_datatype_size(datatype);
181     retval = MPI_SUCCESS;
182   }
183   return retval;
184 }
185
186 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
187 {
188   int retval = 0;
189
190   if (datatype == MPI_DATATYPE_NULL) {
191     retval = MPI_ERR_TYPE;
192   } else if (lb == NULL || extent == NULL) {
193     retval = MPI_ERR_ARG;
194   } else {
195     retval = smpi_datatype_extent(datatype, lb, extent);
196   }
197   return retval;
198 }
199
200 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
201 {
202   return PMPI_Type_get_extent(datatype, lb, extent);
203 }
204
205 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
206 {
207   int retval = 0;
208
209   if (datatype == MPI_DATATYPE_NULL) {
210     retval = MPI_ERR_TYPE;
211   } else if (extent == NULL) {
212     retval = MPI_ERR_ARG;
213   } else {
214     *extent = smpi_datatype_get_extent(datatype);
215     retval = MPI_SUCCESS;
216   }
217   return retval;
218 }
219
220 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
221 {
222   int retval = 0;
223
224   if (datatype == MPI_DATATYPE_NULL) {
225     retval = MPI_ERR_TYPE;
226   } else if (disp == NULL) {
227     retval = MPI_ERR_ARG;
228   } else {
229     *disp = smpi_datatype_lb(datatype);
230     retval = MPI_SUCCESS;
231   }
232   return retval;
233 }
234
235 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
236 {
237   int retval = 0;
238
239   if (datatype == MPI_DATATYPE_NULL) {
240     retval = MPI_ERR_TYPE;
241   } else if (disp == NULL) {
242     retval = MPI_ERR_ARG;
243   } else {
244     *disp = smpi_datatype_ub(datatype);
245     retval = MPI_SUCCESS;
246   }
247   return retval;
248 }
249
250 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
251   int retval = 0;
252
253   if (datatype == MPI_DATATYPE_NULL) {
254     retval = MPI_ERR_TYPE;
255   } else {
256     *newtype = smpi_datatype_dup(datatype);
257     retval = MPI_SUCCESS;
258   }
259   return retval;
260 }
261
262 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
263 {
264   int retval = 0;
265
266   if (function == NULL || op == NULL) {
267     retval = MPI_ERR_ARG;
268   } else {
269     *op = smpi_op_new(function, commute);
270     retval = MPI_SUCCESS;
271   }
272   return retval;
273 }
274
275 int PMPI_Op_free(MPI_Op * op)
276 {
277   int retval = 0;
278
279   if (op == NULL) {
280     retval = MPI_ERR_ARG;
281   } else if (*op == MPI_OP_NULL) {
282     retval = MPI_ERR_OP;
283   } else {
284     smpi_op_destroy(*op);
285     *op = MPI_OP_NULL;
286     retval = MPI_SUCCESS;
287   }
288   return retval;
289 }
290
291 int PMPI_Group_free(MPI_Group * group)
292 {
293   int retval = 0;
294
295   if (group == NULL) {
296     retval = MPI_ERR_ARG;
297   } else {
298     smpi_group_destroy(*group);
299     *group = MPI_GROUP_NULL;
300     retval = MPI_SUCCESS;
301   }
302   return retval;
303 }
304
305 int PMPI_Group_size(MPI_Group group, int *size)
306 {
307   int retval = 0;
308
309   if (group == MPI_GROUP_NULL) {
310     retval = MPI_ERR_GROUP;
311   } else if (size == NULL) {
312     retval = MPI_ERR_ARG;
313   } else {
314     *size = smpi_group_size(group);
315     retval = MPI_SUCCESS;
316   }
317   return retval;
318 }
319
320 int PMPI_Group_rank(MPI_Group group, int *rank)
321 {
322   int retval = 0;
323
324   if (group == MPI_GROUP_NULL) {
325     retval = MPI_ERR_GROUP;
326   } else if (rank == NULL) {
327     retval = MPI_ERR_ARG;
328   } else {
329     *rank = smpi_group_rank(group, smpi_process_index());
330     retval = MPI_SUCCESS;
331   }
332   return retval;
333 }
334
335 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
336                               MPI_Group group2, int *ranks2)
337 {
338   int retval, i, index;
339   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
340     retval = MPI_ERR_GROUP;
341   } else {
342     for (i = 0; i < n; i++) {
343       if(ranks1[i]==MPI_PROC_NULL){
344         ranks2[i]=MPI_PROC_NULL;
345       }else{
346         index = smpi_group_index(group1, ranks1[i]);
347         ranks2[i] = smpi_group_rank(group2, index);
348       }
349     }
350     retval = MPI_SUCCESS;
351   }
352   return retval;
353 }
354
355 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
356 {
357   int retval = 0;
358
359   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
360     retval = MPI_ERR_GROUP;
361   } else if (result == NULL) {
362     retval = MPI_ERR_ARG;
363   } else {
364     *result = smpi_group_compare(group1, group2);
365     retval = MPI_SUCCESS;
366   }
367   return retval;
368 }
369
370 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
371                     MPI_Group * newgroup)
372 {
373   int retval, i, proc1, proc2, size, size2;
374
375   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
376     retval = MPI_ERR_GROUP;
377   } else if (newgroup == NULL) {
378     retval = MPI_ERR_ARG;
379   } else {
380     size = smpi_group_size(group1);
381     size2 = smpi_group_size(group2);
382     for (i = 0; i < size2; i++) {
383       proc2 = smpi_group_index(group2, i);
384       proc1 = smpi_group_rank(group1, proc2);
385       if (proc1 == MPI_UNDEFINED) {
386         size++;
387       }
388     }
389     if (size == 0) {
390       *newgroup = MPI_GROUP_EMPTY;
391     } else {
392       *newgroup = smpi_group_new(size);
393       size2 = smpi_group_size(group1);
394       for (i = 0; i < size2; i++) {
395         proc1 = smpi_group_index(group1, i);
396         smpi_group_set_mapping(*newgroup, proc1, i);
397       }
398       for (i = size2; i < size; i++) {
399         proc2 = smpi_group_index(group2, i - size2);
400         smpi_group_set_mapping(*newgroup, proc2, i);
401       }
402     }
403     retval = MPI_SUCCESS;
404   }
405   return retval;
406 }
407
408 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
409                            MPI_Group * newgroup)
410 {
411   int retval, i, proc1, proc2, size;
412
413   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
414     retval = MPI_ERR_GROUP;
415   } else if (newgroup == NULL) {
416     retval = MPI_ERR_ARG;
417   } else {
418     size = smpi_group_size(group2);
419     for (i = 0; i < size; i++) {
420       proc2 = smpi_group_index(group2, i);
421       proc1 = smpi_group_rank(group1, proc2);
422       if (proc1 == MPI_UNDEFINED) {
423         size--;
424       }
425     }
426     if (size == 0) {
427       *newgroup = MPI_GROUP_EMPTY;
428     } else {
429       *newgroup = smpi_group_new(size);
430       int j=0;
431       for (i = 0; i < smpi_group_size(group2); i++) {
432         proc2 = smpi_group_index(group2, i);
433         proc1 = smpi_group_rank(group1, proc2);
434         if (proc1 != MPI_UNDEFINED) {
435           smpi_group_set_mapping(*newgroup, proc2, j);
436           j++;
437         }
438       }
439     }
440     retval = MPI_SUCCESS;
441   }
442   return retval;
443 }
444
445 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
446 {
447   int retval, i, proc1, proc2, size, size2;
448
449   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
450     retval = MPI_ERR_GROUP;
451   } else if (newgroup == NULL) {
452     retval = MPI_ERR_ARG;
453   } else {
454     size = size2 = smpi_group_size(group1);
455     for (i = 0; i < size2; i++) {
456       proc1 = smpi_group_index(group1, i);
457       proc2 = smpi_group_rank(group2, proc1);
458       if (proc2 != MPI_UNDEFINED) {
459         size--;
460       }
461     }
462     if (size == 0) {
463       *newgroup = MPI_GROUP_EMPTY;
464     } else {
465       *newgroup = smpi_group_new(size);
466       for (i = 0; i < size2; i++) {
467         proc1 = smpi_group_index(group1, i);
468         proc2 = smpi_group_rank(group2, proc1);
469         if (proc2 == MPI_UNDEFINED) {
470           smpi_group_set_mapping(*newgroup, proc1, i);
471         }
472       }
473     }
474     retval = MPI_SUCCESS;
475   }
476   return retval;
477 }
478
479 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
480 {
481   int retval;
482
483   if (group == MPI_GROUP_NULL) {
484     retval = MPI_ERR_GROUP;
485   } else if (newgroup == NULL) {
486     retval = MPI_ERR_ARG;
487   } else {
488     retval = smpi_group_incl(group, n, ranks, newgroup);
489   }
490   return retval;
491 }
492
493 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
494 {
495   int retval, i, j, newsize, oldsize, index;
496
497   if (group == MPI_GROUP_NULL) {
498     retval = MPI_ERR_GROUP;
499   } else if (newgroup == NULL) {
500     retval = MPI_ERR_ARG;
501   } else {
502     if (n == 0) {
503       *newgroup = group;
504       if(group!= smpi_comm_group(MPI_COMM_WORLD)
505                 && group != MPI_GROUP_NULL
506                 && group != smpi_comm_group(MPI_COMM_SELF)
507                 && group != MPI_GROUP_EMPTY)
508       smpi_group_use(group);
509     } else if (n == smpi_group_size(group)) {
510       *newgroup = MPI_GROUP_EMPTY;
511     } else {
512       oldsize=smpi_group_size(group);
513       newsize = oldsize - n;
514       *newgroup = smpi_group_new(newsize);
515
516       int* to_exclude=xbt_new0(int, smpi_group_size(group));
517       for(i=0; i<oldsize; i++)
518         to_exclude[i]=0;
519       for(i=0; i<n; i++)
520         to_exclude[ranks[i]]=1;
521
522       j=0;
523       for(i=0; i<oldsize; i++){
524         if(to_exclude[i]==0){
525           index = smpi_group_index(group, i);
526           smpi_group_set_mapping(*newgroup, index, j);
527           j++;
528         }
529       }
530
531       xbt_free(to_exclude);
532     }
533     retval = MPI_SUCCESS;
534   }
535   return retval;
536 }
537
538 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
539                          MPI_Group * newgroup)
540 {
541   int retval, i, j, rank, size, index;
542
543   if (group == MPI_GROUP_NULL) {
544     retval = MPI_ERR_GROUP;
545   } else if (newgroup == NULL) {
546     retval = MPI_ERR_ARG;
547   } else {
548     if (n == 0) {
549       *newgroup = MPI_GROUP_EMPTY;
550     } else {
551       size = 0;
552       for (i = 0; i < n; i++) {
553         for (rank = ranges[i][0];       /* First */
554              rank >= 0 && rank < smpi_group_size(group); /* Last */
555               ) {
556           size++;
557           if(rank == ranges[i][1]){/*already last ?*/
558             break;
559           }
560           rank += ranges[i][2]; /* Stride */
561           if (ranges[i][0]<ranges[i][1]){
562               if(rank > ranges[i][1])
563                 break;
564           }else{
565               if(rank < ranges[i][1])
566                 break;
567           }
568         }
569       }
570
571       *newgroup = smpi_group_new(size);
572       j = 0;
573       for (i = 0; i < n; i++) {
574         for (rank = ranges[i][0];     /* First */
575              rank >= 0 && rank < smpi_group_size(group); /* Last */
576              ) {
577           index = smpi_group_index(group, rank);
578           smpi_group_set_mapping(*newgroup, index, j);
579           j++;
580           if(rank == ranges[i][1]){/*already last ?*/
581             break;
582           }
583           rank += ranges[i][2]; /* Stride */
584           if (ranges[i][0]<ranges[i][1]){
585             if(rank > ranges[i][1])
586               break;
587           }else{
588             if(rank < ranges[i][1])
589               break;
590           }
591         }
592       }
593     }
594     retval = MPI_SUCCESS;
595   }
596   return retval;
597 }
598
599 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
600                          MPI_Group * newgroup)
601 {
602   int retval, i, rank, newrank,oldrank, size, index, add;
603
604   if (group == MPI_GROUP_NULL) {
605     retval = MPI_ERR_GROUP;
606   } else if (newgroup == NULL) {
607     retval = MPI_ERR_ARG;
608   } else {
609     if (n == 0) {
610       *newgroup = group;
611       if(group!= smpi_comm_group(MPI_COMM_WORLD)
612                 && group != MPI_GROUP_NULL
613                 && group != smpi_comm_group(MPI_COMM_SELF)
614                 && group != MPI_GROUP_EMPTY)
615       smpi_group_use(group);
616     } else {
617       size = smpi_group_size(group);
618       for (i = 0; i < n; i++) {
619         for (rank = ranges[i][0];       /* First */
620              rank >= 0 && rank < smpi_group_size(group); /* Last */
621               ) {
622           size--;
623           if(rank == ranges[i][1]){/*already last ?*/
624             break;
625           }
626           rank += ranges[i][2]; /* Stride */
627           if (ranges[i][0]<ranges[i][1]){
628               if(rank > ranges[i][1])
629                 break;
630           }else{
631               if(rank < ranges[i][1])
632                 break;
633           }
634         }
635       }
636       if (size == 0) {
637         *newgroup = MPI_GROUP_EMPTY;
638       } else {
639         *newgroup = smpi_group_new(size);
640         newrank=0;
641         oldrank=0;
642         while (newrank < size) {
643           add=1;
644           for (i = 0; i < n; i++) {
645             for (rank = ranges[i][0];
646                 rank >= 0 && rank < smpi_group_size(group);
647                 ){
648               if(rank==oldrank){
649                   add=0;
650                   break;
651               }
652               if(rank == ranges[i][1]){/*already last ?*/
653                 break;
654               }
655               rank += ranges[i][2]; /* Stride */
656               if (ranges[i][0]<ranges[i][1]){
657                   if(rank > ranges[i][1])
658                     break;
659               }else{
660                   if(rank < ranges[i][1])
661                     break;
662               }
663             }
664           }
665           if(add==1){
666             index = smpi_group_index(group, oldrank);
667             smpi_group_set_mapping(*newgroup, index, newrank);
668             newrank++;
669           }
670           oldrank++;
671         }
672       }
673     }
674
675     retval = MPI_SUCCESS;
676   }
677   return retval;
678 }
679
680 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
681 {
682   int retval = 0;
683   if (comm == MPI_COMM_NULL) {
684     retval = MPI_ERR_COMM;
685   } else if (rank == NULL) {
686     retval = MPI_ERR_ARG;
687   } else {
688     *rank = smpi_comm_rank(comm);
689     retval = MPI_SUCCESS;
690   }
691   return retval;
692 }
693
694 int PMPI_Comm_size(MPI_Comm comm, int *size)
695 {
696   int retval = 0;
697   if (comm == MPI_COMM_NULL) {
698     retval = MPI_ERR_COMM;
699   } else if (size == NULL) {
700     retval = MPI_ERR_ARG;
701   } else {
702     *size = smpi_comm_size(comm);
703     retval = MPI_SUCCESS;
704   }
705   return retval;
706 }
707
708 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
709 {
710   int retval = 0;
711
712   if (comm == MPI_COMM_NULL)  {
713     retval = MPI_ERR_COMM;
714   } else if (name == NULL || len == NULL)  {
715     retval = MPI_ERR_ARG;
716   } else {
717     smpi_comm_get_name(comm, name, len);
718     retval = MPI_SUCCESS;
719   }
720   return retval;
721 }
722
723 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
724 {
725   int retval = 0;
726
727   if (comm == MPI_COMM_NULL) {
728     retval = MPI_ERR_COMM;
729   } else if (group == NULL) {
730     retval = MPI_ERR_ARG;
731   } else {
732     *group = smpi_comm_group(comm);
733     if(*group!= smpi_comm_group(MPI_COMM_WORLD)
734               && *group != MPI_GROUP_NULL
735               && *group != smpi_comm_group(MPI_COMM_SELF)
736               && *group != MPI_GROUP_EMPTY)
737     smpi_group_use(*group);
738     retval = MPI_SUCCESS;
739   }
740   return retval;
741 }
742
743 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
744 {
745   int retval = 0;
746
747   if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
748     retval = MPI_ERR_COMM;
749   } else if (result == NULL) {
750     retval = MPI_ERR_ARG;
751   } else {
752     if (comm1 == comm2) {       /* Same communicators means same groups */
753       *result = MPI_IDENT;
754     } else {
755       *result =
756           smpi_group_compare(smpi_comm_group(comm1),
757                              smpi_comm_group(comm2));
758       if (*result == MPI_IDENT) {
759         *result = MPI_CONGRUENT;
760       }
761     }
762     retval = MPI_SUCCESS;
763   }
764   return retval;
765 }
766
767 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
768 {
769   int retval = 0;
770
771   if (comm == MPI_COMM_NULL) {
772     retval = MPI_ERR_COMM;
773   } else if (newcomm == NULL) {
774     retval = MPI_ERR_ARG;
775   } else {
776     retval = smpi_comm_dup(comm, newcomm);
777   }
778   return retval;
779 }
780
781 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
782 {
783   int retval = 0;
784
785   if (comm == MPI_COMM_NULL) {
786     retval = MPI_ERR_COMM;
787   } else if (group == MPI_GROUP_NULL) {
788     retval = MPI_ERR_GROUP;
789   } else if (newcomm == NULL) {
790     retval = MPI_ERR_ARG;
791   } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
792     *newcomm= MPI_COMM_NULL;
793     retval = MPI_SUCCESS;
794   }else{
795
796     *newcomm = smpi_comm_new(group, NULL);
797     retval = MPI_SUCCESS;
798   }
799   return retval;
800 }
801
802 int PMPI_Comm_free(MPI_Comm * comm)
803 {
804   int retval = 0;
805
806   if (comm == NULL) {
807     retval = MPI_ERR_ARG;
808   } else if (*comm == MPI_COMM_NULL) {
809     retval = MPI_ERR_COMM;
810   } else {
811     smpi_comm_destroy(*comm);
812     *comm = MPI_COMM_NULL;
813     retval = MPI_SUCCESS;
814   }
815   return retval;
816 }
817
818 int PMPI_Comm_disconnect(MPI_Comm * comm)
819 {
820   /* TODO: wait until all communication in comm are done */
821   int retval = 0;
822
823   if (comm == NULL) {
824     retval = MPI_ERR_ARG;
825   } else if (*comm == MPI_COMM_NULL) {
826     retval = MPI_ERR_COMM;
827   } else {
828     smpi_comm_destroy(*comm);
829     *comm = MPI_COMM_NULL;
830     retval = MPI_SUCCESS;
831   }
832   return retval;
833 }
834
835 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
836 {
837   int retval = 0;
838   smpi_bench_end();
839
840   if (comm_out == NULL) {
841     retval = MPI_ERR_ARG;
842   } else if (comm == MPI_COMM_NULL) {
843     retval = MPI_ERR_COMM;
844   } else {
845     *comm_out = smpi_comm_split(comm, color, key);
846     retval = MPI_SUCCESS;
847   }
848   smpi_bench_begin();
849
850   return retval;
851 }
852
853 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
854                    int tag, MPI_Comm comm, MPI_Request * request)
855 {
856   int retval = 0;
857
858   smpi_bench_end();
859   if (request == NULL) {
860       retval = MPI_ERR_ARG;
861   } else if (comm == MPI_COMM_NULL) {
862       retval = MPI_ERR_COMM;
863   } else if (!is_datatype_valid(datatype)) {
864       retval = MPI_ERR_TYPE;
865   } else if (dst == MPI_PROC_NULL) {
866       retval = MPI_SUCCESS;
867   } else {
868       *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
869       retval = MPI_SUCCESS;
870   }
871   smpi_bench_begin();
872   if (retval != MPI_SUCCESS && request)
873     *request = MPI_REQUEST_NULL;
874   return retval;
875 }
876
877 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
878                    int tag, MPI_Comm comm, MPI_Request * request)
879 {
880   int retval = 0;
881
882   smpi_bench_end();
883   if (request == NULL) {
884     retval = MPI_ERR_ARG;
885   } else if (comm == MPI_COMM_NULL) {
886     retval = MPI_ERR_COMM;
887   } else if (!is_datatype_valid(datatype)) {
888       retval = MPI_ERR_TYPE;
889   } else if (src == MPI_PROC_NULL) {
890     retval = MPI_SUCCESS;
891   } else {
892     *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
893     retval = MPI_SUCCESS;
894   }
895   smpi_bench_begin();
896   if (retval != MPI_SUCCESS && request)
897     *request = MPI_REQUEST_NULL;
898   return retval;
899 }
900
901 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
902                     int dst, int tag, MPI_Comm comm, MPI_Request* request)
903 {
904   int retval = 0;
905
906   smpi_bench_end();
907   if (request == NULL) {
908     retval = MPI_ERR_ARG;
909   } else if (comm == MPI_COMM_NULL) {
910     retval = MPI_ERR_COMM;
911   } else if (!is_datatype_valid(datatype)) {
912       retval = MPI_ERR_TYPE;
913   } else if (dst == MPI_PROC_NULL) {
914     retval = MPI_SUCCESS;
915   } else {
916     *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
917     retval = MPI_SUCCESS;
918   }
919   smpi_bench_begin();
920   if (retval != MPI_SUCCESS && request)
921     *request = MPI_REQUEST_NULL;
922   return retval;
923 }
924
925 int PMPI_Start(MPI_Request * request)
926 {
927   int retval = 0;
928
929   smpi_bench_end();
930   if (request == NULL || *request == MPI_REQUEST_NULL) {
931     retval = MPI_ERR_REQUEST;
932   } else {
933     smpi_mpi_start(*request);
934     retval = MPI_SUCCESS;
935   }
936   smpi_bench_begin();
937   return retval;
938 }
939
940 int PMPI_Startall(int count, MPI_Request * requests)
941 {
942   int retval;
943   int i = 0;
944   smpi_bench_end();
945   if (requests == NULL) {
946     retval = MPI_ERR_ARG;
947   } else {
948     retval = MPI_SUCCESS;
949     for (i = 0 ;  i < count ; i++) {
950       if(requests[i] == MPI_REQUEST_NULL) {
951         retval = MPI_ERR_REQUEST;
952       }
953     }
954     if(retval != MPI_ERR_REQUEST) {
955       smpi_mpi_startall(count, requests);
956     }
957   }
958   smpi_bench_begin();
959   return retval;
960 }
961
962 int PMPI_Request_free(MPI_Request * request)
963 {
964   int retval = 0;
965
966   smpi_bench_end();
967   if (*request == MPI_REQUEST_NULL) {
968     retval = MPI_ERR_ARG;
969   } else {
970     smpi_mpi_request_free(request);
971     retval = MPI_SUCCESS;
972   }
973   smpi_bench_begin();
974   return retval;
975 }
976
977 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
978                int tag, MPI_Comm comm, MPI_Request * request)
979 {
980   int retval = 0;
981
982   smpi_bench_end();
983
984   if (request == NULL) {
985     retval = MPI_ERR_ARG;
986   } else if (comm == MPI_COMM_NULL) {
987     retval = MPI_ERR_COMM;
988   } else if (src == MPI_PROC_NULL) {
989     *request = MPI_REQUEST_NULL;
990     retval = MPI_SUCCESS;
991   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
992     retval = MPI_ERR_RANK;
993   } else if (count < 0) {
994     retval = MPI_ERR_COUNT;
995   } else if (buf==NULL && count > 0) {
996     retval = MPI_ERR_COUNT;
997   } else if (!is_datatype_valid(datatype)) {
998       retval = MPI_ERR_TYPE;
999   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1000     retval = MPI_ERR_TAG;
1001   } else {
1002
1003 #ifdef HAVE_TRACING
1004     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1005     int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1006
1007     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1008     extra->type = TRACING_IRECV;
1009     extra->send_size = count;
1010     extra->src = src_traced;
1011     extra->dst = rank;
1012     extra->datatype1 = encode_datatype(datatype);
1013     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1014 #endif
1015
1016     *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1017     retval = MPI_SUCCESS;
1018
1019 #ifdef HAVE_TRACING
1020     TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1021     (*request)->recv = 1;
1022 #endif
1023   }
1024
1025   smpi_bench_begin();
1026   if (retval != MPI_SUCCESS && request)
1027     *request = MPI_REQUEST_NULL;
1028   return retval;
1029 }
1030
1031
1032 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1033                int tag, MPI_Comm comm, MPI_Request * request)
1034 {
1035   int retval = 0;
1036
1037   smpi_bench_end();
1038   if (request == NULL) {
1039     retval = MPI_ERR_ARG;
1040   } else if (comm == MPI_COMM_NULL) {
1041     retval = MPI_ERR_COMM;
1042   } else if (dst == MPI_PROC_NULL) {
1043     *request = MPI_REQUEST_NULL;
1044     retval = MPI_SUCCESS;
1045   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1046     retval = MPI_ERR_RANK;
1047   } else if (count < 0) {
1048     retval = MPI_ERR_COUNT;
1049   } else if (buf==NULL && count > 0) {
1050     retval = MPI_ERR_COUNT;
1051   } else if (!is_datatype_valid(datatype)) {
1052       retval = MPI_ERR_TYPE;
1053   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1054     retval = MPI_ERR_TAG;
1055   } else {
1056
1057 #ifdef HAVE_TRACING
1058     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1059     int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1060
1061     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1062     extra->type = TRACING_ISEND;
1063     extra->send_size = count;
1064     extra->src = rank;
1065     extra->dst = dst_traced;
1066     extra->datatype1 = encode_datatype(datatype);
1067     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1068     TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1069 #endif
1070
1071     *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1072     retval = MPI_SUCCESS;
1073
1074 #ifdef HAVE_TRACING
1075     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1076     (*request)->send = 1;
1077 #endif
1078   }
1079
1080   smpi_bench_begin();
1081   if (retval != MPI_SUCCESS && request)
1082     *request = MPI_REQUEST_NULL;
1083   return retval;
1084 }
1085
1086 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1087                 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1088 {
1089   int retval = 0;
1090
1091   smpi_bench_end();
1092   if (request == NULL) {
1093     retval = MPI_ERR_ARG;
1094   } else if (comm == MPI_COMM_NULL) {
1095     retval = MPI_ERR_COMM;
1096   } else if (dst == MPI_PROC_NULL) {
1097     *request = MPI_REQUEST_NULL;
1098     retval = MPI_SUCCESS;
1099   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1100     retval = MPI_ERR_RANK;
1101   } else if (count < 0) {
1102     retval = MPI_ERR_COUNT;
1103   } else if (buf==NULL && count > 0) {
1104     retval = MPI_ERR_COUNT;
1105   } else if (!is_datatype_valid(datatype)) {
1106       retval = MPI_ERR_TYPE;
1107   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1108     retval = MPI_ERR_TAG;
1109   } else {
1110
1111 #ifdef HAVE_TRACING
1112     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1113     int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1114     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1115     extra->type = TRACING_ISSEND;
1116     extra->send_size = count;
1117     extra->src = rank;
1118     extra->dst = dst_traced;
1119     extra->datatype1 = encode_datatype(datatype);
1120     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1121     TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1122 #endif
1123
1124     *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1125     retval = MPI_SUCCESS;
1126
1127 #ifdef HAVE_TRACING
1128     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1129     (*request)->send = 1;
1130 #endif
1131   }
1132
1133   smpi_bench_begin();
1134   if (retval != MPI_SUCCESS && request)
1135     *request = MPI_REQUEST_NULL;
1136   return retval;
1137 }
1138
1139 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1140              MPI_Comm comm, MPI_Status * status)
1141 {
1142   int retval = 0;
1143
1144   smpi_bench_end();
1145   if (comm == MPI_COMM_NULL) {
1146     retval = MPI_ERR_COMM;
1147   } else if (src == MPI_PROC_NULL) {
1148     smpi_empty_status(status);
1149     status->MPI_SOURCE = MPI_PROC_NULL;
1150     retval = MPI_SUCCESS;
1151   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1152     retval = MPI_ERR_RANK;
1153   } else if (count < 0) {
1154     retval = MPI_ERR_COUNT;
1155   } else if (buf==NULL && count > 0) {
1156     retval = MPI_ERR_COUNT;
1157   } else if (!is_datatype_valid(datatype)) {
1158       retval = MPI_ERR_TYPE;
1159   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1160     retval = MPI_ERR_TAG;
1161   } else {
1162 #ifdef HAVE_TRACING
1163   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1164   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1165   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1166   extra->type = TRACING_RECV;
1167   extra->send_size = count;
1168   extra->src = src_traced;
1169   extra->dst = rank;
1170   extra->datatype1 = encode_datatype(datatype);
1171   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1172 #endif
1173
1174     smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1175     retval = MPI_SUCCESS;
1176
1177 #ifdef HAVE_TRACING
1178   //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1179   if(status!=MPI_STATUS_IGNORE){
1180     src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1181     TRACE_smpi_recv(rank, src_traced, rank);
1182   }
1183   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1184 #endif
1185   }
1186
1187   smpi_bench_begin();
1188   return retval;
1189 }
1190
1191 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1192              MPI_Comm comm)
1193 {
1194   int retval = 0;
1195
1196   smpi_bench_end();
1197
1198   if (comm == MPI_COMM_NULL) {
1199     retval = MPI_ERR_COMM;
1200   } else if (dst == MPI_PROC_NULL) {
1201     retval = MPI_SUCCESS;
1202   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1203     retval = MPI_ERR_RANK;
1204   } else if (count < 0) {
1205     retval = MPI_ERR_COUNT;
1206   } else if (buf==NULL && count > 0) {
1207     retval = MPI_ERR_COUNT;
1208   } else if (!is_datatype_valid(datatype)) {
1209       retval = MPI_ERR_TYPE;
1210   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1211     retval = MPI_ERR_TAG;
1212   } else {
1213
1214 #ifdef HAVE_TRACING
1215   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1216   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1217   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1218   extra->type = TRACING_SEND;
1219   extra->send_size = count;
1220   extra->src = rank;
1221   extra->dst = dst_traced;
1222   extra->datatype1 = encode_datatype(datatype);
1223   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1224   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1225 #endif
1226
1227     smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1228     retval = MPI_SUCCESS;
1229
1230 #ifdef HAVE_TRACING
1231   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1232 #endif
1233   }
1234
1235   smpi_bench_begin();
1236   return retval;
1237 }
1238
1239
1240
1241 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1242   int retval = 0;
1243
1244    smpi_bench_end();
1245
1246    if (comm == MPI_COMM_NULL) {
1247      retval = MPI_ERR_COMM;
1248    } else if (dst == MPI_PROC_NULL) {
1249      retval = MPI_SUCCESS;
1250    } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1251      retval = MPI_ERR_RANK;
1252    } else if (count < 0) {
1253      retval = MPI_ERR_COUNT;
1254    } else if (buf==NULL && count > 0) {
1255      retval = MPI_ERR_COUNT;
1256    } else if (!is_datatype_valid(datatype)){
1257      retval = MPI_ERR_TYPE;
1258    } else if(tag<0 && tag !=  MPI_ANY_TAG){
1259      retval = MPI_ERR_TAG;
1260    } else {
1261
1262  #ifdef HAVE_TRACING
1263    int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1264    int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1265    instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1266    extra->type = TRACING_SSEND;
1267    extra->send_size = count;
1268    extra->src = rank;
1269    extra->dst = dst_traced;
1270    extra->datatype1 = encode_datatype(datatype);
1271    TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1272  #endif
1273
1274      smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1275      retval = MPI_SUCCESS;
1276
1277  #ifdef HAVE_TRACING
1278    TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1279  #endif
1280    }
1281
1282    smpi_bench_begin();
1283    return retval;}
1284
1285
1286 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1287                  int dst, int sendtag, void *recvbuf, int recvcount,
1288                  MPI_Datatype recvtype, int src, int recvtag,
1289                  MPI_Comm comm, MPI_Status * status)
1290 {
1291   int retval = 0;
1292
1293   smpi_bench_end();
1294
1295   if (comm == MPI_COMM_NULL) {
1296     retval = MPI_ERR_COMM;
1297   } else if (!is_datatype_valid(sendtype)
1298              || !is_datatype_valid(recvtype)) {
1299     retval = MPI_ERR_TYPE;
1300   } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1301       smpi_empty_status(status);
1302       status->MPI_SOURCE = MPI_PROC_NULL;
1303       retval = MPI_SUCCESS;
1304   }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1305       (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1306     retval = MPI_ERR_RANK;
1307   } else if (sendcount < 0 || recvcount<0) {
1308       retval = MPI_ERR_COUNT;
1309   } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1310     retval = MPI_ERR_COUNT;
1311   } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1312     retval = MPI_ERR_TAG;
1313   } else {
1314
1315 #ifdef HAVE_TRACING
1316   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1317   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1318   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1319   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1320   extra->type = TRACING_SENDRECV;
1321   extra->send_size = sendcount;
1322   extra->recv_size = recvcount;
1323   extra->src = src_traced;
1324   extra->dst = dst_traced;
1325   extra->datatype1 = encode_datatype(sendtype);
1326   extra->datatype2 = encode_datatype(recvtype);
1327
1328   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1329   TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1330 #endif
1331
1332
1333     smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1334                       recvcount, recvtype, src, recvtag, comm, status);
1335     retval = MPI_SUCCESS;
1336
1337 #ifdef HAVE_TRACING
1338   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1339   TRACE_smpi_recv(rank, src_traced, rank);
1340 #endif
1341
1342   }
1343
1344   smpi_bench_begin();
1345   return retval;
1346 }
1347
1348 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1349                          int dst, int sendtag, int src, int recvtag,
1350                          MPI_Comm comm, MPI_Status * status)
1351 {
1352   //TODO: suboptimal implementation
1353   void *recvbuf;
1354   int retval = 0;
1355   if (!is_datatype_valid(datatype)) {
1356       retval = MPI_ERR_TYPE;
1357   } else if (count < 0) {
1358       retval = MPI_ERR_COUNT;
1359   } else {
1360     int size = smpi_datatype_get_extent(datatype) * count;
1361     recvbuf = xbt_new0(char, size);
1362     retval =
1363         MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1364                      datatype, src, recvtag, comm, status);
1365     if(retval==MPI_SUCCESS){
1366         smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1367     }
1368     xbt_free(recvbuf);
1369
1370   }
1371   return retval;
1372 }
1373
1374 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1375 {
1376   int retval = 0;
1377   smpi_bench_end();
1378   if (request == NULL || flag == NULL) {
1379     retval = MPI_ERR_ARG;
1380   } else if (*request == MPI_REQUEST_NULL) {
1381     *flag= TRUE;
1382     smpi_empty_status(status);
1383     retval = MPI_ERR_REQUEST;
1384   } else {
1385 #ifdef HAVE_TRACING
1386     int rank = request && (*request)->comm != MPI_COMM_NULL
1387       ? smpi_process_index()
1388       : -1;
1389
1390     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1391     extra->type = TRACING_TEST;
1392     TRACE_smpi_testing_in(rank, extra);
1393 #endif
1394     *flag = smpi_mpi_test(request, status);
1395 #ifdef HAVE_TRACING
1396     TRACE_smpi_testing_out(rank);
1397 #endif
1398     retval = MPI_SUCCESS;
1399   }
1400   smpi_bench_begin();
1401   return retval;
1402 }
1403
1404 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1405                 MPI_Status * status)
1406 {
1407   int retval = 0;
1408
1409   smpi_bench_end();
1410   if (index == NULL || flag == NULL) {
1411     retval = MPI_ERR_ARG;
1412   } else {
1413     *flag = smpi_mpi_testany(count, requests, index, status);
1414     retval = MPI_SUCCESS;
1415   }
1416   smpi_bench_begin();
1417   return retval;
1418 }
1419
1420 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1421 {
1422   int retval = 0;
1423
1424   smpi_bench_end();
1425   if (flag == NULL) {
1426     retval = MPI_ERR_ARG;
1427   } else {
1428     *flag = smpi_mpi_testall(count, requests, statuses);
1429     retval = MPI_SUCCESS;
1430   }
1431   smpi_bench_begin();
1432   return retval;
1433 }
1434
1435 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1436   int retval = 0;
1437   smpi_bench_end();
1438
1439   if (status == NULL) {
1440     retval = MPI_ERR_ARG;
1441   } else if (comm == MPI_COMM_NULL) {
1442     retval = MPI_ERR_COMM;
1443   } else if (source == MPI_PROC_NULL) {
1444     smpi_empty_status(status);
1445     status->MPI_SOURCE = MPI_PROC_NULL;
1446     retval = MPI_SUCCESS;
1447   } else {
1448     smpi_mpi_probe(source, tag, comm, status);
1449     retval = MPI_SUCCESS;
1450   }
1451   smpi_bench_begin();
1452   return retval;
1453 }
1454
1455
1456 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1457   int retval = 0;
1458   smpi_bench_end();
1459
1460   if (flag == NULL) {
1461     retval = MPI_ERR_ARG;
1462   } else if (status == NULL) {
1463     retval = MPI_ERR_ARG;
1464   } else if (comm == MPI_COMM_NULL) {
1465     retval = MPI_ERR_COMM;
1466   } else if (source == MPI_PROC_NULL) {
1467     *flag=TRUE;
1468     smpi_empty_status(status);
1469     status->MPI_SOURCE = MPI_PROC_NULL;
1470     retval = MPI_SUCCESS;
1471   } else {
1472     smpi_mpi_iprobe(source, tag, comm, flag, status);
1473     retval = MPI_SUCCESS;
1474   }
1475   smpi_bench_begin();
1476   return retval;
1477 }
1478
1479 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1480 {
1481   int retval = 0;
1482
1483   smpi_bench_end();
1484
1485   smpi_empty_status(status);
1486
1487   if (request == NULL) {
1488     retval = MPI_ERR_ARG;
1489   } else if (*request == MPI_REQUEST_NULL) {
1490     retval = MPI_ERR_REQUEST;
1491   } else {
1492
1493 #ifdef HAVE_TRACING
1494     int rank = request && (*request)->comm != MPI_COMM_NULL
1495       ? smpi_process_index()
1496       : -1;
1497
1498     int src_traced = (*request)->src;
1499     int dst_traced = (*request)->dst;
1500     MPI_Comm comm = (*request)->comm;
1501     int is_wait_for_receive = (*request)->recv;
1502     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1503     extra->type = TRACING_WAIT;
1504     TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1505 #endif
1506
1507     smpi_mpi_wait(request, status);
1508     retval = MPI_SUCCESS;
1509
1510 #ifdef HAVE_TRACING
1511     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1512     TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1513     if (is_wait_for_receive) {
1514       if(src_traced==MPI_ANY_SOURCE)
1515         src_traced = (status!=MPI_STATUS_IGNORE) ?
1516           smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1517           src_traced;
1518       TRACE_smpi_recv(rank, src_traced, dst_traced);
1519     }
1520 #endif
1521
1522   }
1523
1524   smpi_bench_begin();
1525   return retval;
1526 }
1527
1528 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1529 {
1530   if (index == NULL)
1531     return MPI_ERR_ARG;
1532
1533   smpi_bench_end();
1534 #ifdef HAVE_TRACING
1535   //save requests information for tracing
1536   int i;
1537   int *srcs = xbt_new0(int, count);
1538   int *dsts = xbt_new0(int, count);
1539   int *recvs = xbt_new0(int, count);
1540   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1541
1542   for (i = 0; i < count; i++) {
1543     MPI_Request req = requests[i];      //already received requests are no longer valid
1544     if (req) {
1545       srcs[i] = req->src;
1546       dsts[i] = req->dst;
1547       recvs[i] = req->recv;
1548       comms[i] = req->comm;
1549     }
1550   }
1551   int rank_traced = smpi_process_index();
1552   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1553   extra->type = TRACING_WAITANY;
1554   extra->send_size=count;
1555   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1556
1557 #endif
1558   *index = smpi_mpi_waitany(count, requests, status);
1559 #ifdef HAVE_TRACING
1560   if(*index!=MPI_UNDEFINED){
1561     int src_traced = srcs[*index];
1562     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1563     int dst_traced = dsts[*index];
1564     int is_wait_for_receive = recvs[*index];
1565     if (is_wait_for_receive) {
1566       if(srcs[*index]==MPI_ANY_SOURCE)
1567         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1568                       smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1569                       srcs[*index];
1570       TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1571     }
1572     TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1573     xbt_free(srcs);
1574     xbt_free(dsts);
1575     xbt_free(recvs);
1576     xbt_free(comms);
1577
1578   }
1579 #endif
1580   smpi_bench_begin();
1581   return MPI_SUCCESS;
1582 }
1583
1584 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1585 {
1586
1587   smpi_bench_end();
1588 #ifdef HAVE_TRACING
1589   //save information from requests
1590   int i;
1591   int *srcs = xbt_new0(int, count);
1592   int *dsts = xbt_new0(int, count);
1593   int *recvs = xbt_new0(int, count);
1594   int *valid = xbt_new0(int, count);
1595   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1596
1597   //int valid_count = 0;
1598   for (i = 0; i < count; i++) {
1599     MPI_Request req = requests[i];
1600     if(req!=MPI_REQUEST_NULL){
1601       srcs[i] = req->src;
1602       dsts[i] = req->dst;
1603       recvs[i] = req->recv;
1604       comms[i] = req->comm;
1605       valid[i]=1;;
1606     }else{
1607       valid[i]=0;
1608     }
1609   }
1610   int rank_traced = smpi_process_index();
1611   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1612   extra->type = TRACING_WAITALL;
1613   extra->send_size=count;
1614   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1615 #endif
1616   int retval = smpi_mpi_waitall(count, requests, status);
1617 #ifdef HAVE_TRACING
1618   for (i = 0; i < count; i++) {
1619     if(valid[i]){
1620     //int src_traced = srcs[*index];
1621     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1622       int src_traced = srcs[i];
1623       int dst_traced = dsts[i];
1624       int is_wait_for_receive = recvs[i];
1625       if (is_wait_for_receive) {
1626         if(src_traced==MPI_ANY_SOURCE)
1627         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1628                           smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1629                           srcs[i];
1630         TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1631       }
1632     }
1633   }
1634   TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1635   xbt_free(srcs);
1636   xbt_free(dsts);
1637   xbt_free(recvs);
1638   xbt_free(valid);
1639   xbt_free(comms);
1640
1641 #endif
1642   smpi_bench_begin();
1643   return retval;
1644 }
1645
1646 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1647                  int *indices, MPI_Status status[])
1648 {
1649   int retval = 0;
1650
1651   smpi_bench_end();
1652   if (outcount == NULL) {
1653     retval = MPI_ERR_ARG;
1654   } else {
1655     *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1656     retval = MPI_SUCCESS;
1657   }
1658   smpi_bench_begin();
1659   return retval;
1660 }
1661
1662 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1663                  int* indices, MPI_Status status[])
1664 {
1665   int retval = 0;
1666
1667    smpi_bench_end();
1668    if (outcount == NULL) {
1669      retval = MPI_ERR_ARG;
1670    } else {
1671      *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1672      retval = MPI_SUCCESS;
1673    }
1674    smpi_bench_begin();
1675    return retval;
1676 }
1677
1678
1679 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1680 {
1681   int retval = 0;
1682
1683   smpi_bench_end();
1684
1685   if (comm == MPI_COMM_NULL) {
1686     retval = MPI_ERR_COMM;
1687   } else if (!is_datatype_valid(datatype)) {
1688       retval = MPI_ERR_ARG;
1689   } else {
1690 #ifdef HAVE_TRACING
1691   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1692   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1693
1694   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1695   extra->type = TRACING_BCAST;
1696   extra->send_size = count;
1697   extra->root = root_traced;
1698   extra->datatype1 = encode_datatype(datatype);
1699   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1700
1701 #endif
1702     mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1703     retval = MPI_SUCCESS;
1704 #ifdef HAVE_TRACING
1705   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1706 #endif
1707   }
1708
1709   smpi_bench_begin();
1710   return retval;
1711 }
1712
1713 int PMPI_Barrier(MPI_Comm comm)
1714 {
1715   int retval = 0;
1716
1717   smpi_bench_end();
1718
1719   if (comm == MPI_COMM_NULL) {
1720     retval = MPI_ERR_COMM;
1721   } else {
1722 #ifdef HAVE_TRACING
1723   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1724   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1725   extra->type = TRACING_BARRIER;
1726   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1727 #endif
1728     mpi_coll_barrier_fun(comm);
1729     retval = MPI_SUCCESS;
1730 #ifdef HAVE_TRACING
1731   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1732 #endif
1733   }
1734
1735   smpi_bench_begin();
1736   return retval;
1737 }
1738
1739 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1740                void *recvbuf, int recvcount, MPI_Datatype recvtype,
1741                int root, MPI_Comm comm)
1742 {
1743   int retval = 0;
1744
1745   smpi_bench_end();
1746
1747   if (comm == MPI_COMM_NULL) {
1748     retval = MPI_ERR_COMM;
1749   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1750             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1751     retval = MPI_ERR_TYPE;
1752   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1753             ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1754     retval = MPI_ERR_COUNT;
1755   } else {
1756
1757     char* sendtmpbuf = (char*) sendbuf;
1758     int sendtmpcount = sendcount;
1759     MPI_Datatype sendtmptype = sendtype;
1760     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1761       sendtmpcount=0;
1762       sendtmptype=recvtype;
1763     }
1764 #ifdef HAVE_TRACING
1765   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1766   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1767   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1768   extra->type = TRACING_GATHER;
1769   extra->send_size = sendtmpcount;
1770   extra->recv_size = recvcount;
1771   extra->root = root_traced;
1772   extra->datatype1 = encode_datatype(sendtmptype);
1773   extra->datatype2 = encode_datatype(recvtype);
1774
1775   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1776 #endif
1777     mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1778                     recvtype, root, comm);
1779
1780
1781     retval = MPI_SUCCESS;
1782 #ifdef HAVE_TRACING
1783   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1784 #endif
1785   }
1786
1787   smpi_bench_begin();
1788   return retval;
1789 }
1790
1791 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1792                 void *recvbuf, int *recvcounts, int *displs,
1793                 MPI_Datatype recvtype, int root, MPI_Comm comm)
1794 {
1795   int retval = 0;
1796
1797   smpi_bench_end();
1798
1799   if (comm == MPI_COMM_NULL) {
1800     retval = MPI_ERR_COMM;
1801   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1802             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1803     retval = MPI_ERR_TYPE;
1804   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1805     retval = MPI_ERR_COUNT;
1806   } else if (recvcounts == NULL || displs == NULL) {
1807     retval = MPI_ERR_ARG;
1808   } else {
1809     char* sendtmpbuf = (char*) sendbuf;
1810     int sendtmpcount = sendcount;
1811     MPI_Datatype sendtmptype = sendtype;
1812     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1813       sendtmpcount=0;
1814       sendtmptype=recvtype;
1815     }
1816
1817 #ifdef HAVE_TRACING
1818   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1819   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1820   int i=0;
1821   int size = smpi_comm_size(comm);
1822   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1823   extra->type = TRACING_GATHERV;
1824   extra->send_size = sendtmpcount;
1825   extra->recvcounts= xbt_malloc(size*sizeof(int));
1826   for(i=0; i< size; i++)//copy data to avoid bad free
1827     extra->recvcounts[i] = recvcounts[i];
1828   extra->num_processes = size;
1829   extra->root = root_traced;
1830   extra->datatype1 = encode_datatype(sendtmptype);
1831   extra->datatype2 = encode_datatype(recvtype);
1832
1833   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1834 #endif
1835     smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1836                      displs, recvtype, root, comm);
1837     retval = MPI_SUCCESS;
1838 #ifdef HAVE_TRACING
1839   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1840 #endif
1841   }
1842
1843   smpi_bench_begin();
1844   return retval;
1845 }
1846
1847 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1848                   void *recvbuf, int recvcount, MPI_Datatype recvtype,
1849                   MPI_Comm comm)
1850 {
1851   int retval = 0;
1852
1853   smpi_bench_end();
1854
1855   if (comm == MPI_COMM_NULL) {
1856     retval = MPI_ERR_COMM;
1857   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1858             (recvtype == MPI_DATATYPE_NULL)){
1859     retval = MPI_ERR_TYPE;
1860   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1861             (recvcount <0)){
1862     retval = MPI_ERR_COUNT;
1863   } else {
1864     if(sendbuf == MPI_IN_PLACE) {
1865       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1866       sendcount=recvcount;
1867       sendtype=recvtype;
1868     }
1869 #ifdef HAVE_TRACING
1870   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1871   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1872   extra->type = TRACING_ALLGATHER;
1873   extra->send_size = sendcount;
1874   extra->recv_size = recvcount;
1875   extra->datatype1 = encode_datatype(sendtype);
1876   extra->datatype2 = encode_datatype(recvtype);
1877
1878   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1879 #endif
1880     mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1881                            recvtype, comm);
1882     retval = MPI_SUCCESS;
1883
1884 #ifdef HAVE_TRACING
1885   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1886 #endif
1887   }
1888   smpi_bench_begin();
1889   return retval;
1890 }
1891
1892 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1893                    void *recvbuf, int *recvcounts, int *displs,
1894                    MPI_Datatype recvtype, MPI_Comm comm)
1895 {
1896   int retval = 0;
1897
1898   smpi_bench_end();
1899
1900   if (comm == MPI_COMM_NULL) {
1901     retval = MPI_ERR_COMM;
1902   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1903             (recvtype == MPI_DATATYPE_NULL)){
1904     retval = MPI_ERR_TYPE;
1905   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1906     retval = MPI_ERR_COUNT;
1907   } else if (recvcounts == NULL || displs == NULL) {
1908     retval = MPI_ERR_ARG;
1909   } else {
1910
1911     if(sendbuf == MPI_IN_PLACE) {
1912       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1913       sendcount=recvcounts[smpi_comm_rank(comm)];
1914       sendtype=recvtype;
1915     }
1916 #ifdef HAVE_TRACING
1917   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1918   int i=0;
1919   int size = smpi_comm_size(comm);
1920   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1921   extra->type = TRACING_ALLGATHERV;
1922   extra->send_size = sendcount;
1923   extra->recvcounts= xbt_malloc(size*sizeof(int));
1924   for(i=0; i< size; i++)//copy data to avoid bad free
1925     extra->recvcounts[i] = recvcounts[i];
1926   extra->num_processes = size;
1927   extra->datatype1 = encode_datatype(sendtype);
1928   extra->datatype2 = encode_datatype(recvtype);
1929
1930   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1931 #endif
1932     mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1933                         displs, recvtype, comm);
1934     retval = MPI_SUCCESS;
1935 #ifdef HAVE_TRACING
1936   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1937 #endif
1938   }
1939
1940   smpi_bench_begin();
1941   return retval;
1942 }
1943
1944 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1945                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1946                 int root, MPI_Comm comm)
1947 {
1948   int retval = 0;
1949
1950   smpi_bench_end();
1951
1952   if (comm == MPI_COMM_NULL) {
1953     retval = MPI_ERR_COMM;
1954   } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1955              || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1956     retval = MPI_ERR_TYPE;
1957   } else if ((sendbuf == recvbuf) ||
1958       ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
1959     retval = MPI_ERR_BUFFER;
1960   }else {
1961
1962     if (recvbuf == MPI_IN_PLACE) {
1963         recvtype=sendtype;
1964         recvcount=sendcount;
1965     }
1966 #ifdef HAVE_TRACING
1967   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1968   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1969   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1970   extra->type = TRACING_SCATTER;
1971   extra->send_size = sendcount;
1972   extra->recv_size= recvcount;
1973   extra->root = root_traced;
1974   extra->datatype1 = encode_datatype(sendtype);
1975   extra->datatype2 = encode_datatype(recvtype);
1976
1977   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1978 #endif
1979     mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1980                      recvtype, root, comm);
1981     retval = MPI_SUCCESS;
1982 #ifdef HAVE_TRACING
1983   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1984 #endif
1985   }
1986
1987   smpi_bench_begin();
1988   return retval;
1989 }
1990
1991 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1992                  MPI_Datatype sendtype, void *recvbuf, int recvcount,
1993                  MPI_Datatype recvtype, int root, MPI_Comm comm)
1994 {
1995   int retval = 0;
1996
1997   smpi_bench_end();
1998
1999   if (comm == MPI_COMM_NULL) {
2000     retval = MPI_ERR_COMM;
2001   } else if (sendcounts == NULL || displs == NULL) {
2002     retval = MPI_ERR_ARG;
2003   } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2004              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2005     retval = MPI_ERR_TYPE;
2006   } else {
2007     if (recvbuf == MPI_IN_PLACE) {
2008         recvtype=sendtype;
2009         recvcount=sendcounts[smpi_comm_rank(comm)];
2010     }
2011 #ifdef HAVE_TRACING
2012   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2013   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2014   int i=0;
2015   int size = smpi_comm_size(comm);
2016   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2017   extra->type = TRACING_SCATTERV;
2018   extra->recv_size = recvcount;
2019   extra->sendcounts= xbt_malloc(size*sizeof(int));
2020   for(i=0; i< size; i++)//copy data to avoid bad free
2021     extra->sendcounts[i] = sendcounts[i];
2022   extra->num_processes = size;
2023   extra->root = root_traced;
2024   extra->datatype1 = encode_datatype(sendtype);
2025   extra->datatype2 = encode_datatype(recvtype);
2026
2027   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2028
2029 #endif
2030     smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2031                       recvcount, recvtype, root, comm);
2032     retval = MPI_SUCCESS;
2033 #ifdef HAVE_TRACING
2034   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2035 #endif
2036   }
2037
2038   smpi_bench_begin();
2039   return retval;
2040 }
2041
2042 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2043                MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2044 {
2045   int retval = 0;
2046
2047   smpi_bench_end();
2048
2049   if (comm == MPI_COMM_NULL) {
2050     retval = MPI_ERR_COMM;
2051   } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2052     retval = MPI_ERR_ARG;
2053   } else {
2054 #ifdef HAVE_TRACING
2055   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2056   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2057   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2058   extra->type = TRACING_REDUCE;
2059   extra->send_size = count;
2060   extra->datatype1 = encode_datatype(datatype);
2061   extra->root = root_traced;
2062
2063   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2064 #endif
2065     mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2066
2067     retval = MPI_SUCCESS;
2068 #ifdef HAVE_TRACING
2069   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2070 #endif
2071   }
2072
2073   smpi_bench_begin();
2074   return retval;
2075 }
2076
2077 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2078     MPI_Datatype datatype, MPI_Op op){
2079   int retval = 0;
2080
2081     smpi_bench_end();
2082     if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2083       retval = MPI_ERR_ARG;
2084     } else {
2085       smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2086       retval=MPI_SUCCESS;
2087     }
2088     smpi_bench_begin();
2089     return retval;
2090 }
2091
2092 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2093                   MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2094 {
2095   int retval = 0;
2096
2097   smpi_bench_end();
2098
2099   if (comm == MPI_COMM_NULL) {
2100     retval = MPI_ERR_COMM;
2101   } else if (!is_datatype_valid(datatype)) {
2102     retval = MPI_ERR_TYPE;
2103   } else if (op == MPI_OP_NULL) {
2104     retval = MPI_ERR_OP;
2105   } else {
2106
2107     char* sendtmpbuf = (char*) sendbuf;
2108     if( sendbuf == MPI_IN_PLACE ) {
2109       sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2110       smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2111     }
2112 #ifdef HAVE_TRACING
2113   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2114   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2115   extra->type = TRACING_ALLREDUCE;
2116   extra->send_size = count;
2117   extra->datatype1 = encode_datatype(datatype);
2118
2119   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2120 #endif
2121     mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2122
2123     if( sendbuf == MPI_IN_PLACE ) {
2124       xbt_free(sendtmpbuf);
2125     }
2126
2127     retval = MPI_SUCCESS;
2128 #ifdef HAVE_TRACING
2129   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2130 #endif
2131   }
2132
2133   smpi_bench_begin();
2134   return retval;
2135 }
2136
2137 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2138              MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2139 {
2140   int retval = 0;
2141
2142   smpi_bench_end();
2143
2144   if (comm == MPI_COMM_NULL) {
2145     retval = MPI_ERR_COMM;
2146   } else if (!is_datatype_valid(datatype)) {
2147     retval = MPI_ERR_TYPE;
2148   } else if (op == MPI_OP_NULL) {
2149     retval = MPI_ERR_OP;
2150   } else {
2151 #ifdef HAVE_TRACING
2152   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2153   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2154   extra->type = TRACING_SCAN;
2155   extra->send_size = count;
2156   extra->datatype1 = encode_datatype(datatype);
2157
2158   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2159 #endif
2160     smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2161     retval = MPI_SUCCESS;
2162 #ifdef HAVE_TRACING
2163   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2164 #endif
2165   }
2166
2167   smpi_bench_begin();
2168   return retval;
2169 }
2170
2171 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2172                 MPI_Op op, MPI_Comm comm){
2173   int retval = 0;
2174
2175   smpi_bench_end();
2176
2177   if (comm == MPI_COMM_NULL) {
2178     retval = MPI_ERR_COMM;
2179   } else if (!is_datatype_valid(datatype)) {
2180     retval = MPI_ERR_TYPE;
2181   } else if (op == MPI_OP_NULL) {
2182     retval = MPI_ERR_OP;
2183   } else {
2184 #ifdef HAVE_TRACING
2185   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2186   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2187   extra->type = TRACING_EXSCAN;
2188   extra->send_size = count;
2189   extra->datatype1 = encode_datatype(datatype);
2190
2191   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2192 #endif
2193     smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2194     retval = MPI_SUCCESS;
2195 #ifdef HAVE_TRACING
2196   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2197 #endif
2198   }
2199
2200   smpi_bench_begin();
2201   return retval;
2202 }
2203
2204 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2205                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2206 {
2207   int retval = 0;
2208   smpi_bench_end();
2209
2210   if (comm == MPI_COMM_NULL) {
2211     retval = MPI_ERR_COMM;
2212   } else if (!is_datatype_valid(datatype)) {
2213     retval = MPI_ERR_TYPE;
2214   } else if (op == MPI_OP_NULL) {
2215     retval = MPI_ERR_OP;
2216   } else if (recvcounts == NULL) {
2217     retval = MPI_ERR_ARG;
2218   } else {
2219 #ifdef HAVE_TRACING
2220   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2221   int i=0;
2222   int size = smpi_comm_size(comm);
2223   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2224   extra->type = TRACING_REDUCE_SCATTER;
2225   extra->send_size = 0;
2226   extra->recvcounts= xbt_malloc(size*sizeof(int));
2227   for(i=0; i< size; i++)//copy data to avoid bad free
2228     extra->recvcounts[i] = recvcounts[i];
2229   extra->num_processes = size;
2230   extra->datatype1 = encode_datatype(datatype);
2231
2232   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2233 #endif
2234     void* sendtmpbuf=sendbuf;
2235     if(sendbuf==MPI_IN_PLACE){
2236       sendtmpbuf=recvbuf;
2237     }
2238
2239     mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2240                        datatype,  op, comm);
2241     retval = MPI_SUCCESS;
2242 #ifdef HAVE_TRACING
2243   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2244 #endif
2245   }
2246
2247   smpi_bench_begin();
2248   return retval;
2249 }
2250
2251 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2252                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2253 {
2254   int retval,i;
2255   smpi_bench_end();
2256
2257   if (comm == MPI_COMM_NULL) {
2258     retval = MPI_ERR_COMM;
2259   } else if (!is_datatype_valid(datatype)) {
2260     retval = MPI_ERR_TYPE;
2261   } else if (op == MPI_OP_NULL) {
2262     retval = MPI_ERR_OP;
2263   } else if (recvcount < 0) {
2264     retval = MPI_ERR_ARG;
2265   } else {
2266     int count=smpi_comm_size(comm);
2267
2268 #ifdef HAVE_TRACING
2269   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2270   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2271   extra->type = TRACING_REDUCE_SCATTER;
2272   extra->send_size = 0;
2273   extra->recvcounts= xbt_malloc(count*sizeof(int));
2274   for(i=0; i< count; i++)//copy data to avoid bad free
2275     extra->recvcounts[i] = recvcount;
2276   extra->num_processes = count;
2277   extra->datatype1 = encode_datatype(datatype);
2278
2279   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2280 #endif
2281     int* recvcounts=(int*)xbt_malloc(count);
2282     for (i=0; i<count;i++)recvcounts[i]=recvcount;
2283     mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2284                        datatype,  op, comm);
2285     xbt_free(recvcounts);
2286     retval = MPI_SUCCESS;
2287 #ifdef HAVE_TRACING
2288   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2289 #endif
2290   }
2291
2292   smpi_bench_begin();
2293   return retval;
2294 }
2295
2296 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2297                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
2298                  MPI_Comm comm)
2299 {
2300   int retval = 0;
2301
2302   smpi_bench_end();
2303
2304   if (comm == MPI_COMM_NULL) {
2305     retval = MPI_ERR_COMM;
2306   } else if (sendtype == MPI_DATATYPE_NULL
2307              || recvtype == MPI_DATATYPE_NULL) {
2308     retval = MPI_ERR_TYPE;
2309   } else {
2310 #ifdef HAVE_TRACING
2311   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2312   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2313   extra->type = TRACING_ALLTOALL;
2314   extra->send_size = sendcount;
2315   extra->recv_size = recvcount;
2316   extra->datatype1 = encode_datatype(sendtype);
2317   extra->datatype2 = encode_datatype(recvtype);
2318
2319   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2320 #endif
2321     retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2322 #ifdef HAVE_TRACING
2323   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2324 #endif
2325   }
2326
2327   smpi_bench_begin();
2328   return retval;
2329 }
2330
2331 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2332                   MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2333                   int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2334 {
2335   int retval = 0;
2336
2337   smpi_bench_end();
2338
2339   if (comm == MPI_COMM_NULL) {
2340     retval = MPI_ERR_COMM;
2341   } else if (sendtype == MPI_DATATYPE_NULL
2342              || recvtype == MPI_DATATYPE_NULL) {
2343     retval = MPI_ERR_TYPE;
2344   } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2345              || recvdisps == NULL) {
2346     retval = MPI_ERR_ARG;
2347   } else {
2348 #ifdef HAVE_TRACING
2349   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2350   int i=0;
2351   int size = smpi_comm_size(comm);
2352   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2353   extra->type = TRACING_ALLTOALLV;
2354   extra->send_size = 0;
2355   extra->recv_size = 0;
2356   extra->recvcounts= xbt_malloc(size*sizeof(int));
2357   extra->sendcounts= xbt_malloc(size*sizeof(int));
2358
2359   for(i=0; i< size; i++){//copy data to avoid bad free
2360     extra->send_size += sendcounts[i];
2361     extra->recv_size += recvcounts[i];
2362
2363     extra->sendcounts[i] = sendcounts[i];
2364     extra->recvcounts[i] = recvcounts[i];
2365   }
2366   extra->num_processes = size;
2367
2368   extra->datatype1 = encode_datatype(sendtype);
2369   extra->datatype2 = encode_datatype(recvtype);
2370
2371   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2372 #endif
2373     retval =
2374         mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2375                                   recvbuf, recvcounts, recvdisps, recvtype,
2376                                   comm);
2377 #ifdef HAVE_TRACING
2378   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2379 #endif
2380   }
2381
2382   smpi_bench_begin();
2383   return retval;
2384 }
2385
2386
2387 int PMPI_Get_processor_name(char *name, int *resultlen)
2388 {
2389   int retval = MPI_SUCCESS;
2390
2391   strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2392           strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2393           strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2394           MPI_MAX_PROCESSOR_NAME - 1 );
2395   *resultlen =
2396       strlen(name) >
2397       MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2398
2399   return retval;
2400 }
2401
2402 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2403 {
2404   int retval = MPI_SUCCESS;
2405   size_t size;
2406
2407   if (status == NULL || count == NULL) {
2408     retval = MPI_ERR_ARG;
2409   } else if (!is_datatype_valid(datatype)) {
2410     retval = MPI_ERR_TYPE;
2411   } else {
2412     size = smpi_datatype_size(datatype);
2413     if (size == 0) {
2414       *count = 0;
2415     } else if (status->count % size != 0) {
2416       retval = MPI_UNDEFINED;
2417     } else {
2418       *count = smpi_mpi_get_count(status, datatype);
2419     }
2420   }
2421   return retval;
2422 }
2423
2424 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2425   int retval = 0;
2426
2427   if (old_type == MPI_DATATYPE_NULL) {
2428     retval = MPI_ERR_TYPE;
2429   } else if (count<0){
2430     retval = MPI_ERR_COUNT;
2431   } else {
2432     retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2433   }
2434   return retval;
2435 }
2436
2437 int PMPI_Type_commit(MPI_Datatype* datatype) {
2438   int retval = 0;
2439
2440   if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2441     retval = MPI_ERR_TYPE;
2442   } else {
2443     smpi_datatype_commit(datatype);
2444     retval = MPI_SUCCESS;
2445   }
2446   return retval;
2447 }
2448
2449
2450 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2451   int retval = 0;
2452
2453   if (old_type == MPI_DATATYPE_NULL) {
2454     retval = MPI_ERR_TYPE;
2455   } else if (count<0 || blocklen<0){
2456     retval = MPI_ERR_COUNT;
2457   } else {
2458     retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2459   }
2460   return retval;
2461 }
2462
2463 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2464   int retval = 0;
2465
2466   if (old_type == MPI_DATATYPE_NULL) {
2467     retval = MPI_ERR_TYPE;
2468   } else if (count<0 || blocklen<0){
2469     retval = MPI_ERR_COUNT;
2470   } else {
2471     retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2472   }
2473   return retval;
2474 }
2475
2476 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2477   return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2478 }
2479
2480 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2481   int retval = 0;
2482
2483   if (old_type == MPI_DATATYPE_NULL) {
2484     retval = MPI_ERR_TYPE;
2485   } else if (count<0){
2486     retval = MPI_ERR_COUNT;
2487   } else {
2488     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2489   }
2490   return retval;
2491 }
2492
2493 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2494   int retval = 0;
2495
2496   if (old_type == MPI_DATATYPE_NULL) {
2497     retval = MPI_ERR_TYPE;
2498   } else if (count<0){
2499     retval = MPI_ERR_COUNT;
2500   } else {
2501     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2502   }
2503   return retval;
2504 }
2505
2506 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2507   int retval,i;
2508
2509   if (old_type == MPI_DATATYPE_NULL) {
2510     retval = MPI_ERR_TYPE;
2511   } else if (count<0){
2512     retval = MPI_ERR_COUNT;
2513   } else {
2514     int* blocklens=(int*)xbt_malloc(blocklength*count);
2515     for (i=0; i<count;i++)blocklens[i]=blocklength;
2516     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2517     xbt_free(blocklens);
2518   }
2519   return retval;
2520 }
2521
2522
2523 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2524   int retval = 0;
2525
2526   if (old_type == MPI_DATATYPE_NULL) {
2527     retval = MPI_ERR_TYPE;
2528   } else if (count<0){
2529     retval = MPI_ERR_COUNT;
2530   } else {
2531     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2532   }
2533   return retval;
2534 }
2535
2536 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2537   return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2538 }
2539
2540 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2541   int retval,i;
2542
2543   if (old_type == MPI_DATATYPE_NULL) {
2544     retval = MPI_ERR_TYPE;
2545   } else if (count<0){
2546     retval = MPI_ERR_COUNT;
2547   } else {
2548     int* blocklens=(int*)xbt_malloc(blocklength*count);
2549     for (i=0; i<count;i++)blocklens[i]=blocklength;
2550     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2551     xbt_free(blocklens);
2552   }
2553   return retval;
2554 }
2555
2556
2557 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2558   int retval = 0;
2559
2560   if (count<0){
2561     retval = MPI_ERR_COUNT;
2562   } else {
2563     retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2564   }
2565   return retval;
2566 }
2567
2568 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2569   return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2570 }
2571
2572
2573 int PMPI_Error_class(int errorcode, int* errorclass) {
2574   // assume smpi uses only standard mpi error codes
2575   *errorclass=errorcode;
2576   return MPI_SUCCESS;
2577 }
2578
2579
2580 int PMPI_Initialized(int* flag) {
2581    *flag=smpi_process_initialized();
2582    return MPI_SUCCESS;
2583 }
2584
2585 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2586  * will be implemented, not only should we check if the topology is NULL, but
2587  * we should check if it is the good topology type (so we have to add a
2588  *  MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2589
2590 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2591   int retval = 0;
2592   if (comm_old == MPI_COMM_NULL){
2593     retval =  MPI_ERR_COMM;
2594   } else if (ndims < 0 ||
2595            (ndims > 0 && (dims == NULL || 
2596                           periodic == NULL)) ||
2597            comm_cart == NULL) {
2598     retval = MPI_ERR_ARG;
2599   } else{
2600     retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2601   }
2602   return retval;
2603 }
2604
2605 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2606   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2607     return MPI_ERR_TOPOLOGY;
2608   }
2609   if (coords == NULL) {
2610     return MPI_ERR_ARG;
2611   }
2612   return smpi_mpi_cart_rank(comm, coords, rank);
2613 }
2614
2615 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2616   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2617     return MPI_ERR_TOPOLOGY;
2618   }
2619   if (source == NULL || dest == NULL || direction < 0 ) {
2620     return MPI_ERR_ARG;
2621   }
2622   return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2623 }
2624
2625 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2626   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2627     return MPI_ERR_TOPOLOGY;
2628   }
2629   if (rank < 0 || rank >= smpi_comm_size(comm)) {
2630     return MPI_ERR_RANK;
2631   }
2632   if (maxdims <= 0) {
2633     return MPI_ERR_ARG;
2634   }
2635   if(coords == NULL) {
2636     return MPI_ERR_ARG;
2637   }
2638   return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2639 }
2640
2641 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2642   if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2643     return MPI_ERR_TOPOLOGY;
2644   }
2645   if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2646     return MPI_ERR_ARG;
2647   }
2648   return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2649 }
2650
2651 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2652   if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2653     return MPI_ERR_TOPOLOGY;
2654   }
2655   if (ndims == NULL) {
2656     return MPI_ERR_ARG;
2657   }
2658   return smpi_mpi_cartdim_get(comm, ndims);
2659 }
2660
2661 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2662   if(dims == NULL) {
2663     return MPI_ERR_ARG;
2664   }
2665   if (ndims < 1 || nnodes < 1) {
2666     return MPI_ERR_DIMS;
2667   }
2668
2669   return smpi_mpi_dims_create(nnodes, ndims, dims);
2670 }
2671
2672 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2673   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2674     return MPI_ERR_TOPOLOGY;
2675   }
2676   if (comm_new == NULL) {
2677     return MPI_ERR_ARG;
2678   }
2679   return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2680 }
2681
2682 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2683     if(oldtype == MPI_DATATYPE_NULL) {
2684         return MPI_ERR_TYPE;
2685     }
2686     int blocks[3] = { 1, 1, 1 };
2687     MPI_Aint disps[3] = { lb, 0, lb+extent };
2688     MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2689         
2690     s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks,
2691                                                                 disps,
2692                                                                 3,
2693                                                                 types
2694                                                                 );
2695     smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2696
2697     (*newtype)->flags &= ~DT_FLAG_COMMITED;
2698     return MPI_SUCCESS;
2699 }
2700
2701
2702
2703 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2704   int retval = 0;
2705   smpi_bench_end();
2706   if (comm == MPI_COMM_NULL) {
2707     retval= MPI_ERR_COMM;
2708   }else if ((base == NULL && size != 0)
2709             || disp_unit <= 0 || size < 0 ){
2710     retval= MPI_ERR_OTHER;
2711   }else{
2712     *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2713     retval = MPI_SUCCESS;
2714   }
2715   smpi_bench_begin();
2716   return retval;
2717 }
2718
2719 int PMPI_Win_free( MPI_Win* win){
2720   int retval = 0;
2721   smpi_bench_end();
2722   if (win == NULL || *win == MPI_WIN_NULL) {
2723     retval = MPI_ERR_WIN;
2724   }else{
2725     retval=smpi_mpi_win_free(win);
2726   }
2727   smpi_bench_begin();
2728   return retval;
2729 }
2730
2731 int PMPI_Win_set_name(MPI_Win  win, char * name)
2732 {
2733   int retval = 0;
2734   if (win == MPI_WIN_NULL)  {
2735     retval = MPI_ERR_TYPE;
2736   } else if (name == NULL)  {
2737     retval = MPI_ERR_ARG;
2738   } else {
2739     smpi_mpi_win_set_name(win, name);
2740     retval = MPI_SUCCESS;
2741   }
2742   return retval;
2743 }
2744
2745 int PMPI_Win_get_name(MPI_Win  win, char * name, int* len)
2746 {
2747   int retval = MPI_SUCCESS;
2748
2749   if (win == MPI_WIN_NULL)  {
2750     retval = MPI_ERR_WIN;
2751   } else if (name == NULL)  {
2752     retval = MPI_ERR_ARG;
2753   } else {
2754     smpi_mpi_win_get_name(win, name, len);
2755   }
2756   return retval;
2757 }
2758
2759 int PMPI_Win_get_group(MPI_Win  win, MPI_Group * group){
2760   int retval = MPI_SUCCESS;
2761   if (win == MPI_WIN_NULL)  {
2762     retval = MPI_ERR_WIN;
2763   }else {
2764     smpi_mpi_win_get_group(win, group);
2765   }
2766   return retval;
2767 }
2768
2769
2770 int PMPI_Win_fence( int assert,  MPI_Win win){
2771   int retval = 0;
2772   smpi_bench_end();
2773   if (win == MPI_WIN_NULL) {
2774     retval = MPI_ERR_WIN;
2775   } else {
2776     retval = smpi_mpi_win_fence(assert, win);
2777   }
2778   smpi_bench_begin();
2779   return retval;
2780 }
2781
2782 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2783               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2784   int retval = 0;
2785   smpi_bench_end();
2786   if (win == MPI_WIN_NULL) {
2787     retval = MPI_ERR_WIN;
2788   } else if (target_rank == MPI_PROC_NULL) {
2789     retval = MPI_SUCCESS;
2790   } else if (target_rank <0){
2791     retval = MPI_ERR_RANK;
2792   } else if (target_disp <0){
2793       retval = MPI_ERR_ARG;
2794   } else if (origin_count < 0 || target_count < 0) {
2795     retval = MPI_ERR_COUNT;
2796   } else if (origin_addr==NULL && origin_count > 0){
2797     retval = MPI_ERR_COUNT;
2798   } else if ((!is_datatype_valid(origin_datatype)) ||
2799             (!is_datatype_valid(target_datatype))) {
2800     retval = MPI_ERR_TYPE;
2801   } else {
2802     retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2803   }
2804   smpi_bench_begin();
2805   return retval;
2806 }
2807
2808 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2809               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2810   int retval = 0;
2811   smpi_bench_end();
2812   if (win == MPI_WIN_NULL) {
2813     retval = MPI_ERR_WIN;
2814   } else if (target_rank == MPI_PROC_NULL) {
2815     retval = MPI_SUCCESS;
2816   } else if (target_rank <0){
2817     retval = MPI_ERR_RANK;
2818   } else if (target_disp <0){
2819     retval = MPI_ERR_ARG;
2820   } else if (origin_count < 0 || target_count < 0) {
2821     retval = MPI_ERR_COUNT;
2822   } else if (origin_addr==NULL && origin_count > 0){
2823     retval = MPI_ERR_COUNT;
2824   } else if ((!is_datatype_valid(origin_datatype)) ||
2825             (!is_datatype_valid(target_datatype))) {
2826     retval = MPI_ERR_TYPE;
2827   } else {
2828     retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2829   }
2830   smpi_bench_begin();
2831   return retval;
2832 }
2833
2834
2835 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2836               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2837   int retval = 0;
2838   smpi_bench_end();
2839   if (win == MPI_WIN_NULL) {
2840     retval = MPI_ERR_WIN;
2841   } else if (target_rank == MPI_PROC_NULL) {
2842     retval = MPI_SUCCESS;
2843   } else if (target_rank <0){
2844     retval = MPI_ERR_RANK;
2845   } else if (target_disp <0){
2846     retval = MPI_ERR_ARG;
2847   } else if (origin_count < 0 || target_count < 0) {
2848     retval = MPI_ERR_COUNT;
2849   } else if (origin_addr==NULL && origin_count > 0){
2850     retval = MPI_ERR_COUNT;
2851   } else if ((!is_datatype_valid(origin_datatype)) ||
2852             (!is_datatype_valid(target_datatype))) {
2853     retval = MPI_ERR_TYPE;
2854   } else if (op == MPI_OP_NULL) {
2855     retval = MPI_ERR_OP;
2856   } else {
2857     retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, op, win);
2858   }
2859   smpi_bench_begin();
2860   return retval;
2861 }
2862
2863
2864 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2865   void *ptr = xbt_malloc(size);
2866   if(!ptr)
2867     return MPI_ERR_NO_MEM;
2868   else {
2869     *(void **)baseptr = ptr;
2870     return MPI_SUCCESS;
2871   }
2872 }
2873
2874 int PMPI_Free_mem(void *baseptr){
2875   xbt_free(baseptr);
2876   return MPI_SUCCESS;
2877 }
2878
2879 int PMPI_Type_set_name(MPI_Datatype  datatype, char * name)
2880 {
2881   int retval = 0;
2882   if (datatype == MPI_DATATYPE_NULL)  {
2883     retval = MPI_ERR_TYPE;
2884   } else if (name == NULL)  {
2885     retval = MPI_ERR_ARG;
2886   } else {
2887     smpi_datatype_set_name(datatype, name);
2888     retval = MPI_SUCCESS;
2889   }
2890   return retval;
2891 }
2892
2893 int PMPI_Type_get_name(MPI_Datatype  datatype, char * name, int* len)
2894 {
2895   int retval = 0;
2896
2897   if (datatype == MPI_DATATYPE_NULL)  {
2898     retval = MPI_ERR_TYPE;
2899   } else if (name == NULL)  {
2900     retval = MPI_ERR_ARG;
2901   } else {
2902     smpi_datatype_get_name(datatype, name, len);
2903     retval = MPI_SUCCESS;
2904   }
2905   return retval;
2906 }
2907
2908
2909 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2910   return smpi_type_f2c(datatype);
2911 }
2912
2913 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2914   return smpi_type_c2f( datatype);
2915 }
2916
2917 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2918   return smpi_group_f2c( group);
2919 }
2920
2921 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2922   return smpi_group_c2f(group);
2923 }
2924
2925 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2926   return smpi_request_f2c(request);
2927 }
2928
2929 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2930   return smpi_request_c2f(request);
2931 }
2932
2933 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2934   return smpi_win_f2c(win);
2935 }
2936
2937 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2938   return smpi_win_c2f(win);
2939 }
2940
2941 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2942   return smpi_op_f2c(op);
2943 }
2944
2945 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2946   return smpi_op_c2f(op);
2947 }
2948
2949 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2950   return smpi_comm_f2c(comm);
2951 }
2952
2953 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2954   return smpi_comm_c2f(comm);
2955 }
2956
2957 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2958   return smpi_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2959 }
2960
2961 int PMPI_Keyval_free(int* keyval) {
2962   return smpi_keyval_free(keyval);
2963 }
2964
2965 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2966   if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
2967        ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2968        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2969     return MPI_ERR_ARG;
2970   else if (comm==MPI_COMM_NULL)
2971     return MPI_ERR_COMM;
2972   else
2973     return smpi_attr_delete(comm, keyval);
2974 }
2975
2976 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2977   if (comm==MPI_COMM_NULL){
2978     *flag=0;
2979     return MPI_ERR_COMM;
2980   } else if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
2981        ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2982        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE){
2983     *flag=1;
2984     //FIXME : not ideal and leaky, but should not be called too much
2985     int* res = xbt_new(int, 1);
2986     *res=keyval;
2987     *(int**)attr_value=res;
2988     return MPI_SUCCESS;
2989   } else
2990   return smpi_attr_get(comm, keyval, attr_value, flag);
2991 }
2992
2993 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2994   if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
2995        ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2996        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2997     return MPI_ERR_ARG;
2998   else if (comm==MPI_COMM_NULL)
2999     return MPI_ERR_COMM;
3000   else
3001   return smpi_attr_put(comm, keyval, attr_value);
3002 }
3003
3004
3005 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3006 {
3007   return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3008 }
3009
3010 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3011 {
3012   return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3013 }
3014
3015 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3016 {
3017   return PMPI_Attr_delete(comm, comm_keyval);
3018 }
3019
3020 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3021 {
3022   return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3023 }
3024
3025 int PMPI_Comm_free_keyval(int* keyval) {
3026   return PMPI_Keyval_free(keyval);
3027 }
3028
3029 /* The following calls are not yet implemented and will fail at runtime. */
3030 /* Once implemented, please move them above this notice. */
3031
3032 #define NOT_YET_IMPLEMENTED {                                           \
3033     XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
3034     return MPI_SUCCESS;                                                 \
3035   }
3036
3037
3038 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3039   NOT_YET_IMPLEMENTED
3040 }
3041
3042 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3043   NOT_YET_IMPLEMENTED
3044 }
3045
3046 MPI_Errhandler PMPI_Errhandler_f2c(MPI_Fint errhandler){
3047   NOT_YET_IMPLEMENTED
3048 }
3049
3050 MPI_Fint PMPI_Errhandler_c2f(MPI_Errhandler errhandler){
3051   NOT_YET_IMPLEMENTED
3052 }
3053
3054 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3055   NOT_YET_IMPLEMENTED
3056 }
3057
3058
3059 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
3060   NOT_YET_IMPLEMENTED
3061 }
3062
3063
3064 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
3065   NOT_YET_IMPLEMENTED
3066 }
3067
3068 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
3069   NOT_YET_IMPLEMENTED
3070 }
3071
3072 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
3073   NOT_YET_IMPLEMENTED
3074 }
3075
3076 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
3077   NOT_YET_IMPLEMENTED
3078 }
3079
3080 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
3081   NOT_YET_IMPLEMENTED
3082 }
3083
3084 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
3085   NOT_YET_IMPLEMENTED
3086 }
3087
3088 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
3089   NOT_YET_IMPLEMENTED
3090 }
3091
3092 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
3093   NOT_YET_IMPLEMENTED
3094 }
3095
3096 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
3097   NOT_YET_IMPLEMENTED
3098 }
3099
3100 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
3101   NOT_YET_IMPLEMENTED
3102 }
3103
3104 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
3105   NOT_YET_IMPLEMENTED
3106 }
3107
3108 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
3109   NOT_YET_IMPLEMENTED
3110 }
3111
3112 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
3113   NOT_YET_IMPLEMENTED
3114 }
3115
3116 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
3117   NOT_YET_IMPLEMENTED
3118 }
3119
3120 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
3121   NOT_YET_IMPLEMENTED
3122 }
3123
3124 int PMPI_Cancel(MPI_Request* request) {
3125   NOT_YET_IMPLEMENTED
3126 }
3127
3128 int PMPI_Buffer_attach(void* buffer, int size) {
3129   NOT_YET_IMPLEMENTED
3130 }
3131
3132 int PMPI_Buffer_detach(void* buffer, int* size) {
3133   NOT_YET_IMPLEMENTED
3134 }
3135
3136 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
3137   NOT_YET_IMPLEMENTED
3138 }
3139
3140 int PMPI_Pcontrol(const int level )
3141 {
3142   NOT_YET_IMPLEMENTED
3143 }
3144
3145 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3146   NOT_YET_IMPLEMENTED
3147 }
3148
3149 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3150 {
3151   NOT_YET_IMPLEMENTED
3152 }
3153
3154 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3155 {
3156   NOT_YET_IMPLEMENTED
3157 }
3158
3159 int PMPI_Type_delete_attr (MPI_Datatype type, int comm_keyval)
3160 {
3161   NOT_YET_IMPLEMENTED
3162 }
3163
3164 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3165 {
3166   NOT_YET_IMPLEMENTED
3167 }
3168
3169 int PMPI_Type_free_keyval(int* keyval) {
3170   NOT_YET_IMPLEMENTED
3171 }
3172
3173 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
3174   NOT_YET_IMPLEMENTED
3175 }
3176
3177 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3178   NOT_YET_IMPLEMENTED
3179 }
3180
3181 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3182   NOT_YET_IMPLEMENTED
3183 }
3184
3185 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3186   NOT_YET_IMPLEMENTED
3187 }
3188
3189 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3190   NOT_YET_IMPLEMENTED
3191 }
3192
3193 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3194   NOT_YET_IMPLEMENTED
3195 }
3196
3197 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3198   NOT_YET_IMPLEMENTED
3199 }
3200
3201 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3202   NOT_YET_IMPLEMENTED
3203 }
3204
3205 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3206   NOT_YET_IMPLEMENTED
3207 }
3208
3209 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3210   NOT_YET_IMPLEMENTED
3211 }
3212
3213 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3214   NOT_YET_IMPLEMENTED
3215 }
3216
3217 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3218   NOT_YET_IMPLEMENTED
3219 }
3220
3221 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3222   NOT_YET_IMPLEMENTED
3223 }
3224
3225 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
3226   NOT_YET_IMPLEMENTED
3227 }
3228
3229 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
3230   NOT_YET_IMPLEMENTED
3231 }
3232
3233 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3234   NOT_YET_IMPLEMENTED
3235 }
3236
3237 int PMPI_Info_create( MPI_Info *info){
3238   NOT_YET_IMPLEMENTED
3239 }
3240
3241 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3242   NOT_YET_IMPLEMENTED
3243 }
3244
3245 int PMPI_Info_free( MPI_Info *info){
3246   NOT_YET_IMPLEMENTED
3247 }
3248
3249 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
3250                             int *num_addresses, int *num_datatypes, int *combiner){
3251   NOT_YET_IMPLEMENTED
3252 }
3253
3254 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
3255                            int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
3256                            MPI_Datatype* array_of_datatypes){
3257   NOT_YET_IMPLEMENTED
3258 }
3259
3260 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
3261                             int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
3262                             int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
3263   NOT_YET_IMPLEMENTED
3264 }
3265
3266 int PMPI_Type_create_subarray(int ndims,int *array_of_sizes, int *array_of_subsizes, int *array_of_starts, int order, MPI_Datatype oldtype, MPI_Datatype *newtype){
3267   NOT_YET_IMPLEMENTED
3268 }
3269
3270 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3271   NOT_YET_IMPLEMENTED
3272 }
3273
3274 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3275                     void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
3276                     MPI_Comm comm){
3277   NOT_YET_IMPLEMENTED
3278 }
3279
3280 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3281   NOT_YET_IMPLEMENTED
3282 }
3283
3284 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3285   NOT_YET_IMPLEMENTED
3286 }
3287
3288 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3289   NOT_YET_IMPLEMENTED
3290 }
3291
3292 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3293   NOT_YET_IMPLEMENTED
3294 }
3295
3296 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3297   NOT_YET_IMPLEMENTED
3298 }
3299
3300 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3301   NOT_YET_IMPLEMENTED
3302 }
3303
3304 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3305   NOT_YET_IMPLEMENTED
3306 }
3307
3308 int PMPI_Add_error_class( int *errorclass){
3309   NOT_YET_IMPLEMENTED
3310 }
3311
3312 int PMPI_Add_error_code(  int errorclass, int *errorcode){
3313   NOT_YET_IMPLEMENTED
3314 }
3315
3316 int PMPI_Add_error_string( int errorcode, char *string){
3317   NOT_YET_IMPLEMENTED
3318 }
3319
3320 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3321   NOT_YET_IMPLEMENTED
3322 }
3323
3324 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3325   NOT_YET_IMPLEMENTED
3326 }
3327
3328 int PMPI_Info_delete(MPI_Info info, char *key){
3329   NOT_YET_IMPLEMENTED
3330 }
3331
3332 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3333   NOT_YET_IMPLEMENTED
3334 }
3335
3336 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3337   NOT_YET_IMPLEMENTED
3338 }
3339
3340 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3341   NOT_YET_IMPLEMENTED
3342 }
3343
3344 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3345   NOT_YET_IMPLEMENTED
3346 }
3347
3348 int PMPI_Grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request){
3349   NOT_YET_IMPLEMENTED
3350 }
3351
3352 int PMPI_Grequest_complete( MPI_Request request){
3353   NOT_YET_IMPLEMENTED
3354 }
3355
3356 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3357   NOT_YET_IMPLEMENTED
3358 }
3359
3360 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3361   NOT_YET_IMPLEMENTED
3362 }
3363
3364 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3365   NOT_YET_IMPLEMENTED
3366 }
3367
3368 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3369   NOT_YET_IMPLEMENTED
3370 }
3371
3372 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3373   NOT_YET_IMPLEMENTED
3374 }
3375
3376 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3377   NOT_YET_IMPLEMENTED
3378 }
3379
3380 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3381   NOT_YET_IMPLEMENTED
3382 }
3383
3384 int PMPI_Open_port( MPI_Info info, char *port_name){
3385   NOT_YET_IMPLEMENTED
3386 }
3387
3388 int PMPI_Close_port(char *port_name){
3389   NOT_YET_IMPLEMENTED
3390 }
3391
3392 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3393   NOT_YET_IMPLEMENTED
3394 }
3395
3396 int PMPI_Comm_spawn( char *command, char **argv, int maxprocs, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3397   NOT_YET_IMPLEMENTED
3398 }
3399
3400 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3401                               int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3402                               MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3403   NOT_YET_IMPLEMENTED
3404 }
3405
3406 int PMPI_Comm_get_parent( MPI_Comm *parent){
3407   NOT_YET_IMPLEMENTED
3408 }
3409
3410 int PMPI_Win_complete(MPI_Win win){
3411   NOT_YET_IMPLEMENTED
3412 }
3413
3414 int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win) {
3415   NOT_YET_IMPLEMENTED
3416 }
3417
3418 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
3419   NOT_YET_IMPLEMENTED
3420 }
3421
3422 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
3423   NOT_YET_IMPLEMENTED
3424 }
3425
3426 int PMPI_Win_test(MPI_Win win, int *flag){
3427   NOT_YET_IMPLEMENTED
3428 }
3429
3430 int PMPI_Win_unlock(int rank, MPI_Win win){
3431   NOT_YET_IMPLEMENTED
3432 }
3433
3434 int PMPI_Win_wait(MPI_Win win){
3435   NOT_YET_IMPLEMENTED
3436 }