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