Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[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     *newcomm = smpi_comm_new(smpi_comm_group(comm), smpi_comm_topo(comm));
777     retval = MPI_SUCCESS;
778   }
779   return retval;
780 }
781
782 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
783 {
784   int retval = 0;
785
786   if (comm == MPI_COMM_NULL) {
787     retval = MPI_ERR_COMM;
788   } else if (group == MPI_GROUP_NULL) {
789     retval = MPI_ERR_GROUP;
790   } else if (newcomm == NULL) {
791     retval = MPI_ERR_ARG;
792   } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
793     *newcomm= MPI_COMM_NULL;
794     retval = MPI_SUCCESS;
795   }else{
796
797     *newcomm = smpi_comm_new(group, NULL);
798     retval = MPI_SUCCESS;
799   }
800   return retval;
801 }
802
803 int PMPI_Comm_free(MPI_Comm * comm)
804 {
805   int retval = 0;
806
807   if (comm == NULL) {
808     retval = MPI_ERR_ARG;
809   } else if (*comm == MPI_COMM_NULL) {
810     retval = MPI_ERR_COMM;
811   } else {
812     smpi_comm_destroy(*comm);
813     *comm = MPI_COMM_NULL;
814     retval = MPI_SUCCESS;
815   }
816   return retval;
817 }
818
819 int PMPI_Comm_disconnect(MPI_Comm * comm)
820 {
821   /* TODO: wait until all communication in comm are done */
822   int retval = 0;
823
824   if (comm == NULL) {
825     retval = MPI_ERR_ARG;
826   } else if (*comm == MPI_COMM_NULL) {
827     retval = MPI_ERR_COMM;
828   } else {
829     smpi_comm_destroy(*comm);
830     *comm = MPI_COMM_NULL;
831     retval = MPI_SUCCESS;
832   }
833   return retval;
834 }
835
836 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
837 {
838   int retval = 0;
839   smpi_bench_end();
840
841   if (comm_out == NULL) {
842     retval = MPI_ERR_ARG;
843   } else if (comm == MPI_COMM_NULL) {
844     retval = MPI_ERR_COMM;
845   } else {
846     *comm_out = smpi_comm_split(comm, color, key);
847     retval = MPI_SUCCESS;
848   }
849   smpi_bench_begin();
850
851   return retval;
852 }
853
854 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
855                    int tag, MPI_Comm comm, MPI_Request * request)
856 {
857   int retval = 0;
858
859   smpi_bench_end();
860   if (request == NULL) {
861       retval = MPI_ERR_ARG;
862   } else if (comm == MPI_COMM_NULL) {
863       retval = MPI_ERR_COMM;
864   } else if (!is_datatype_valid(datatype)) {
865       retval = MPI_ERR_TYPE;
866   } else if (dst == MPI_PROC_NULL) {
867       retval = MPI_SUCCESS;
868   } else {
869       *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
870       retval = MPI_SUCCESS;
871   }
872   smpi_bench_begin();
873   if (retval != MPI_SUCCESS && request)
874     *request = MPI_REQUEST_NULL;
875   return retval;
876 }
877
878 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
879                    int tag, MPI_Comm comm, MPI_Request * request)
880 {
881   int retval = 0;
882
883   smpi_bench_end();
884   if (request == NULL) {
885     retval = MPI_ERR_ARG;
886   } else if (comm == MPI_COMM_NULL) {
887     retval = MPI_ERR_COMM;
888   } else if (!is_datatype_valid(datatype)) {
889       retval = MPI_ERR_TYPE;
890   } else if (src == MPI_PROC_NULL) {
891     retval = MPI_SUCCESS;
892   } else {
893     *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
894     retval = MPI_SUCCESS;
895   }
896   smpi_bench_begin();
897   if (retval != MPI_SUCCESS && request)
898     *request = MPI_REQUEST_NULL;
899   return retval;
900 }
901
902 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
903                     int dst, int tag, MPI_Comm comm, MPI_Request* request)
904 {
905   int retval = 0;
906
907   smpi_bench_end();
908   if (request == NULL) {
909     retval = MPI_ERR_ARG;
910   } else if (comm == MPI_COMM_NULL) {
911     retval = MPI_ERR_COMM;
912   } else if (!is_datatype_valid(datatype)) {
913       retval = MPI_ERR_TYPE;
914   } else if (dst == MPI_PROC_NULL) {
915     retval = MPI_SUCCESS;
916   } else {
917     *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
918     retval = MPI_SUCCESS;
919   }
920   smpi_bench_begin();
921   if (retval != MPI_SUCCESS && request)
922     *request = MPI_REQUEST_NULL;
923   return retval;
924 }
925
926 int PMPI_Start(MPI_Request * request)
927 {
928   int retval = 0;
929
930   smpi_bench_end();
931   if (request == NULL || *request == MPI_REQUEST_NULL) {
932     retval = MPI_ERR_REQUEST;
933   } else {
934     smpi_mpi_start(*request);
935     retval = MPI_SUCCESS;
936   }
937   smpi_bench_begin();
938   return retval;
939 }
940
941 int PMPI_Startall(int count, MPI_Request * requests)
942 {
943   int retval;
944   int i = 0;
945   smpi_bench_end();
946   if (requests == NULL) {
947     retval = MPI_ERR_ARG;
948   } else {
949     retval = MPI_SUCCESS;
950     for (i = 0 ;  i < count ; i++) {
951       if(requests[i] == MPI_REQUEST_NULL) {
952         retval = MPI_ERR_REQUEST;
953       }
954     }
955     if(retval != MPI_ERR_REQUEST) {
956       smpi_mpi_startall(count, requests);
957     }
958   }
959   smpi_bench_begin();
960   return retval;
961 }
962
963 int PMPI_Request_free(MPI_Request * request)
964 {
965   int retval = 0;
966
967   smpi_bench_end();
968   if (*request == MPI_REQUEST_NULL) {
969     retval = MPI_ERR_ARG;
970   } else {
971     smpi_mpi_request_free(request);
972     retval = MPI_SUCCESS;
973   }
974   smpi_bench_begin();
975   return retval;
976 }
977
978 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
979                int tag, MPI_Comm comm, MPI_Request * request)
980 {
981   int retval = 0;
982
983   smpi_bench_end();
984
985   if (request == NULL) {
986     retval = MPI_ERR_ARG;
987   } else if (comm == MPI_COMM_NULL) {
988     retval = MPI_ERR_COMM;
989   } else if (src == MPI_PROC_NULL) {
990     *request = MPI_REQUEST_NULL;
991     retval = MPI_SUCCESS;
992   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
993     retval = MPI_ERR_RANK;
994   } else if (count < 0) {
995     retval = MPI_ERR_COUNT;
996   } else if (buf==NULL && count > 0) {
997     retval = MPI_ERR_COUNT;
998   } else if (!is_datatype_valid(datatype)) {
999       retval = MPI_ERR_TYPE;
1000   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1001     retval = MPI_ERR_TAG;
1002   } else {
1003
1004 #ifdef HAVE_TRACING
1005     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1006     int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1007
1008     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1009     extra->type = TRACING_IRECV;
1010     extra->send_size = count;
1011     extra->src = src_traced;
1012     extra->dst = rank;
1013     extra->datatype1 = encode_datatype(datatype);
1014     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1015 #endif
1016
1017     *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1018     retval = MPI_SUCCESS;
1019
1020 #ifdef HAVE_TRACING
1021     TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1022     (*request)->recv = 1;
1023 #endif
1024   }
1025
1026   smpi_bench_begin();
1027   if (retval != MPI_SUCCESS && request)
1028     *request = MPI_REQUEST_NULL;
1029   return retval;
1030 }
1031
1032
1033 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1034                int tag, MPI_Comm comm, MPI_Request * request)
1035 {
1036   int retval = 0;
1037
1038   smpi_bench_end();
1039   if (request == NULL) {
1040     retval = MPI_ERR_ARG;
1041   } else if (comm == MPI_COMM_NULL) {
1042     retval = MPI_ERR_COMM;
1043   } else if (dst == MPI_PROC_NULL) {
1044     *request = MPI_REQUEST_NULL;
1045     retval = MPI_SUCCESS;
1046   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1047     retval = MPI_ERR_RANK;
1048   } else if (count < 0) {
1049     retval = MPI_ERR_COUNT;
1050   } else if (buf==NULL && count > 0) {
1051     retval = MPI_ERR_COUNT;
1052   } else if (!is_datatype_valid(datatype)) {
1053       retval = MPI_ERR_TYPE;
1054   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1055     retval = MPI_ERR_TAG;
1056   } else {
1057
1058 #ifdef HAVE_TRACING
1059     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1060     int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1061
1062     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1063     extra->type = TRACING_ISEND;
1064     extra->send_size = count;
1065     extra->src = rank;
1066     extra->dst = dst_traced;
1067     extra->datatype1 = encode_datatype(datatype);
1068     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1069     TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1070 #endif
1071
1072     *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1073     retval = MPI_SUCCESS;
1074
1075 #ifdef HAVE_TRACING
1076     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1077     (*request)->send = 1;
1078 #endif
1079   }
1080
1081   smpi_bench_begin();
1082   if (retval != MPI_SUCCESS && request)
1083     *request = MPI_REQUEST_NULL;
1084   return retval;
1085 }
1086
1087 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1088                 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1089 {
1090   int retval = 0;
1091
1092   smpi_bench_end();
1093   if (request == NULL) {
1094     retval = MPI_ERR_ARG;
1095   } else if (comm == MPI_COMM_NULL) {
1096     retval = MPI_ERR_COMM;
1097   } else if (dst == MPI_PROC_NULL) {
1098     *request = MPI_REQUEST_NULL;
1099     retval = MPI_SUCCESS;
1100   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1101     retval = MPI_ERR_RANK;
1102   } else if (count < 0) {
1103     retval = MPI_ERR_COUNT;
1104   } else if (buf==NULL && count > 0) {
1105     retval = MPI_ERR_COUNT;
1106   } else if (!is_datatype_valid(datatype)) {
1107       retval = MPI_ERR_TYPE;
1108   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1109     retval = MPI_ERR_TAG;
1110   } else {
1111
1112 #ifdef HAVE_TRACING
1113     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1114     int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1115     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1116     extra->type = TRACING_ISSEND;
1117     extra->send_size = count;
1118     extra->src = rank;
1119     extra->dst = dst_traced;
1120     extra->datatype1 = encode_datatype(datatype);
1121     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1122     TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1123 #endif
1124
1125     *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1126     retval = MPI_SUCCESS;
1127
1128 #ifdef HAVE_TRACING
1129     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1130     (*request)->send = 1;
1131 #endif
1132   }
1133
1134   smpi_bench_begin();
1135   if (retval != MPI_SUCCESS && request)
1136     *request = MPI_REQUEST_NULL;
1137   return retval;
1138 }
1139
1140 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1141              MPI_Comm comm, MPI_Status * status)
1142 {
1143   int retval = 0;
1144
1145   smpi_bench_end();
1146   if (comm == MPI_COMM_NULL) {
1147     retval = MPI_ERR_COMM;
1148   } else if (src == MPI_PROC_NULL) {
1149     smpi_empty_status(status);
1150     status->MPI_SOURCE = MPI_PROC_NULL;
1151     retval = MPI_SUCCESS;
1152   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1153     retval = MPI_ERR_RANK;
1154   } else if (count < 0) {
1155     retval = MPI_ERR_COUNT;
1156   } else if (buf==NULL && count > 0) {
1157     retval = MPI_ERR_COUNT;
1158   } else if (!is_datatype_valid(datatype)) {
1159       retval = MPI_ERR_TYPE;
1160   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1161     retval = MPI_ERR_TAG;
1162   } else {
1163 #ifdef HAVE_TRACING
1164   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1165   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1166   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1167   extra->type = TRACING_RECV;
1168   extra->send_size = count;
1169   extra->src = src_traced;
1170   extra->dst = rank;
1171   extra->datatype1 = encode_datatype(datatype);
1172   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1173 #endif
1174
1175     smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1176     retval = MPI_SUCCESS;
1177
1178 #ifdef HAVE_TRACING
1179   //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1180   if(status!=MPI_STATUS_IGNORE){
1181     src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1182     TRACE_smpi_recv(rank, src_traced, rank);
1183   }
1184   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1185 #endif
1186   }
1187
1188   smpi_bench_begin();
1189   return retval;
1190 }
1191
1192 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1193              MPI_Comm comm)
1194 {
1195   int retval = 0;
1196
1197   smpi_bench_end();
1198
1199   if (comm == MPI_COMM_NULL) {
1200     retval = MPI_ERR_COMM;
1201   } else if (dst == MPI_PROC_NULL) {
1202     retval = MPI_SUCCESS;
1203   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1204     retval = MPI_ERR_RANK;
1205   } else if (count < 0) {
1206     retval = MPI_ERR_COUNT;
1207   } else if (buf==NULL && count > 0) {
1208     retval = MPI_ERR_COUNT;
1209   } else if (!is_datatype_valid(datatype)) {
1210       retval = MPI_ERR_TYPE;
1211   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1212     retval = MPI_ERR_TAG;
1213   } else {
1214
1215 #ifdef HAVE_TRACING
1216   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1217   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1218   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1219   extra->type = TRACING_SEND;
1220   extra->send_size = count;
1221   extra->src = rank;
1222   extra->dst = dst_traced;
1223   extra->datatype1 = encode_datatype(datatype);
1224   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1225   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1226 #endif
1227
1228     smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1229     retval = MPI_SUCCESS;
1230
1231 #ifdef HAVE_TRACING
1232   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1233 #endif
1234   }
1235
1236   smpi_bench_begin();
1237   return retval;
1238 }
1239
1240
1241
1242 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1243   int retval = 0;
1244
1245    smpi_bench_end();
1246
1247    if (comm == MPI_COMM_NULL) {
1248      retval = MPI_ERR_COMM;
1249    } else if (dst == MPI_PROC_NULL) {
1250      retval = MPI_SUCCESS;
1251    } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1252      retval = MPI_ERR_RANK;
1253    } else if (count < 0) {
1254      retval = MPI_ERR_COUNT;
1255    } else if (buf==NULL && count > 0) {
1256      retval = MPI_ERR_COUNT;
1257    } else if (!is_datatype_valid(datatype)){
1258      retval = MPI_ERR_TYPE;
1259    } else if(tag<0 && tag !=  MPI_ANY_TAG){
1260      retval = MPI_ERR_TAG;
1261    } else {
1262
1263  #ifdef HAVE_TRACING
1264    int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1265    int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1266    instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1267    extra->type = TRACING_SSEND;
1268    extra->send_size = count;
1269    extra->src = rank;
1270    extra->dst = dst_traced;
1271    extra->datatype1 = encode_datatype(datatype);
1272    TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1273  #endif
1274
1275      smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1276      retval = MPI_SUCCESS;
1277
1278  #ifdef HAVE_TRACING
1279    TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1280  #endif
1281    }
1282
1283    smpi_bench_begin();
1284    return retval;}
1285
1286
1287 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1288                  int dst, int sendtag, void *recvbuf, int recvcount,
1289                  MPI_Datatype recvtype, int src, int recvtag,
1290                  MPI_Comm comm, MPI_Status * status)
1291 {
1292   int retval = 0;
1293
1294   smpi_bench_end();
1295
1296   if (comm == MPI_COMM_NULL) {
1297     retval = MPI_ERR_COMM;
1298   } else if (!is_datatype_valid(sendtype)
1299              || !is_datatype_valid(recvtype)) {
1300     retval = MPI_ERR_TYPE;
1301   } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1302       smpi_empty_status(status);
1303       status->MPI_SOURCE = MPI_PROC_NULL;
1304       retval = MPI_SUCCESS;
1305   }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1306       (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1307     retval = MPI_ERR_RANK;
1308   } else if (sendcount < 0 || recvcount<0) {
1309       retval = MPI_ERR_COUNT;
1310   } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1311     retval = MPI_ERR_COUNT;
1312   } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1313     retval = MPI_ERR_TAG;
1314   } else {
1315
1316 #ifdef HAVE_TRACING
1317   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1318   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1319   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1320   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1321   extra->type = TRACING_SENDRECV;
1322   extra->send_size = sendcount;
1323   extra->recv_size = recvcount;
1324   extra->src = src_traced;
1325   extra->dst = dst_traced;
1326   extra->datatype1 = encode_datatype(sendtype);
1327   extra->datatype2 = encode_datatype(recvtype);
1328
1329   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1330   TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1331 #endif
1332
1333
1334     smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1335                       recvcount, recvtype, src, recvtag, comm, status);
1336     retval = MPI_SUCCESS;
1337
1338 #ifdef HAVE_TRACING
1339   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1340   TRACE_smpi_recv(rank, src_traced, rank);
1341 #endif
1342
1343   }
1344
1345   smpi_bench_begin();
1346   return retval;
1347 }
1348
1349 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1350                          int dst, int sendtag, int src, int recvtag,
1351                          MPI_Comm comm, MPI_Status * status)
1352 {
1353   //TODO: suboptimal implementation
1354   void *recvbuf;
1355   int retval = 0;
1356   if (!is_datatype_valid(datatype)) {
1357       retval = MPI_ERR_TYPE;
1358   } else if (count < 0) {
1359       retval = MPI_ERR_COUNT;
1360   } else {
1361     int size = smpi_datatype_get_extent(datatype) * count;
1362     recvbuf = xbt_new0(char, size);
1363     retval =
1364         MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1365                      datatype, src, recvtag, comm, status);
1366     if(retval==MPI_SUCCESS){
1367         smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1368     }
1369     xbt_free(recvbuf);
1370
1371   }
1372   return retval;
1373 }
1374
1375 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1376 {
1377   int retval = 0;
1378   smpi_bench_end();
1379   if (request == NULL || flag == NULL) {
1380     retval = MPI_ERR_ARG;
1381   } else if (*request == MPI_REQUEST_NULL) {
1382     *flag= TRUE;
1383     smpi_empty_status(status);
1384     retval = MPI_ERR_REQUEST;
1385   } else {
1386 #ifdef HAVE_TRACING
1387     int rank = request && (*request)->comm != MPI_COMM_NULL
1388       ? smpi_process_index()
1389       : -1;
1390
1391     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1392     extra->type = TRACING_TEST;
1393     TRACE_smpi_testing_in(rank, extra);
1394 #endif
1395     *flag = smpi_mpi_test(request, status);
1396 #ifdef HAVE_TRACING
1397     TRACE_smpi_testing_out(rank);
1398 #endif
1399     retval = MPI_SUCCESS;
1400   }
1401   smpi_bench_begin();
1402   return retval;
1403 }
1404
1405 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1406                 MPI_Status * status)
1407 {
1408   int retval = 0;
1409
1410   smpi_bench_end();
1411   if (index == NULL || flag == NULL) {
1412     retval = MPI_ERR_ARG;
1413   } else {
1414     *flag = smpi_mpi_testany(count, requests, index, status);
1415     retval = MPI_SUCCESS;
1416   }
1417   smpi_bench_begin();
1418   return retval;
1419 }
1420
1421 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1422 {
1423   int retval = 0;
1424
1425   smpi_bench_end();
1426   if (flag == NULL) {
1427     retval = MPI_ERR_ARG;
1428   } else {
1429     *flag = smpi_mpi_testall(count, requests, statuses);
1430     retval = MPI_SUCCESS;
1431   }
1432   smpi_bench_begin();
1433   return retval;
1434 }
1435
1436 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1437   int retval = 0;
1438   smpi_bench_end();
1439
1440   if (status == NULL) {
1441     retval = MPI_ERR_ARG;
1442   } else if (comm == MPI_COMM_NULL) {
1443     retval = MPI_ERR_COMM;
1444   } else if (source == MPI_PROC_NULL) {
1445     smpi_empty_status(status);
1446     status->MPI_SOURCE = MPI_PROC_NULL;
1447     retval = MPI_SUCCESS;
1448   } else {
1449     smpi_mpi_probe(source, tag, comm, status);
1450     retval = MPI_SUCCESS;
1451   }
1452   smpi_bench_begin();
1453   return retval;
1454 }
1455
1456
1457 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1458   int retval = 0;
1459   smpi_bench_end();
1460
1461   if (flag == NULL) {
1462     retval = MPI_ERR_ARG;
1463   } else if (status == NULL) {
1464     retval = MPI_ERR_ARG;
1465   } else if (comm == MPI_COMM_NULL) {
1466     retval = MPI_ERR_COMM;
1467   } else if (source == MPI_PROC_NULL) {
1468     *flag=TRUE;
1469     smpi_empty_status(status);
1470     status->MPI_SOURCE = MPI_PROC_NULL;
1471     retval = MPI_SUCCESS;
1472   } else {
1473     smpi_mpi_iprobe(source, tag, comm, flag, status);
1474     retval = MPI_SUCCESS;
1475   }
1476   smpi_bench_begin();
1477   return retval;
1478 }
1479
1480 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1481 {
1482   int retval = 0;
1483
1484   smpi_bench_end();
1485
1486   smpi_empty_status(status);
1487
1488   if (request == NULL) {
1489     retval = MPI_ERR_ARG;
1490   } else if (*request == MPI_REQUEST_NULL) {
1491     retval = MPI_ERR_REQUEST;
1492   } else {
1493
1494 #ifdef HAVE_TRACING
1495     int rank = request && (*request)->comm != MPI_COMM_NULL
1496       ? smpi_process_index()
1497       : -1;
1498
1499     int src_traced = (*request)->src;
1500     int dst_traced = (*request)->dst;
1501     MPI_Comm comm = (*request)->comm;
1502     int is_wait_for_receive = (*request)->recv;
1503     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1504     extra->type = TRACING_WAIT;
1505     TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1506 #endif
1507
1508     smpi_mpi_wait(request, status);
1509     retval = MPI_SUCCESS;
1510
1511 #ifdef HAVE_TRACING
1512     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1513     TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1514     if (is_wait_for_receive) {
1515       if(src_traced==MPI_ANY_SOURCE)
1516         src_traced = (status!=MPI_STATUS_IGNORE) ?
1517           smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1518           src_traced;
1519       TRACE_smpi_recv(rank, src_traced, dst_traced);
1520     }
1521 #endif
1522
1523   }
1524
1525   smpi_bench_begin();
1526   return retval;
1527 }
1528
1529 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1530 {
1531   if (index == NULL)
1532     return MPI_ERR_ARG;
1533
1534   smpi_bench_end();
1535 #ifdef HAVE_TRACING
1536   //save requests information for tracing
1537   int i;
1538   int *srcs = xbt_new0(int, count);
1539   int *dsts = xbt_new0(int, count);
1540   int *recvs = xbt_new0(int, count);
1541   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1542
1543   for (i = 0; i < count; i++) {
1544     MPI_Request req = requests[i];      //already received requests are no longer valid
1545     if (req) {
1546       srcs[i] = req->src;
1547       dsts[i] = req->dst;
1548       recvs[i] = req->recv;
1549       comms[i] = req->comm;
1550     }
1551   }
1552   int rank_traced = smpi_process_index();
1553   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1554   extra->type = TRACING_WAITANY;
1555   extra->send_size=count;
1556   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1557
1558 #endif
1559   *index = smpi_mpi_waitany(count, requests, status);
1560 #ifdef HAVE_TRACING
1561   if(*index!=MPI_UNDEFINED){
1562     int src_traced = srcs[*index];
1563     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1564     int dst_traced = dsts[*index];
1565     int is_wait_for_receive = recvs[*index];
1566     if (is_wait_for_receive) {
1567       if(srcs[*index]==MPI_ANY_SOURCE)
1568         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1569                       smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1570                       srcs[*index];
1571       TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1572     }
1573     TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1574     xbt_free(srcs);
1575     xbt_free(dsts);
1576     xbt_free(recvs);
1577     xbt_free(comms);
1578
1579   }
1580 #endif
1581   smpi_bench_begin();
1582   return MPI_SUCCESS;
1583 }
1584
1585 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1586 {
1587
1588   smpi_bench_end();
1589 #ifdef HAVE_TRACING
1590   //save information from requests
1591   int i;
1592   int *srcs = xbt_new0(int, count);
1593   int *dsts = xbt_new0(int, count);
1594   int *recvs = xbt_new0(int, count);
1595   int *valid = xbt_new0(int, count);
1596   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1597
1598   //int valid_count = 0;
1599   for (i = 0; i < count; i++) {
1600     MPI_Request req = requests[i];
1601     if(req!=MPI_REQUEST_NULL){
1602       srcs[i] = req->src;
1603       dsts[i] = req->dst;
1604       recvs[i] = req->recv;
1605       comms[i] = req->comm;
1606       valid[i]=1;;
1607     }else{
1608       valid[i]=0;
1609     }
1610   }
1611   int rank_traced = smpi_process_index();
1612   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1613   extra->type = TRACING_WAITALL;
1614   extra->send_size=count;
1615   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1616 #endif
1617   int retval = smpi_mpi_waitall(count, requests, status);
1618 #ifdef HAVE_TRACING
1619   for (i = 0; i < count; i++) {
1620     if(valid[i]){
1621     //int src_traced = srcs[*index];
1622     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1623       int src_traced = srcs[i];
1624       int dst_traced = dsts[i];
1625       int is_wait_for_receive = recvs[i];
1626       if (is_wait_for_receive) {
1627         if(src_traced==MPI_ANY_SOURCE)
1628         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1629                           smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1630                           srcs[i];
1631         TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1632       }
1633     }
1634   }
1635   TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1636   xbt_free(srcs);
1637   xbt_free(dsts);
1638   xbt_free(recvs);
1639   xbt_free(valid);
1640   xbt_free(comms);
1641
1642 #endif
1643   smpi_bench_begin();
1644   return retval;
1645 }
1646
1647 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1648                  int *indices, MPI_Status status[])
1649 {
1650   int retval = 0;
1651
1652   smpi_bench_end();
1653   if (outcount == NULL) {
1654     retval = MPI_ERR_ARG;
1655   } else {
1656     *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1657     retval = MPI_SUCCESS;
1658   }
1659   smpi_bench_begin();
1660   return retval;
1661 }
1662
1663 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1664                  int* indices, MPI_Status status[])
1665 {
1666   int retval = 0;
1667
1668    smpi_bench_end();
1669    if (outcount == NULL) {
1670      retval = MPI_ERR_ARG;
1671    } else {
1672      *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1673      retval = MPI_SUCCESS;
1674    }
1675    smpi_bench_begin();
1676    return retval;
1677 }
1678
1679
1680 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1681 {
1682   int retval = 0;
1683
1684   smpi_bench_end();
1685
1686   if (comm == MPI_COMM_NULL) {
1687     retval = MPI_ERR_COMM;
1688   } else if (!is_datatype_valid(datatype)) {
1689       retval = MPI_ERR_ARG;
1690   } else {
1691 #ifdef HAVE_TRACING
1692   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1693   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1694
1695   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1696   extra->type = TRACING_BCAST;
1697   extra->send_size = count;
1698   extra->root = root_traced;
1699   extra->datatype1 = encode_datatype(datatype);
1700   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1701
1702 #endif
1703     mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1704     retval = MPI_SUCCESS;
1705 #ifdef HAVE_TRACING
1706   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1707 #endif
1708   }
1709
1710   smpi_bench_begin();
1711   return retval;
1712 }
1713
1714 int PMPI_Barrier(MPI_Comm comm)
1715 {
1716   int retval = 0;
1717
1718   smpi_bench_end();
1719
1720   if (comm == MPI_COMM_NULL) {
1721     retval = MPI_ERR_COMM;
1722   } else {
1723 #ifdef HAVE_TRACING
1724   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1725   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1726   extra->type = TRACING_BARRIER;
1727   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1728 #endif
1729     mpi_coll_barrier_fun(comm);
1730     retval = MPI_SUCCESS;
1731 #ifdef HAVE_TRACING
1732   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1733 #endif
1734   }
1735
1736   smpi_bench_begin();
1737   return retval;
1738 }
1739
1740 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1741                void *recvbuf, int recvcount, MPI_Datatype recvtype,
1742                int root, MPI_Comm comm)
1743 {
1744   int retval = 0;
1745
1746   smpi_bench_end();
1747
1748   if (comm == MPI_COMM_NULL) {
1749     retval = MPI_ERR_COMM;
1750   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1751             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1752     retval = MPI_ERR_TYPE;
1753   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1754             ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1755     retval = MPI_ERR_COUNT;
1756   } else {
1757
1758     char* sendtmpbuf = (char*) sendbuf;
1759     int sendtmpcount = sendcount;
1760     MPI_Datatype sendtmptype = sendtype;
1761     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1762       sendtmpcount=0;
1763       sendtmptype=recvtype;
1764     }
1765 #ifdef HAVE_TRACING
1766   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1767   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1768   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1769   extra->type = TRACING_GATHER;
1770   extra->send_size = sendtmpcount;
1771   extra->recv_size = recvcount;
1772   extra->root = root_traced;
1773   extra->datatype1 = encode_datatype(sendtmptype);
1774   extra->datatype2 = encode_datatype(recvtype);
1775
1776   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1777 #endif
1778     mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1779                     recvtype, root, comm);
1780
1781
1782     retval = MPI_SUCCESS;
1783 #ifdef HAVE_TRACING
1784   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1785 #endif
1786   }
1787
1788   smpi_bench_begin();
1789   return retval;
1790 }
1791
1792 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1793                 void *recvbuf, int *recvcounts, int *displs,
1794                 MPI_Datatype recvtype, int root, MPI_Comm comm)
1795 {
1796   int retval = 0;
1797
1798   smpi_bench_end();
1799
1800   if (comm == MPI_COMM_NULL) {
1801     retval = MPI_ERR_COMM;
1802   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1803             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1804     retval = MPI_ERR_TYPE;
1805   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1806     retval = MPI_ERR_COUNT;
1807   } else if (recvcounts == NULL || displs == NULL) {
1808     retval = MPI_ERR_ARG;
1809   } else {
1810     char* sendtmpbuf = (char*) sendbuf;
1811     int sendtmpcount = sendcount;
1812     MPI_Datatype sendtmptype = sendtype;
1813     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1814       sendtmpcount=0;
1815       sendtmptype=recvtype;
1816     }
1817
1818 #ifdef HAVE_TRACING
1819   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1820   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1821   int i=0;
1822   int size = smpi_comm_size(comm);
1823   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1824   extra->type = TRACING_GATHERV;
1825   extra->send_size = sendtmpcount;
1826   extra->recvcounts= xbt_malloc(size*sizeof(int));
1827   for(i=0; i< size; i++)//copy data to avoid bad free
1828     extra->recvcounts[i] = recvcounts[i];
1829   extra->num_processes = size;
1830   extra->root = root_traced;
1831   extra->datatype1 = encode_datatype(sendtmptype);
1832   extra->datatype2 = encode_datatype(recvtype);
1833
1834   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1835 #endif
1836     smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1837                      displs, recvtype, root, comm);
1838     retval = MPI_SUCCESS;
1839 #ifdef HAVE_TRACING
1840   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1841 #endif
1842   }
1843
1844   smpi_bench_begin();
1845   return retval;
1846 }
1847
1848 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1849                   void *recvbuf, int recvcount, MPI_Datatype recvtype,
1850                   MPI_Comm comm)
1851 {
1852   int retval = 0;
1853
1854   smpi_bench_end();
1855
1856   if (comm == MPI_COMM_NULL) {
1857     retval = MPI_ERR_COMM;
1858   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1859             (recvtype == MPI_DATATYPE_NULL)){
1860     retval = MPI_ERR_TYPE;
1861   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1862             (recvcount <0)){
1863     retval = MPI_ERR_COUNT;
1864   } else {
1865     if(sendbuf == MPI_IN_PLACE) {
1866       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1867       sendcount=recvcount;
1868       sendtype=recvtype;
1869     }
1870 #ifdef HAVE_TRACING
1871   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1872   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1873   extra->type = TRACING_ALLGATHER;
1874   extra->send_size = sendcount;
1875   extra->recv_size = recvcount;
1876   extra->datatype1 = encode_datatype(sendtype);
1877   extra->datatype2 = encode_datatype(recvtype);
1878
1879   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1880 #endif
1881     mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1882                            recvtype, comm);
1883     retval = MPI_SUCCESS;
1884
1885 #ifdef HAVE_TRACING
1886   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1887 #endif
1888   }
1889   smpi_bench_begin();
1890   return retval;
1891 }
1892
1893 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1894                    void *recvbuf, int *recvcounts, int *displs,
1895                    MPI_Datatype recvtype, MPI_Comm comm)
1896 {
1897   int retval = 0;
1898
1899   smpi_bench_end();
1900
1901   if (comm == MPI_COMM_NULL) {
1902     retval = MPI_ERR_COMM;
1903   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1904             (recvtype == MPI_DATATYPE_NULL)){
1905     retval = MPI_ERR_TYPE;
1906   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1907     retval = MPI_ERR_COUNT;
1908   } else if (recvcounts == NULL || displs == NULL) {
1909     retval = MPI_ERR_ARG;
1910   } else {
1911
1912     if(sendbuf == MPI_IN_PLACE) {
1913       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1914       sendcount=recvcounts[smpi_comm_rank(comm)];
1915       sendtype=recvtype;
1916     }
1917 #ifdef HAVE_TRACING
1918   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1919   int i=0;
1920   int size = smpi_comm_size(comm);
1921   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1922   extra->type = TRACING_ALLGATHERV;
1923   extra->send_size = sendcount;
1924   extra->recvcounts= xbt_malloc(size*sizeof(int));
1925   for(i=0; i< size; i++)//copy data to avoid bad free
1926     extra->recvcounts[i] = recvcounts[i];
1927   extra->num_processes = size;
1928   extra->datatype1 = encode_datatype(sendtype);
1929   extra->datatype2 = encode_datatype(recvtype);
1930
1931   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1932 #endif
1933     mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1934                         displs, recvtype, comm);
1935     retval = MPI_SUCCESS;
1936 #ifdef HAVE_TRACING
1937   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1938 #endif
1939   }
1940
1941   smpi_bench_begin();
1942   return retval;
1943 }
1944
1945 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1946                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1947                 int root, MPI_Comm comm)
1948 {
1949   int retval = 0;
1950
1951   smpi_bench_end();
1952
1953   if (comm == MPI_COMM_NULL) {
1954     retval = MPI_ERR_COMM;
1955   } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1956              || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1957     retval = MPI_ERR_TYPE;
1958   } else if ((sendbuf == recvbuf) ||
1959       ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
1960     retval = MPI_ERR_BUFFER;
1961   }else {
1962
1963     if (recvbuf == MPI_IN_PLACE) {
1964         recvtype=sendtype;
1965         recvcount=sendcount;
1966     }
1967 #ifdef HAVE_TRACING
1968   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1969   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1970   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1971   extra->type = TRACING_SCATTER;
1972   extra->send_size = sendcount;
1973   extra->recv_size= recvcount;
1974   extra->root = root_traced;
1975   extra->datatype1 = encode_datatype(sendtype);
1976   extra->datatype2 = encode_datatype(recvtype);
1977
1978   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1979 #endif
1980     mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1981                      recvtype, root, comm);
1982     retval = MPI_SUCCESS;
1983 #ifdef HAVE_TRACING
1984   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1985 #endif
1986   }
1987
1988   smpi_bench_begin();
1989   return retval;
1990 }
1991
1992 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1993                  MPI_Datatype sendtype, void *recvbuf, int recvcount,
1994                  MPI_Datatype recvtype, int root, MPI_Comm comm)
1995 {
1996   int retval = 0;
1997
1998   smpi_bench_end();
1999
2000   if (comm == MPI_COMM_NULL) {
2001     retval = MPI_ERR_COMM;
2002   } else if (sendcounts == NULL || displs == NULL) {
2003     retval = MPI_ERR_ARG;
2004   } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2005              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2006     retval = MPI_ERR_TYPE;
2007   } else {
2008     if (recvbuf == MPI_IN_PLACE) {
2009         recvtype=sendtype;
2010         recvcount=sendcounts[smpi_comm_rank(comm)];
2011     }
2012 #ifdef HAVE_TRACING
2013   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2014   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2015   int i=0;
2016   int size = smpi_comm_size(comm);
2017   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2018   extra->type = TRACING_SCATTERV;
2019   extra->recv_size = recvcount;
2020   extra->sendcounts= xbt_malloc(size*sizeof(int));
2021   for(i=0; i< size; i++)//copy data to avoid bad free
2022     extra->sendcounts[i] = sendcounts[i];
2023   extra->num_processes = size;
2024   extra->root = root_traced;
2025   extra->datatype1 = encode_datatype(sendtype);
2026   extra->datatype2 = encode_datatype(recvtype);
2027
2028   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2029
2030 #endif
2031     smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2032                       recvcount, recvtype, root, comm);
2033     retval = MPI_SUCCESS;
2034 #ifdef HAVE_TRACING
2035   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2036 #endif
2037   }
2038
2039   smpi_bench_begin();
2040   return retval;
2041 }
2042
2043 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2044                MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2045 {
2046   int retval = 0;
2047
2048   smpi_bench_end();
2049
2050   if (comm == MPI_COMM_NULL) {
2051     retval = MPI_ERR_COMM;
2052   } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2053     retval = MPI_ERR_ARG;
2054   } else {
2055 #ifdef HAVE_TRACING
2056   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2057   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2058   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2059   extra->type = TRACING_REDUCE;
2060   extra->send_size = count;
2061   extra->datatype1 = encode_datatype(datatype);
2062   extra->root = root_traced;
2063
2064   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2065 #endif
2066     mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2067
2068     retval = MPI_SUCCESS;
2069 #ifdef HAVE_TRACING
2070   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2071 #endif
2072   }
2073
2074   smpi_bench_begin();
2075   return retval;
2076 }
2077
2078 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2079     MPI_Datatype datatype, MPI_Op op){
2080   int retval = 0;
2081
2082     smpi_bench_end();
2083     if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2084       retval = MPI_ERR_ARG;
2085     } else {
2086       smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2087       retval=MPI_SUCCESS;
2088     }
2089     smpi_bench_begin();
2090     return retval;
2091 }
2092
2093 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2094                   MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2095 {
2096   int retval = 0;
2097
2098   smpi_bench_end();
2099
2100   if (comm == MPI_COMM_NULL) {
2101     retval = MPI_ERR_COMM;
2102   } else if (!is_datatype_valid(datatype)) {
2103     retval = MPI_ERR_TYPE;
2104   } else if (op == MPI_OP_NULL) {
2105     retval = MPI_ERR_OP;
2106   } else {
2107
2108     char* sendtmpbuf = (char*) sendbuf;
2109     if( sendbuf == MPI_IN_PLACE ) {
2110       sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2111       smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2112     }
2113 #ifdef HAVE_TRACING
2114   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2115   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2116   extra->type = TRACING_ALLREDUCE;
2117   extra->send_size = count;
2118   extra->datatype1 = encode_datatype(datatype);
2119
2120   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2121 #endif
2122     mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2123
2124     if( sendbuf == MPI_IN_PLACE ) {
2125       xbt_free(sendtmpbuf);
2126     }
2127
2128     retval = MPI_SUCCESS;
2129 #ifdef HAVE_TRACING
2130   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2131 #endif
2132   }
2133
2134   smpi_bench_begin();
2135   return retval;
2136 }
2137
2138 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2139              MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2140 {
2141   int retval = 0;
2142
2143   smpi_bench_end();
2144
2145   if (comm == MPI_COMM_NULL) {
2146     retval = MPI_ERR_COMM;
2147   } else if (!is_datatype_valid(datatype)) {
2148     retval = MPI_ERR_TYPE;
2149   } else if (op == MPI_OP_NULL) {
2150     retval = MPI_ERR_OP;
2151   } else {
2152 #ifdef HAVE_TRACING
2153   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2154   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2155   extra->type = TRACING_SCAN;
2156   extra->send_size = count;
2157   extra->datatype1 = encode_datatype(datatype);
2158
2159   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2160 #endif
2161     smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2162     retval = MPI_SUCCESS;
2163 #ifdef HAVE_TRACING
2164   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2165 #endif
2166   }
2167
2168   smpi_bench_begin();
2169   return retval;
2170 }
2171
2172 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2173                 MPI_Op op, MPI_Comm comm){
2174   int retval = 0;
2175
2176   smpi_bench_end();
2177
2178   if (comm == MPI_COMM_NULL) {
2179     retval = MPI_ERR_COMM;
2180   } else if (!is_datatype_valid(datatype)) {
2181     retval = MPI_ERR_TYPE;
2182   } else if (op == MPI_OP_NULL) {
2183     retval = MPI_ERR_OP;
2184   } else {
2185 #ifdef HAVE_TRACING
2186   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2187   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2188   extra->type = TRACING_EXSCAN;
2189   extra->send_size = count;
2190   extra->datatype1 = encode_datatype(datatype);
2191
2192   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2193 #endif
2194     smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2195     retval = MPI_SUCCESS;
2196 #ifdef HAVE_TRACING
2197   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2198 #endif
2199   }
2200
2201   smpi_bench_begin();
2202   return retval;
2203 }
2204
2205 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2206                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2207 {
2208   int retval = 0;
2209   smpi_bench_end();
2210
2211   if (comm == MPI_COMM_NULL) {
2212     retval = MPI_ERR_COMM;
2213   } else if (!is_datatype_valid(datatype)) {
2214     retval = MPI_ERR_TYPE;
2215   } else if (op == MPI_OP_NULL) {
2216     retval = MPI_ERR_OP;
2217   } else if (recvcounts == NULL) {
2218     retval = MPI_ERR_ARG;
2219   } else {
2220 #ifdef HAVE_TRACING
2221   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2222   int i=0;
2223   int size = smpi_comm_size(comm);
2224   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2225   extra->type = TRACING_REDUCE_SCATTER;
2226   extra->send_size = 0;
2227   extra->recvcounts= xbt_malloc(size*sizeof(int));
2228   for(i=0; i< size; i++)//copy data to avoid bad free
2229     extra->recvcounts[i] = recvcounts[i];
2230   extra->num_processes = size;
2231   extra->datatype1 = encode_datatype(datatype);
2232
2233   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2234 #endif
2235     void* sendtmpbuf=sendbuf;
2236     if(sendbuf==MPI_IN_PLACE){
2237       sendtmpbuf=recvbuf;
2238     }
2239
2240     mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2241                        datatype,  op, comm);
2242     retval = MPI_SUCCESS;
2243 #ifdef HAVE_TRACING
2244   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2245 #endif
2246   }
2247
2248   smpi_bench_begin();
2249   return retval;
2250 }
2251
2252 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2253                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2254 {
2255   int retval,i;
2256   smpi_bench_end();
2257
2258   if (comm == MPI_COMM_NULL) {
2259     retval = MPI_ERR_COMM;
2260   } else if (!is_datatype_valid(datatype)) {
2261     retval = MPI_ERR_TYPE;
2262   } else if (op == MPI_OP_NULL) {
2263     retval = MPI_ERR_OP;
2264   } else if (recvcount < 0) {
2265     retval = MPI_ERR_ARG;
2266   } else {
2267     int count=smpi_comm_size(comm);
2268
2269 #ifdef HAVE_TRACING
2270   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2271   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2272   extra->type = TRACING_REDUCE_SCATTER;
2273   extra->send_size = 0;
2274   extra->recvcounts= xbt_malloc(count*sizeof(int));
2275   for(i=0; i< count; i++)//copy data to avoid bad free
2276     extra->recvcounts[i] = recvcount;
2277   extra->num_processes = count;
2278   extra->datatype1 = encode_datatype(datatype);
2279
2280   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2281 #endif
2282     int* recvcounts=(int*)xbt_malloc(count);
2283     for (i=0; i<count;i++)recvcounts[i]=recvcount;
2284     mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2285                        datatype,  op, comm);
2286     xbt_free(recvcounts);
2287     retval = MPI_SUCCESS;
2288 #ifdef HAVE_TRACING
2289   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2290 #endif
2291   }
2292
2293   smpi_bench_begin();
2294   return retval;
2295 }
2296
2297 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2298                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
2299                  MPI_Comm comm)
2300 {
2301   int retval = 0;
2302
2303   smpi_bench_end();
2304
2305   if (comm == MPI_COMM_NULL) {
2306     retval = MPI_ERR_COMM;
2307   } else if (sendtype == MPI_DATATYPE_NULL
2308              || recvtype == MPI_DATATYPE_NULL) {
2309     retval = MPI_ERR_TYPE;
2310   } else {
2311 #ifdef HAVE_TRACING
2312   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2313   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2314   extra->type = TRACING_ALLTOALL;
2315   extra->send_size = sendcount;
2316   extra->recv_size = recvcount;
2317   extra->datatype1 = encode_datatype(sendtype);
2318   extra->datatype2 = encode_datatype(recvtype);
2319
2320   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2321 #endif
2322     retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2323 #ifdef HAVE_TRACING
2324   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2325 #endif
2326   }
2327
2328   smpi_bench_begin();
2329   return retval;
2330 }
2331
2332 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2333                   MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2334                   int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2335 {
2336   int retval = 0;
2337
2338   smpi_bench_end();
2339
2340   if (comm == MPI_COMM_NULL) {
2341     retval = MPI_ERR_COMM;
2342   } else if (sendtype == MPI_DATATYPE_NULL
2343              || recvtype == MPI_DATATYPE_NULL) {
2344     retval = MPI_ERR_TYPE;
2345   } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2346              || recvdisps == NULL) {
2347     retval = MPI_ERR_ARG;
2348   } else {
2349 #ifdef HAVE_TRACING
2350   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2351   int i=0;
2352   int size = smpi_comm_size(comm);
2353   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2354   extra->type = TRACING_ALLTOALLV;
2355   extra->send_size = 0;
2356   extra->recv_size = 0;
2357   extra->recvcounts= xbt_malloc(size*sizeof(int));
2358   extra->sendcounts= xbt_malloc(size*sizeof(int));
2359
2360   for(i=0; i< size; i++){//copy data to avoid bad free
2361     extra->send_size += sendcounts[i];
2362     extra->recv_size += recvcounts[i];
2363
2364     extra->sendcounts[i] = sendcounts[i];
2365     extra->recvcounts[i] = recvcounts[i];
2366   }
2367   extra->num_processes = size;
2368
2369   extra->datatype1 = encode_datatype(sendtype);
2370   extra->datatype2 = encode_datatype(recvtype);
2371
2372   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2373 #endif
2374     retval =
2375         mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2376                                   recvbuf, recvcounts, recvdisps, recvtype,
2377                                   comm);
2378 #ifdef HAVE_TRACING
2379   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2380 #endif
2381   }
2382
2383   smpi_bench_begin();
2384   return retval;
2385 }
2386
2387
2388 int PMPI_Get_processor_name(char *name, int *resultlen)
2389 {
2390   int retval = MPI_SUCCESS;
2391
2392   strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2393           strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2394           strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2395           MPI_MAX_PROCESSOR_NAME - 1 );
2396   *resultlen =
2397       strlen(name) >
2398       MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2399
2400   return retval;
2401 }
2402
2403 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2404 {
2405   int retval = MPI_SUCCESS;
2406   size_t size;
2407
2408   if (status == NULL || count == NULL) {
2409     retval = MPI_ERR_ARG;
2410   } else if (!is_datatype_valid(datatype)) {
2411     retval = MPI_ERR_TYPE;
2412   } else {
2413     size = smpi_datatype_size(datatype);
2414     if (size == 0) {
2415       *count = 0;
2416     } else if (status->count % size != 0) {
2417       retval = MPI_UNDEFINED;
2418     } else {
2419       *count = smpi_mpi_get_count(status, datatype);
2420     }
2421   }
2422   return retval;
2423 }
2424
2425 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2426   int retval = 0;
2427
2428   if (old_type == MPI_DATATYPE_NULL) {
2429     retval = MPI_ERR_TYPE;
2430   } else if (count<0){
2431     retval = MPI_ERR_COUNT;
2432   } else {
2433     retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2434   }
2435   return retval;
2436 }
2437
2438 int PMPI_Type_commit(MPI_Datatype* datatype) {
2439   int retval = 0;
2440
2441   if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2442     retval = MPI_ERR_TYPE;
2443   } else {
2444     smpi_datatype_commit(datatype);
2445     retval = MPI_SUCCESS;
2446   }
2447   return retval;
2448 }
2449
2450
2451 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2452   int retval = 0;
2453
2454   if (old_type == MPI_DATATYPE_NULL) {
2455     retval = MPI_ERR_TYPE;
2456   } else if (count<0 || blocklen<0){
2457     retval = MPI_ERR_COUNT;
2458   } else {
2459     retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2460   }
2461   return retval;
2462 }
2463
2464 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2465   int retval = 0;
2466
2467   if (old_type == MPI_DATATYPE_NULL) {
2468     retval = MPI_ERR_TYPE;
2469   } else if (count<0 || blocklen<0){
2470     retval = MPI_ERR_COUNT;
2471   } else {
2472     retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2473   }
2474   return retval;
2475 }
2476
2477 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2478   return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2479 }
2480
2481 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2482   int retval = 0;
2483
2484   if (old_type == MPI_DATATYPE_NULL) {
2485     retval = MPI_ERR_TYPE;
2486   } else if (count<0){
2487     retval = MPI_ERR_COUNT;
2488   } else {
2489     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2490   }
2491   return retval;
2492 }
2493
2494 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2495   int retval = 0;
2496
2497   if (old_type == MPI_DATATYPE_NULL) {
2498     retval = MPI_ERR_TYPE;
2499   } else if (count<0){
2500     retval = MPI_ERR_COUNT;
2501   } else {
2502     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2503   }
2504   return retval;
2505 }
2506
2507 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2508   int retval,i;
2509
2510   if (old_type == MPI_DATATYPE_NULL) {
2511     retval = MPI_ERR_TYPE;
2512   } else if (count<0){
2513     retval = MPI_ERR_COUNT;
2514   } else {
2515     int* blocklens=(int*)xbt_malloc(blocklength*count);
2516     for (i=0; i<count;i++)blocklens[i]=blocklength;
2517     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2518     xbt_free(blocklens);
2519   }
2520   return retval;
2521 }
2522
2523
2524 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2525   int retval = 0;
2526
2527   if (old_type == MPI_DATATYPE_NULL) {
2528     retval = MPI_ERR_TYPE;
2529   } else if (count<0){
2530     retval = MPI_ERR_COUNT;
2531   } else {
2532     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2533   }
2534   return retval;
2535 }
2536
2537 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2538   return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2539 }
2540
2541 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2542   int retval,i;
2543
2544   if (old_type == MPI_DATATYPE_NULL) {
2545     retval = MPI_ERR_TYPE;
2546   } else if (count<0){
2547     retval = MPI_ERR_COUNT;
2548   } else {
2549     int* blocklens=(int*)xbt_malloc(blocklength*count);
2550     for (i=0; i<count;i++)blocklens[i]=blocklength;
2551     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2552     xbt_free(blocklens);
2553   }
2554   return retval;
2555 }
2556
2557
2558 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2559   int retval = 0;
2560
2561   if (count<0){
2562     retval = MPI_ERR_COUNT;
2563   } else {
2564     retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2565   }
2566   return retval;
2567 }
2568
2569 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2570   return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2571 }
2572
2573
2574 int PMPI_Error_class(int errorcode, int* errorclass) {
2575   // assume smpi uses only standard mpi error codes
2576   *errorclass=errorcode;
2577   return MPI_SUCCESS;
2578 }
2579
2580
2581 int PMPI_Initialized(int* flag) {
2582    *flag=smpi_process_initialized();
2583    return MPI_SUCCESS;
2584 }
2585
2586 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2587  * will be implemented, not only should we check if the topology is NULL, but
2588  * we should check if it is the good topology type (so we have to add a
2589  *  MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2590
2591 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2592   int retval = 0;
2593   if (comm_old == MPI_COMM_NULL){
2594     retval =  MPI_ERR_COMM;
2595   } else if (ndims < 0 ||
2596            (ndims > 0 && (dims == NULL || 
2597                           periodic == NULL)) ||
2598            comm_cart == NULL) {
2599     retval = MPI_ERR_ARG;
2600   } else{
2601     retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2602   }
2603   return retval;
2604 }
2605
2606 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2607   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2608     return MPI_ERR_TOPOLOGY;
2609   }
2610   if (coords == NULL) {
2611     return MPI_ERR_ARG;
2612   }
2613   return smpi_mpi_cart_rank(comm, coords, rank);
2614 }
2615
2616 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2617   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2618     return MPI_ERR_TOPOLOGY;
2619   }
2620   if (source == NULL || dest == NULL || direction < 0 ) {
2621     return MPI_ERR_ARG;
2622   }
2623   return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2624 }
2625
2626 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2627   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2628     return MPI_ERR_TOPOLOGY;
2629   }
2630   if (rank < 0 || rank >= smpi_comm_size(comm)) {
2631     return MPI_ERR_RANK;
2632   }
2633   if (maxdims <= 0) {
2634     return MPI_ERR_ARG;
2635   }
2636   if(coords == NULL) {
2637     return MPI_ERR_ARG;
2638   }
2639   return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2640 }
2641
2642 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2643   if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2644     return MPI_ERR_TOPOLOGY;
2645   }
2646   if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2647     return MPI_ERR_ARG;
2648   }
2649   return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2650 }
2651
2652 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2653   if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2654     return MPI_ERR_TOPOLOGY;
2655   }
2656   if (ndims == NULL) {
2657     return MPI_ERR_ARG;
2658   }
2659   return smpi_mpi_cartdim_get(comm, ndims);
2660 }
2661
2662 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2663   if(dims == NULL) {
2664     return MPI_ERR_ARG;
2665   }
2666   if (ndims < 1 || nnodes < 1) {
2667     return MPI_ERR_DIMS;
2668   }
2669
2670   return smpi_mpi_dims_create(nnodes, ndims, dims);
2671 }
2672
2673 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2674   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2675     return MPI_ERR_TOPOLOGY;
2676   }
2677   if (comm_new == NULL) {
2678     return MPI_ERR_ARG;
2679   }
2680   return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2681 }
2682
2683 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2684     if(oldtype == MPI_DATATYPE_NULL) {
2685         return MPI_ERR_TYPE;
2686     }
2687     int blocks[3] = { 1, 1, 1 };
2688     MPI_Aint disps[3] = { lb, 0, lb+extent };
2689     MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2690         
2691     s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks,
2692                                                                 disps,
2693                                                                 3,
2694                                                                 types
2695                                                                 );
2696     smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2697
2698     (*newtype)->flags &= ~DT_FLAG_COMMITED;
2699     return MPI_SUCCESS;
2700 }
2701
2702
2703
2704 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2705   int retval = 0;
2706   smpi_bench_end();
2707   if (comm == MPI_COMM_NULL) {
2708     retval= MPI_ERR_COMM;
2709   }else if ((base == NULL && size != 0)
2710             || disp_unit <= 0 || size < 0 ){
2711     retval= MPI_ERR_OTHER;
2712   }else{
2713     *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2714     retval = MPI_SUCCESS;
2715   }
2716   smpi_bench_begin();
2717   return retval;
2718 }
2719
2720 int PMPI_Win_free( MPI_Win* win){
2721   int retval = 0;
2722   smpi_bench_end();
2723   if (win == NULL || *win == MPI_WIN_NULL) {
2724     retval = MPI_ERR_WIN;
2725   }else{
2726     retval=smpi_mpi_win_free(win);
2727   }
2728   smpi_bench_begin();
2729   return retval;
2730 }
2731
2732 int PMPI_Win_set_name(MPI_Win  win, char * name)
2733 {
2734   int retval = 0;
2735   if (win == MPI_WIN_NULL)  {
2736     retval = MPI_ERR_TYPE;
2737   } else if (name == NULL)  {
2738     retval = MPI_ERR_ARG;
2739   } else {
2740     smpi_mpi_win_set_name(win, name);
2741     retval = MPI_SUCCESS;
2742   }
2743   return retval;
2744 }
2745
2746 int PMPI_Win_get_name(MPI_Win  win, char * name, int* len)
2747 {
2748   int retval = 0;
2749
2750   if (win == MPI_WIN_NULL)  {
2751     retval = MPI_ERR_TYPE;
2752   } else if (name == NULL)  {
2753     retval = MPI_ERR_ARG;
2754   } else {
2755     smpi_mpi_win_get_name(win, name, len);
2756     retval = MPI_SUCCESS;
2757   }
2758   return retval;
2759 }
2760
2761
2762 int PMPI_Win_fence( int assert,  MPI_Win win){
2763   int retval = 0;
2764   smpi_bench_end();
2765   if (win == MPI_WIN_NULL) {
2766     retval = MPI_ERR_WIN;
2767   } else {
2768     retval = smpi_mpi_win_fence(assert, win);
2769   }
2770   smpi_bench_begin();
2771   return retval;
2772 }
2773
2774 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2775               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2776   int retval = 0;
2777   smpi_bench_end();
2778   if (win == MPI_WIN_NULL) {
2779     retval = MPI_ERR_WIN;
2780   } else if (target_rank == MPI_PROC_NULL) {
2781     retval = MPI_SUCCESS;
2782   } else if (target_rank <0){
2783     retval = MPI_ERR_RANK;
2784   } else if (target_disp <0){
2785       retval = MPI_ERR_ARG;
2786   } else if (origin_count < 0 || target_count < 0) {
2787     retval = MPI_ERR_COUNT;
2788   } else if (origin_addr==NULL && origin_count > 0){
2789     retval = MPI_ERR_COUNT;
2790   } else if ((!is_datatype_valid(origin_datatype)) ||
2791             (!is_datatype_valid(target_datatype))) {
2792     retval = MPI_ERR_TYPE;
2793   } else {
2794     retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2795   }
2796   smpi_bench_begin();
2797   return retval;
2798 }
2799
2800 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2801               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2802   int retval = 0;
2803   smpi_bench_end();
2804   if (win == MPI_WIN_NULL) {
2805     retval = MPI_ERR_WIN;
2806   } else if (target_rank == MPI_PROC_NULL) {
2807     retval = MPI_SUCCESS;
2808   } else if (target_rank <0){
2809     retval = MPI_ERR_RANK;
2810   } else if (target_disp <0){
2811     retval = MPI_ERR_ARG;
2812   } else if (origin_count < 0 || target_count < 0) {
2813     retval = MPI_ERR_COUNT;
2814   } else if (origin_addr==NULL && origin_count > 0){
2815     retval = MPI_ERR_COUNT;
2816   } else if ((!is_datatype_valid(origin_datatype)) ||
2817             (!is_datatype_valid(target_datatype))) {
2818     retval = MPI_ERR_TYPE;
2819   } else {
2820     retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2821   }
2822   smpi_bench_begin();
2823   return retval;
2824 }
2825
2826
2827 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2828               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2829   int retval = 0;
2830   smpi_bench_end();
2831   if (win == MPI_WIN_NULL) {
2832     retval = MPI_ERR_WIN;
2833   } else if (target_rank == MPI_PROC_NULL) {
2834     retval = MPI_SUCCESS;
2835   } else if (target_rank <0){
2836     retval = MPI_ERR_RANK;
2837   } else if (target_disp <0){
2838     retval = MPI_ERR_ARG;
2839   } else if (origin_count < 0 || target_count < 0) {
2840     retval = MPI_ERR_COUNT;
2841   } else if (origin_addr==NULL && origin_count > 0){
2842     retval = MPI_ERR_COUNT;
2843   } else if ((!is_datatype_valid(origin_datatype)) ||
2844             (!is_datatype_valid(target_datatype))) {
2845     retval = MPI_ERR_TYPE;
2846   } else if (op == MPI_OP_NULL) {
2847     retval = MPI_ERR_OP;
2848   } else {
2849     retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, op, win);
2850   }
2851   smpi_bench_begin();
2852   return retval;
2853 }
2854
2855
2856 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2857   void *ptr = xbt_malloc(size);
2858   if(!ptr)
2859     return MPI_ERR_NO_MEM;
2860   else {
2861     *(void **)baseptr = ptr;
2862     return MPI_SUCCESS;
2863   }
2864 }
2865
2866 int PMPI_Free_mem(void *baseptr){
2867   xbt_free(baseptr);
2868   return MPI_SUCCESS;
2869 }
2870
2871 int PMPI_Type_set_name(MPI_Datatype  datatype, char * name)
2872 {
2873   int retval = 0;
2874   if (datatype == MPI_DATATYPE_NULL)  {
2875     retval = MPI_ERR_TYPE;
2876   } else if (name == NULL)  {
2877     retval = MPI_ERR_ARG;
2878   } else {
2879     smpi_datatype_set_name(datatype, name);
2880     retval = MPI_SUCCESS;
2881   }
2882   return retval;
2883 }
2884
2885 int PMPI_Type_get_name(MPI_Datatype  datatype, char * name, int* len)
2886 {
2887   int retval = 0;
2888
2889   if (datatype == MPI_DATATYPE_NULL)  {
2890     retval = MPI_ERR_TYPE;
2891   } else if (name == NULL)  {
2892     retval = MPI_ERR_ARG;
2893   } else {
2894     smpi_datatype_get_name(datatype, name, len);
2895     retval = MPI_SUCCESS;
2896   }
2897   return retval;
2898 }
2899
2900 /* The following calls are not yet implemented and will fail at runtime. */
2901 /* Once implemented, please move them above this notice. */
2902
2903 #define NOT_YET_IMPLEMENTED {                                           \
2904     XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
2905     return MPI_SUCCESS;                                                 \
2906   }
2907
2908
2909
2910 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2911   NOT_YET_IMPLEMENTED
2912 }
2913
2914
2915 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2916   NOT_YET_IMPLEMENTED
2917 }
2918
2919
2920 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2921   NOT_YET_IMPLEMENTED
2922 }
2923
2924 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2925   NOT_YET_IMPLEMENTED
2926 }
2927
2928 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2929   NOT_YET_IMPLEMENTED
2930 }
2931
2932 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2933   NOT_YET_IMPLEMENTED
2934 }
2935
2936 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2937   NOT_YET_IMPLEMENTED
2938 }
2939
2940 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2941   NOT_YET_IMPLEMENTED
2942 }
2943
2944 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2945   NOT_YET_IMPLEMENTED
2946 }
2947
2948 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2949   NOT_YET_IMPLEMENTED
2950 }
2951
2952 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2953   NOT_YET_IMPLEMENTED
2954 }
2955
2956 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2957   NOT_YET_IMPLEMENTED
2958 }
2959
2960 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2961   NOT_YET_IMPLEMENTED
2962 }
2963
2964 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2965   NOT_YET_IMPLEMENTED
2966 }
2967
2968 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
2969   NOT_YET_IMPLEMENTED
2970 }
2971
2972 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
2973   NOT_YET_IMPLEMENTED
2974 }
2975
2976 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
2977   NOT_YET_IMPLEMENTED
2978 }
2979
2980 int PMPI_Cancel(MPI_Request* request) {
2981   NOT_YET_IMPLEMENTED
2982 }
2983
2984 int PMPI_Buffer_attach(void* buffer, int size) {
2985   NOT_YET_IMPLEMENTED
2986 }
2987
2988 int PMPI_Buffer_detach(void* buffer, int* size) {
2989   NOT_YET_IMPLEMENTED
2990 }
2991
2992 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2993   NOT_YET_IMPLEMENTED
2994 }
2995
2996 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2997 {
2998   NOT_YET_IMPLEMENTED
2999 }
3000
3001 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3002 {
3003   NOT_YET_IMPLEMENTED
3004 }
3005
3006 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3007 {
3008   NOT_YET_IMPLEMENTED
3009 }
3010
3011 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3012 {
3013   NOT_YET_IMPLEMENTED
3014 }
3015
3016 int PMPI_Comm_free_keyval(int* keyval) {
3017   NOT_YET_IMPLEMENTED
3018 }
3019
3020 int PMPI_Pcontrol(const int level )
3021 {
3022   NOT_YET_IMPLEMENTED
3023 }
3024
3025 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3026   NOT_YET_IMPLEMENTED
3027 }
3028
3029 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3030 {
3031   NOT_YET_IMPLEMENTED
3032 }
3033
3034 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3035 {
3036   NOT_YET_IMPLEMENTED
3037 }
3038
3039 int PMPI_Type_delete_attr (MPI_Datatype type, int comm_keyval)
3040 {
3041   NOT_YET_IMPLEMENTED
3042 }
3043
3044 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3045 {
3046   NOT_YET_IMPLEMENTED
3047 }
3048
3049 int PMPI_Type_free_keyval(int* keyval) {
3050   NOT_YET_IMPLEMENTED
3051 }
3052
3053 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
3054   NOT_YET_IMPLEMENTED
3055 }
3056
3057 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3058   NOT_YET_IMPLEMENTED
3059 }
3060
3061 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3062   NOT_YET_IMPLEMENTED
3063 }
3064
3065 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3066   NOT_YET_IMPLEMENTED
3067 }
3068
3069 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3070   NOT_YET_IMPLEMENTED
3071 }
3072
3073 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3074   NOT_YET_IMPLEMENTED
3075 }
3076
3077 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3078   NOT_YET_IMPLEMENTED
3079 }
3080
3081 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3082   NOT_YET_IMPLEMENTED
3083 }
3084
3085 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3086   NOT_YET_IMPLEMENTED
3087 }
3088
3089 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3090   NOT_YET_IMPLEMENTED
3091 }
3092
3093 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3094   NOT_YET_IMPLEMENTED
3095 }
3096
3097 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3098   NOT_YET_IMPLEMENTED
3099 }
3100
3101 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3102   NOT_YET_IMPLEMENTED
3103 }
3104
3105 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3106   NOT_YET_IMPLEMENTED
3107 }
3108
3109 int PMPI_Keyval_free(int* keyval) {
3110   NOT_YET_IMPLEMENTED
3111 }
3112
3113 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3114   NOT_YET_IMPLEMENTED
3115 }
3116
3117 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3118   NOT_YET_IMPLEMENTED
3119 }
3120
3121 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3122   NOT_YET_IMPLEMENTED
3123 }
3124
3125 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
3126   NOT_YET_IMPLEMENTED
3127 }
3128
3129 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
3130   NOT_YET_IMPLEMENTED
3131 }
3132
3133 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3134   NOT_YET_IMPLEMENTED
3135 }
3136
3137 int PMPI_Info_create( MPI_Info *info){
3138   NOT_YET_IMPLEMENTED
3139 }
3140
3141 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3142   NOT_YET_IMPLEMENTED
3143 }
3144
3145 int PMPI_Info_free( MPI_Info *info){
3146   NOT_YET_IMPLEMENTED
3147 }
3148
3149 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
3150                             int *num_addresses, int *num_datatypes, int *combiner){
3151   NOT_YET_IMPLEMENTED
3152 }
3153
3154 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
3155                            int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
3156                            MPI_Datatype* array_of_datatypes){
3157   NOT_YET_IMPLEMENTED
3158 }
3159
3160 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
3161                             int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
3162                             int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
3163   NOT_YET_IMPLEMENTED
3164 }
3165
3166 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){
3167   NOT_YET_IMPLEMENTED
3168 }
3169
3170 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3171   NOT_YET_IMPLEMENTED
3172 }
3173
3174 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3175                     void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
3176                     MPI_Comm comm){
3177   NOT_YET_IMPLEMENTED
3178 }
3179
3180 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3181   NOT_YET_IMPLEMENTED
3182 }
3183
3184 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3185   NOT_YET_IMPLEMENTED
3186 }
3187
3188 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3189   NOT_YET_IMPLEMENTED
3190 }
3191
3192 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3193   NOT_YET_IMPLEMENTED
3194 }
3195
3196 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3197   NOT_YET_IMPLEMENTED
3198 }
3199
3200 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3201   NOT_YET_IMPLEMENTED
3202 }
3203
3204 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3205   NOT_YET_IMPLEMENTED
3206 }
3207
3208 int PMPI_Add_error_class( int *errorclass){
3209   NOT_YET_IMPLEMENTED
3210 }
3211
3212 int PMPI_Add_error_code(  int errorclass, int *errorcode){
3213   NOT_YET_IMPLEMENTED
3214 }
3215
3216 int PMPI_Add_error_string( int errorcode, char *string){
3217   NOT_YET_IMPLEMENTED
3218 }
3219
3220 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3221   NOT_YET_IMPLEMENTED
3222 }
3223
3224 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3225   NOT_YET_IMPLEMENTED
3226 }
3227
3228 int PMPI_Info_delete(MPI_Info info, char *key){
3229   NOT_YET_IMPLEMENTED
3230 }
3231
3232 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3233   NOT_YET_IMPLEMENTED
3234 }
3235
3236 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3237   NOT_YET_IMPLEMENTED
3238 }
3239
3240 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3241   NOT_YET_IMPLEMENTED
3242 }
3243
3244 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3245   NOT_YET_IMPLEMENTED
3246 }
3247
3248 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){
3249   NOT_YET_IMPLEMENTED
3250 }
3251
3252 int PMPI_Grequest_complete( MPI_Request request){
3253   NOT_YET_IMPLEMENTED
3254 }
3255
3256 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3257   NOT_YET_IMPLEMENTED
3258 }
3259
3260 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3261   NOT_YET_IMPLEMENTED
3262 }
3263
3264 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3265   NOT_YET_IMPLEMENTED
3266 }
3267
3268 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3269   NOT_YET_IMPLEMENTED
3270 }
3271
3272 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3273   NOT_YET_IMPLEMENTED
3274 }
3275
3276 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3277   NOT_YET_IMPLEMENTED
3278 }
3279
3280 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3281   NOT_YET_IMPLEMENTED
3282 }
3283
3284 int PMPI_Open_port( MPI_Info info, char *port_name){
3285   NOT_YET_IMPLEMENTED
3286 }
3287
3288 int PMPI_Close_port(char *port_name){
3289   NOT_YET_IMPLEMENTED
3290 }
3291
3292 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3293   NOT_YET_IMPLEMENTED
3294 }
3295
3296 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){
3297   NOT_YET_IMPLEMENTED
3298 }
3299
3300 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3301                               int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3302                               MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3303   NOT_YET_IMPLEMENTED
3304 }
3305
3306 int PMPI_Comm_get_parent( MPI_Comm *parent){
3307   NOT_YET_IMPLEMENTED
3308 }