Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / src / smpi / smpi_pmpi.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "private.h"
8 #include "smpi_mpi_dt_private.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
11                                 "Logging specific to SMPI (pmpi)");
12
13 #ifdef HAVE_TRACING
14 //this function need to be here because of the calls to smpi_bench
15 void TRACE_smpi_set_category(const char *category)
16 {
17   //need to end bench otherwise categories for execution tasks are wrong
18   smpi_bench_end();
19   TRACE_internal_smpi_set_category (category);
20   //begin bench after changing process's category
21   smpi_bench_begin();
22 }
23 #endif
24
25 /* PMPI User level calls */
26
27 int PMPI_Init(int *argc, char ***argv)
28 {
29   smpi_process_init(argc, argv);
30 #ifdef HAVE_TRACING
31   int rank = smpi_process_index();
32   TRACE_smpi_init(rank);
33
34   TRACE_smpi_computing_init(rank);
35 #endif
36   smpi_bench_begin();
37   return MPI_SUCCESS;
38 }
39
40 int PMPI_Finalize(void)
41 {
42   smpi_process_finalize();
43   smpi_bench_end();
44 #ifdef HAVE_TRACING
45   int rank = smpi_process_index();
46   TRACE_smpi_computing_out(rank);
47   TRACE_smpi_finalize(smpi_process_index());
48 #endif
49   smpi_process_destroy();
50   return MPI_SUCCESS;
51 }
52
53 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
54 {
55   if (provided != NULL) {
56     *provided = MPI_THREAD_MULTIPLE;
57   }
58   return MPI_Init(argc, argv);
59 }
60
61 int PMPI_Query_thread(int *provided)
62 {
63   int retval;
64
65   smpi_bench_end();
66   if (provided == NULL) {
67     retval = MPI_ERR_ARG;
68   } else {
69     *provided = MPI_THREAD_MULTIPLE;
70     retval = MPI_SUCCESS;
71   }
72   smpi_bench_begin();
73   return retval;
74 }
75
76 int PMPI_Is_thread_main(int *flag)
77 {
78   int retval;
79
80   smpi_bench_end();
81   if (flag == NULL) {
82     retval = MPI_ERR_ARG;
83   } else {
84     *flag = smpi_process_index() == 0;
85     retval = MPI_SUCCESS;
86   }
87   smpi_bench_begin();
88   return retval;
89 }
90
91 int PMPI_Abort(MPI_Comm comm, int errorcode)
92 {
93   smpi_bench_end();
94   smpi_process_destroy();
95 #ifdef HAVE_TRACING
96   int rank = smpi_process_index();
97   TRACE_smpi_computing_out(rank);
98 #endif
99   // FIXME: should kill all processes in comm instead
100   simcall_process_kill(SIMIX_process_self());
101   return MPI_SUCCESS;
102 }
103
104 double PMPI_Wtime(void)
105 {
106   double time;
107
108   smpi_bench_end();
109   time = SIMIX_get_clock();
110   smpi_bench_begin();
111   return time;
112 }
113 extern double sg_maxmin_precision;
114 double PMPI_Wtick(void)
115 {
116   return sg_maxmin_precision;
117 }
118
119 int PMPI_Address(void *location, MPI_Aint * address)
120 {
121   int retval;
122
123   smpi_bench_end();
124   if (!address) {
125     retval = MPI_ERR_ARG;
126   } else {
127     *address = (MPI_Aint) location;
128     retval = MPI_SUCCESS;
129   }
130   smpi_bench_begin();
131   return retval;
132 }
133
134 int PMPI_Type_free(MPI_Datatype * datatype)
135 {
136   int retval;
137
138   smpi_bench_end();
139   if (!datatype) {
140     retval = MPI_ERR_ARG;
141   } else {
142     smpi_datatype_free(datatype);
143     retval = MPI_SUCCESS;
144   }
145   smpi_bench_begin();
146   return retval;
147 }
148
149 int PMPI_Type_size(MPI_Datatype datatype, int *size)
150 {
151   int retval;
152
153   smpi_bench_end();
154   if (datatype == MPI_DATATYPE_NULL) {
155     retval = MPI_ERR_TYPE;
156   } else if (size == NULL) {
157     retval = MPI_ERR_ARG;
158   } else {
159     *size = (int) smpi_datatype_size(datatype);
160     retval = MPI_SUCCESS;
161   }
162   smpi_bench_begin();
163   return retval;
164 }
165
166 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
167 {
168   int retval;
169
170   smpi_bench_end();
171   if (datatype == MPI_DATATYPE_NULL) {
172     retval = MPI_ERR_TYPE;
173   } else if (lb == NULL || extent == NULL) {
174     retval = MPI_ERR_ARG;
175   } else {
176     retval = smpi_datatype_extent(datatype, lb, extent);
177   }
178   smpi_bench_begin();
179   return retval;
180 }
181
182 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
183 {
184   int retval;
185   MPI_Aint dummy;
186
187   smpi_bench_end();
188   if (datatype == MPI_DATATYPE_NULL) {
189     retval = MPI_ERR_TYPE;
190   } else if (extent == NULL) {
191     retval = MPI_ERR_ARG;
192   } else {
193     retval = smpi_datatype_extent(datatype, &dummy, extent);
194   }
195   smpi_bench_begin();
196   return retval;
197 }
198
199 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
200 {
201   int retval;
202
203   smpi_bench_end();
204   if (datatype == MPI_DATATYPE_NULL) {
205     retval = MPI_ERR_TYPE;
206   } else if (disp == NULL) {
207     retval = MPI_ERR_ARG;
208   } else {
209     *disp = smpi_datatype_lb(datatype);
210     retval = MPI_SUCCESS;
211   }
212   smpi_bench_begin();
213   return retval;
214 }
215
216 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
217 {
218   int retval;
219
220   smpi_bench_end();
221   if (datatype == MPI_DATATYPE_NULL) {
222     retval = MPI_ERR_TYPE;
223   } else if (disp == NULL) {
224     retval = MPI_ERR_ARG;
225   } else {
226     *disp = smpi_datatype_ub(datatype);
227     retval = MPI_SUCCESS;
228   }
229   smpi_bench_begin();
230   return retval;
231 }
232
233 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
234 {
235   int retval;
236
237   smpi_bench_end();
238   if (function == NULL || op == NULL) {
239     retval = MPI_ERR_ARG;
240   } else {
241     *op = smpi_op_new(function, commute);
242     retval = MPI_SUCCESS;
243   }
244   smpi_bench_begin();
245   return retval;
246 }
247
248 int PMPI_Op_free(MPI_Op * op)
249 {
250   int retval;
251
252   smpi_bench_end();
253   if (op == NULL) {
254     retval = MPI_ERR_ARG;
255   } else if (*op == MPI_OP_NULL) {
256     retval = MPI_ERR_OP;
257   } else {
258     smpi_op_destroy(*op);
259     *op = MPI_OP_NULL;
260     retval = MPI_SUCCESS;
261   }
262   smpi_bench_begin();
263   return retval;
264 }
265
266 int PMPI_Group_free(MPI_Group * group)
267 {
268   int retval;
269
270   smpi_bench_end();
271   if (group == NULL) {
272     retval = MPI_ERR_ARG;
273   } else {
274     if(*group!= smpi_comm_group(MPI_COMM_WORLD))// do not free the group of the comm_world
275     smpi_group_destroy(*group);
276     *group = MPI_GROUP_NULL;
277     retval = MPI_SUCCESS;
278   }
279   smpi_bench_begin();
280   return retval;
281 }
282
283 int PMPI_Group_size(MPI_Group group, int *size)
284 {
285   int retval;
286
287   smpi_bench_end();
288   if (group == MPI_GROUP_NULL) {
289     retval = MPI_ERR_GROUP;
290   } else if (size == NULL) {
291     retval = MPI_ERR_ARG;
292   } else {
293     *size = smpi_group_size(group);
294     retval = MPI_SUCCESS;
295   }
296   smpi_bench_begin();
297   return retval;
298 }
299
300 int PMPI_Group_rank(MPI_Group group, int *rank)
301 {
302   int retval;
303
304   smpi_bench_end();
305   if (group == MPI_GROUP_NULL) {
306     retval = MPI_ERR_GROUP;
307   } else if (rank == NULL) {
308     retval = MPI_ERR_ARG;
309   } else {
310     *rank = smpi_group_rank(group, smpi_process_index());
311     retval = MPI_SUCCESS;
312   }
313   smpi_bench_begin();
314   return retval;
315 }
316
317 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
318                               MPI_Group group2, int *ranks2)
319 {
320   int retval, i, index;
321
322   smpi_bench_end();
323   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
324     retval = MPI_ERR_GROUP;
325   } else {
326     for (i = 0; i < n; i++) {
327       index = smpi_group_index(group1, ranks1[i]);
328       ranks2[i] = smpi_group_rank(group2, index);
329     }
330     retval = MPI_SUCCESS;
331   }
332   smpi_bench_begin();
333   return retval;
334 }
335
336 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
337 {
338   int retval;
339
340   smpi_bench_end();
341   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
342     retval = MPI_ERR_GROUP;
343   } else if (result == NULL) {
344     retval = MPI_ERR_ARG;
345   } else {
346     *result = smpi_group_compare(group1, group2);
347     retval = MPI_SUCCESS;
348   }
349   smpi_bench_begin();
350   return retval;
351 }
352
353 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
354                     MPI_Group * newgroup)
355 {
356   int retval, i, proc1, proc2, size, size2;
357
358   smpi_bench_end();
359   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
360     retval = MPI_ERR_GROUP;
361   } else if (newgroup == NULL) {
362     retval = MPI_ERR_ARG;
363   } else {
364     size = smpi_group_size(group1);
365     size2 = smpi_group_size(group2);
366     for (i = 0; i < size2; i++) {
367       proc2 = smpi_group_index(group2, i);
368       proc1 = smpi_group_rank(group1, proc2);
369       if (proc1 == MPI_UNDEFINED) {
370         size++;
371       }
372     }
373     if (size == 0) {
374       *newgroup = MPI_GROUP_EMPTY;
375     } else {
376       *newgroup = smpi_group_new(size);
377       size2 = smpi_group_size(group1);
378       for (i = 0; i < size2; i++) {
379         proc1 = smpi_group_index(group1, i);
380         smpi_group_set_mapping(*newgroup, proc1, i);
381       }
382       for (i = size2; i < size; i++) {
383         proc2 = smpi_group_index(group2, i - size2);
384         smpi_group_set_mapping(*newgroup, proc2, i);
385       }
386     }
387     smpi_group_use(*newgroup);
388     retval = MPI_SUCCESS;
389   }
390   smpi_bench_begin();
391   return retval;
392 }
393
394 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
395                            MPI_Group * newgroup)
396 {
397   int retval, i, proc1, proc2, size, size2;
398
399   smpi_bench_end();
400   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
401     retval = MPI_ERR_GROUP;
402   } else if (newgroup == NULL) {
403     retval = MPI_ERR_ARG;
404   } else {
405     size = smpi_group_size(group1);
406     size2 = smpi_group_size(group2);
407     for (i = 0; i < size2; i++) {
408       proc2 = smpi_group_index(group2, i);
409       proc1 = smpi_group_rank(group1, proc2);
410       if (proc1 == MPI_UNDEFINED) {
411         size--;
412       }
413     }
414     if (size == 0) {
415       *newgroup = MPI_GROUP_EMPTY;
416     } else {
417       *newgroup = smpi_group_new(size);
418       size2 = smpi_group_size(group1);
419       for (i = 0; i < size2; i++) {
420         proc1 = smpi_group_index(group1, i);
421         proc2 = smpi_group_rank(group2, proc1);
422         if (proc2 != MPI_UNDEFINED) {
423           smpi_group_set_mapping(*newgroup, proc1, i);
424         }
425       }
426     }
427     smpi_group_use(*newgroup);
428     retval = MPI_SUCCESS;
429   }
430   smpi_bench_begin();
431   return retval;
432 }
433
434 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
435 {
436   int retval, i, proc1, proc2, size, size2;
437
438   smpi_bench_end();
439   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
440     retval = MPI_ERR_GROUP;
441   } else if (newgroup == NULL) {
442     retval = MPI_ERR_ARG;
443   } else {
444     size = size2 = smpi_group_size(group1);
445     for (i = 0; i < size2; i++) {
446       proc1 = smpi_group_index(group1, i);
447       proc2 = smpi_group_rank(group2, proc1);
448       if (proc2 != MPI_UNDEFINED) {
449         size--;
450       }
451     }
452     if (size == 0) {
453       *newgroup = MPI_GROUP_EMPTY;
454     } else {
455       *newgroup = smpi_group_new(size);
456       for (i = 0; i < size2; i++) {
457         proc1 = smpi_group_index(group1, i);
458         proc2 = smpi_group_rank(group2, proc1);
459         if (proc2 == MPI_UNDEFINED) {
460           smpi_group_set_mapping(*newgroup, proc1, i);
461         }
462       }
463     }
464     smpi_group_use(*newgroup);
465     retval = MPI_SUCCESS;
466   }
467   smpi_bench_begin();
468   return retval;
469 }
470
471 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
472 {
473   int retval, i, index;
474
475   smpi_bench_end();
476   if (group == MPI_GROUP_NULL) {
477     retval = MPI_ERR_GROUP;
478   } else if (newgroup == NULL) {
479     retval = MPI_ERR_ARG;
480   } else {
481     if (n == 0) {
482       *newgroup = MPI_GROUP_EMPTY;
483     } else if (n == smpi_group_size(group)) {
484       *newgroup = group;
485     } else {
486       *newgroup = smpi_group_new(n);
487       for (i = 0; i < n; i++) {
488         index = smpi_group_index(group, ranks[i]);
489         smpi_group_set_mapping(*newgroup, index, i);
490       }
491     }
492     smpi_group_use(*newgroup);
493     retval = MPI_SUCCESS;
494   }
495   smpi_bench_begin();
496   return retval;
497 }
498
499 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
500 {
501   int retval, i, size, rank, index;
502
503   smpi_bench_end();
504   if (group == MPI_GROUP_NULL) {
505     retval = MPI_ERR_GROUP;
506   } else if (newgroup == NULL) {
507     retval = MPI_ERR_ARG;
508   } else {
509     if (n == 0) {
510       *newgroup = group;
511     } else if (n == smpi_group_size(group)) {
512       *newgroup = MPI_GROUP_EMPTY;
513     } else {
514       size = smpi_group_size(group) - n;
515       *newgroup = smpi_group_new(size);
516       rank = 0;
517       while (rank < size) {
518         for (i = 0; i < n; i++) {
519           if (ranks[i] == rank) {
520             break;
521           }
522         }
523         if (i >= n) {
524           index = smpi_group_index(group, rank);
525           smpi_group_set_mapping(*newgroup, index, rank);
526           
527         }
528         rank++;
529       }
530     }
531     smpi_group_use(*newgroup);
532     retval = MPI_SUCCESS;
533   }
534   smpi_bench_begin();
535   return retval;
536 }
537
538 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
539                          MPI_Group * newgroup)
540 {
541   int retval, i, j, rank, size, index;
542
543   smpi_bench_end();
544   if (group == MPI_GROUP_NULL) {
545     retval = MPI_ERR_GROUP;
546   } else if (newgroup == NULL) {
547     retval = MPI_ERR_ARG;
548   } else {
549     if (n == 0) {
550       *newgroup = MPI_GROUP_EMPTY;
551     } else {
552       size = 0;
553       for (i = 0; i < n; i++) {
554         for (rank = ranges[i][0];       /* First */
555              rank >= 0 && rank <= ranges[i][1]; /* Last */
556              rank += ranges[i][2] /* Stride */ ) {
557           size++;
558         }
559       }
560       if (size == smpi_group_size(group)) {
561         *newgroup = group;
562       } else {
563         *newgroup = smpi_group_new(size);
564         j = 0;
565         for (i = 0; i < n; i++) {
566           for (rank = ranges[i][0];     /* First */
567                rank >= 0 && rank <= ranges[i][1];       /* Last */
568                rank += ranges[i][2] /* Stride */ ) {
569             index = smpi_group_index(group, rank);
570             smpi_group_set_mapping(*newgroup, index, j);
571             j++;
572           }
573         }
574       }
575     }
576     smpi_group_use(*newgroup);
577     retval = MPI_SUCCESS;
578   }
579   smpi_bench_begin();
580   return retval;
581 }
582
583 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
584                          MPI_Group * newgroup)
585 {
586   int retval, i, newrank, rank, size, index, add;
587
588   smpi_bench_end();
589   if (group == MPI_GROUP_NULL) {
590     retval = MPI_ERR_GROUP;
591   } else if (newgroup == NULL) {
592     retval = MPI_ERR_ARG;
593   } else {
594     if (n == 0) {
595       *newgroup = group;
596     } else {
597       size = smpi_group_size(group);
598       for (i = 0; i < n; i++) {
599         for (rank = ranges[i][0];       /* First */
600              rank >= 0 && rank <= ranges[i][1]; /* Last */
601              rank += ranges[i][2] /* Stride */ ) {
602           size--;
603         }
604       }
605       if (size == 0) {
606         *newgroup = MPI_GROUP_EMPTY;
607       } else {
608         *newgroup = smpi_group_new(size);
609         newrank = 0;
610         while (newrank < size) {
611           for (i = 0; i < n; i++) {
612             add = 1;
613             for (rank = ranges[i][0];   /* First */
614                  rank >= 0 && rank <= ranges[i][1];     /* Last */
615                  rank += ranges[i][2] /* Stride */ ) {
616               if (rank == newrank) {
617                 add = 0;
618                 break;
619               }
620             }
621             if (add == 1) {
622               index = smpi_group_index(group, newrank);
623               smpi_group_set_mapping(*newgroup, index, newrank);
624             }
625           }
626           newrank++; //added to avoid looping, need to be checked ..
627         }
628       }
629     }
630     smpi_group_use(*newgroup);
631     retval = MPI_SUCCESS;
632   }
633   smpi_bench_begin();
634   return retval;
635 }
636
637 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
638 {
639   int retval;
640
641   smpi_bench_end();
642   if (comm == MPI_COMM_NULL) {
643     retval = MPI_ERR_COMM;
644   } else if (rank == NULL) {
645     retval = MPI_ERR_ARG;
646   } else {
647     *rank = smpi_comm_rank(comm);
648     retval = MPI_SUCCESS;
649   }
650   smpi_bench_begin();
651   return retval;
652 }
653
654 int PMPI_Comm_size(MPI_Comm comm, int *size)
655 {
656   int retval;
657
658   smpi_bench_end();
659   if (comm == MPI_COMM_NULL) {
660     retval = MPI_ERR_COMM;
661   } else if (size == NULL) {
662     retval = MPI_ERR_ARG;
663   } else {
664     *size = smpi_comm_size(comm);
665     retval = MPI_SUCCESS;
666   }
667   smpi_bench_begin();
668   return retval;
669 }
670
671 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
672 {
673   int retval;
674
675   smpi_bench_end();
676   if (comm == MPI_COMM_NULL)  {
677     retval = MPI_ERR_COMM;
678   } else if (name == NULL || len == NULL)  {
679     retval = MPI_ERR_ARG;
680   } else {
681     smpi_comm_get_name(comm, name, len);
682     retval = MPI_SUCCESS;
683   }
684   smpi_bench_begin();
685   return retval;
686 }
687
688 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
689 {
690   int retval;
691
692   smpi_bench_end();
693   if (comm == MPI_COMM_NULL) {
694     retval = MPI_ERR_COMM;
695   } else if (group == NULL) {
696     retval = MPI_ERR_ARG;
697   } else {
698     *group = smpi_comm_group(comm);
699     retval = MPI_SUCCESS;
700   }
701   smpi_bench_begin();
702   return retval;
703 }
704
705 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
706 {
707   int retval;
708
709   smpi_bench_end();
710   if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
711     retval = MPI_ERR_COMM;
712   } else if (result == NULL) {
713     retval = MPI_ERR_ARG;
714   } else {
715     if (comm1 == comm2) {       /* Same communicators means same groups */
716       *result = MPI_IDENT;
717     } else {
718       *result =
719           smpi_group_compare(smpi_comm_group(comm1),
720                              smpi_comm_group(comm2));
721       if (*result == MPI_IDENT) {
722         *result = MPI_CONGRUENT;
723       }
724     }
725     retval = MPI_SUCCESS;
726   }
727   smpi_bench_begin();
728   return retval;
729 }
730
731 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
732 {
733   int retval;
734
735   smpi_bench_end();
736   if (comm == MPI_COMM_NULL) {
737     retval = MPI_ERR_COMM;
738   } else if (newcomm == NULL) {
739     retval = MPI_ERR_ARG;
740   } else {
741     *newcomm = smpi_comm_new(smpi_comm_group(comm));
742     retval = MPI_SUCCESS;
743   }
744   smpi_bench_begin();
745   return retval;
746 }
747
748 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
749 {
750   int retval;
751
752   smpi_bench_end();
753   if (comm == MPI_COMM_NULL) {
754     retval = MPI_ERR_COMM;
755   } else if (group == MPI_GROUP_NULL) {
756     retval = MPI_ERR_GROUP;
757   } else if (newcomm == NULL) {
758     retval = MPI_ERR_ARG;
759   } else {
760     *newcomm = smpi_comm_new(group);
761     retval = MPI_SUCCESS;
762   }
763   smpi_bench_begin();
764   return retval;
765 }
766
767 int PMPI_Comm_free(MPI_Comm * comm)
768 {
769   int retval;
770
771   smpi_bench_end();
772   if (comm == NULL) {
773     retval = MPI_ERR_ARG;
774   } else if (*comm == MPI_COMM_NULL) {
775     retval = MPI_ERR_COMM;
776   } else {
777     smpi_comm_destroy(*comm);
778     *comm = MPI_COMM_NULL;
779     retval = MPI_SUCCESS;
780   }
781   smpi_bench_begin();
782   return retval;
783 }
784
785 int PMPI_Comm_disconnect(MPI_Comm * comm)
786 {
787   /* TODO: wait until all communication in comm are done */
788   int retval;
789
790   smpi_bench_end();
791   if (comm == NULL) {
792     retval = MPI_ERR_ARG;
793   } else if (*comm == MPI_COMM_NULL) {
794     retval = MPI_ERR_COMM;
795   } else {
796     smpi_comm_destroy(*comm);
797     *comm = MPI_COMM_NULL;
798     retval = MPI_SUCCESS;
799   }
800   smpi_bench_begin();
801   return retval;
802 }
803
804 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
805 {
806   int retval;
807
808   smpi_bench_end();
809   if (comm_out == NULL) {
810     retval = MPI_ERR_ARG;
811   } else if (comm == MPI_COMM_NULL) {
812     retval = MPI_ERR_COMM;
813   } else {
814     *comm_out = smpi_comm_split(comm, color, key);
815     retval = MPI_SUCCESS;
816   }
817   smpi_bench_begin();
818   return retval;
819 }
820
821 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
822                   int tag, MPI_Comm comm, MPI_Request * request)
823 {
824   int retval;
825
826   smpi_bench_end();
827   if (request == NULL) {
828     retval = MPI_ERR_ARG;
829   } else if (comm == MPI_COMM_NULL) {
830     retval = MPI_ERR_COMM;
831   } else if (dst == MPI_PROC_NULL) {
832     retval = MPI_SUCCESS;
833   } else {
834     *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
835     retval = MPI_SUCCESS;
836   }
837   smpi_bench_begin();
838   return retval;
839 }
840
841 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
842                   int tag, MPI_Comm comm, MPI_Request * request)
843 {
844   int retval;
845
846   smpi_bench_end();
847   if (request == NULL) {
848     retval = MPI_ERR_ARG;
849   } else if (comm == MPI_COMM_NULL) {
850     retval = MPI_ERR_COMM;
851   } else if (src == MPI_PROC_NULL) {
852       retval = MPI_SUCCESS;
853   } else {
854     *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
855     retval = MPI_SUCCESS;
856   }
857   smpi_bench_begin();
858   return retval;
859 }
860
861 int PMPI_Start(MPI_Request * request)
862 {
863   int retval;
864
865   smpi_bench_end();
866   if (request == NULL || *request == MPI_REQUEST_NULL) {
867     retval = MPI_ERR_ARG;
868   } else {
869     smpi_mpi_start(*request);
870     retval = MPI_SUCCESS;
871   }
872   smpi_bench_begin();
873   return retval;
874 }
875
876 int PMPI_Startall(int count, MPI_Request * requests)
877 {
878   int retval;
879
880   smpi_bench_end();
881   if (requests == NULL) {
882     retval = MPI_ERR_ARG;
883   } else {
884     smpi_mpi_startall(count, requests);
885     retval = MPI_SUCCESS;
886   }
887   smpi_bench_begin();
888   return retval;
889 }
890
891 int PMPI_Request_free(MPI_Request * request)
892 {
893   int retval;
894
895   smpi_bench_end();
896   if (request == MPI_REQUEST_NULL) {
897     retval = MPI_ERR_ARG;
898   } else {
899     smpi_mpi_request_free(request);
900     retval = MPI_SUCCESS;
901   }
902   smpi_bench_begin();
903   return retval;
904 }
905
906 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
907               int tag, MPI_Comm comm, MPI_Request * request)
908 {
909   int retval;
910
911   smpi_bench_end();
912
913   if (request == NULL) {
914     retval = MPI_ERR_ARG;
915   } else if (comm == MPI_COMM_NULL) {
916     retval = MPI_ERR_COMM;
917   } else if (src == MPI_PROC_NULL) {
918     *request = MPI_REQUEST_NULL;
919     retval = MPI_SUCCESS;
920   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
921     retval = MPI_ERR_COMM;
922   } else if (count < 0) {
923     retval = MPI_ERR_COUNT;
924   } else if (buf==NULL && count > 0) {
925     retval = MPI_ERR_COUNT;
926   } else if (datatype == MPI_DATATYPE_NULL){
927     retval = MPI_ERR_TYPE;
928   } else if(tag<0 && tag !=  MPI_ANY_TAG){
929     retval = MPI_ERR_TAG;
930   } else {
931
932 #ifdef HAVE_TRACING
933   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
934   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
935   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
936 #endif
937
938     *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
939     retval = MPI_SUCCESS;
940
941 #ifdef HAVE_TRACING
942   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
943   (*request)->recv = 1;
944 #endif
945   }
946
947   smpi_bench_begin();
948   return retval;
949 }
950
951
952 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
953               int tag, MPI_Comm comm, MPI_Request * request)
954 {
955   int retval;
956
957   smpi_bench_end();
958   if (request == NULL) {
959     retval = MPI_ERR_ARG;
960   } else if (comm == MPI_COMM_NULL) {
961     retval = MPI_ERR_COMM;
962   } else if (dst == MPI_PROC_NULL) {
963     *request = MPI_REQUEST_NULL;
964     retval = MPI_SUCCESS;
965   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
966     retval = MPI_ERR_COMM;
967   } else if (count < 0) {
968     retval = MPI_ERR_COUNT;
969   } else if (buf==NULL && count > 0) {
970     retval = MPI_ERR_COUNT;
971   } else if (datatype == MPI_DATATYPE_NULL){
972     retval = MPI_ERR_TYPE;
973   } else if(tag<0 && tag !=  MPI_ANY_TAG){
974     retval = MPI_ERR_TAG;
975   } else {
976
977 #ifdef HAVE_TRACING
978   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
979   TRACE_smpi_computing_out(rank);
980   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
981   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
982   TRACE_smpi_send(rank, rank, dst_traced);
983 #endif
984
985     *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
986     retval = MPI_SUCCESS;
987
988 #ifdef HAVE_TRACING
989   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
990   (*request)->send = 1;
991   TRACE_smpi_computing_in(rank);
992 #endif
993   }
994
995   smpi_bench_begin();
996   return retval;
997 }
998
999
1000
1001 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1002              MPI_Comm comm, MPI_Status * status)
1003 {
1004   int retval;
1005
1006   smpi_bench_end();
1007
1008   if (comm == MPI_COMM_NULL) {
1009     retval = MPI_ERR_COMM;
1010   } else if (src == MPI_PROC_NULL) {
1011     smpi_empty_status(status);
1012     status->MPI_SOURCE = MPI_PROC_NULL;
1013     retval = MPI_SUCCESS;
1014   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1015     retval = MPI_ERR_COMM;
1016   } else if (count < 0) {
1017     retval = MPI_ERR_COUNT;
1018   } else if (buf==NULL && count > 0) {
1019     retval = MPI_ERR_COUNT;
1020   } else if (datatype == MPI_DATATYPE_NULL){
1021     retval = MPI_ERR_TYPE;
1022   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1023     retval = MPI_ERR_TAG;
1024   } else {
1025 #ifdef HAVE_TRACING
1026   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1027   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1028   TRACE_smpi_computing_out(rank);
1029
1030   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
1031 #endif
1032
1033     smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1034     retval = MPI_SUCCESS;
1035
1036 #ifdef HAVE_TRACING
1037   //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1038   if(status!=MPI_STATUS_IGNORE)src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1039   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1040   TRACE_smpi_recv(rank, src_traced, rank);
1041   TRACE_smpi_computing_in(rank);
1042 #endif
1043   }
1044
1045   smpi_bench_begin();
1046   return retval;
1047 }
1048
1049 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1050              MPI_Comm comm)
1051 {
1052   int retval;
1053
1054   smpi_bench_end();
1055
1056   if (comm == MPI_COMM_NULL) {
1057     retval = MPI_ERR_COMM;
1058   } else if (dst == MPI_PROC_NULL) {
1059     retval = MPI_SUCCESS;
1060   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1061     retval = MPI_ERR_COMM;
1062   } else if (count < 0) {
1063     retval = MPI_ERR_COUNT;
1064   } else if (buf==NULL && count > 0) {
1065     retval = MPI_ERR_COUNT;
1066   } else if (datatype == MPI_DATATYPE_NULL){
1067     retval = MPI_ERR_TYPE;
1068   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1069     retval = MPI_ERR_TAG;
1070   } else {
1071
1072 #ifdef HAVE_TRACING
1073   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1074   TRACE_smpi_computing_out(rank);
1075   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1076   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1077   TRACE_smpi_send(rank, rank, dst_traced);
1078 #endif
1079
1080     smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1081     retval = MPI_SUCCESS;
1082
1083 #ifdef HAVE_TRACING
1084   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1085   TRACE_smpi_computing_in(rank);
1086 #endif
1087   }
1088
1089   smpi_bench_begin();
1090   return retval;
1091 }
1092
1093 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1094                  int dst, int sendtag, void *recvbuf, int recvcount,
1095                  MPI_Datatype recvtype, int src, int recvtag,
1096                  MPI_Comm comm, MPI_Status * status)
1097 {
1098   int retval;
1099
1100   smpi_bench_end();
1101
1102   if (comm == MPI_COMM_NULL) {
1103     retval = MPI_ERR_COMM;
1104   } else if (sendtype == MPI_DATATYPE_NULL
1105              || recvtype == MPI_DATATYPE_NULL) {
1106     retval = MPI_ERR_TYPE;
1107   } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1108       smpi_empty_status(status);
1109       status->MPI_SOURCE = MPI_PROC_NULL;
1110       retval = MPI_SUCCESS;
1111   }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1112       (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1113     retval = MPI_ERR_COMM;
1114   } else if (sendcount < 0 || recvcount<0) {
1115       retval = MPI_ERR_COUNT;
1116   } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1117     retval = MPI_ERR_COUNT;
1118   } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1119     retval = MPI_ERR_TAG;
1120   } else {
1121
1122 #ifdef HAVE_TRACING
1123   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1124   TRACE_smpi_computing_out(rank);
1125   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1126   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1127   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1128   TRACE_smpi_send(rank, rank, dst_traced);
1129   TRACE_smpi_send(rank, src_traced, rank);
1130 #endif
1131
1132
1133     smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1134                       recvcount, recvtype, src, recvtag, comm, status);
1135     retval = MPI_SUCCESS;
1136
1137 #ifdef HAVE_TRACING
1138   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1139   TRACE_smpi_recv(rank, rank, dst_traced);
1140   TRACE_smpi_recv(rank, src_traced, rank);
1141   TRACE_smpi_computing_in(rank);
1142 #endif
1143
1144   }
1145
1146   smpi_bench_begin();
1147   return retval;
1148 }
1149
1150 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1151                          int dst, int sendtag, int src, int recvtag,
1152                          MPI_Comm comm, MPI_Status * status)
1153 {
1154   //TODO: suboptimal implementation
1155   void *recvbuf;
1156   int retval;
1157   if ((datatype == MPI_DATATYPE_NULL)||(datatype->has_subtype==1)) {
1158       retval = MPI_ERR_TYPE;
1159   } else if (count < 0) {
1160       retval = MPI_ERR_COUNT;
1161   } else {
1162     int size = smpi_datatype_size(datatype) * count;
1163     recvbuf = xbt_new(char, size);
1164     retval =
1165         MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1166                      datatype, src, recvtag, comm, status);
1167     if(retval==MPI_SUCCESS){
1168         memcpy(buf, recvbuf, size * sizeof(char));
1169     }
1170     xbt_free(recvbuf);
1171
1172   }
1173   return retval;
1174 }
1175
1176 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1177 {
1178   int retval;
1179
1180   smpi_bench_end();
1181   if (request == MPI_REQUEST_NULL || flag == NULL) {
1182     retval = MPI_ERR_ARG;
1183   } else if (*request == MPI_REQUEST_NULL) {
1184     *flag= TRUE;
1185     retval = MPI_ERR_REQUEST;
1186   } else {
1187     *flag = smpi_mpi_test(request, status);
1188     retval = MPI_SUCCESS;
1189   }
1190   smpi_bench_begin();
1191   return retval;
1192 }
1193
1194 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1195                 MPI_Status * status)
1196 {
1197   int retval;
1198
1199   smpi_bench_end();
1200   if (index == NULL || flag == NULL) {
1201     retval = MPI_ERR_ARG;
1202   } else {
1203     *flag = smpi_mpi_testany(count, requests, index, status);
1204     retval = MPI_SUCCESS;
1205   }
1206   smpi_bench_begin();
1207   return retval;
1208 }
1209
1210 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1211 {
1212   int retval;
1213
1214   smpi_bench_end();
1215   if (flag == NULL) {
1216     retval = MPI_ERR_ARG;
1217   } else {
1218     *flag = smpi_mpi_testall(count, requests, statuses);
1219     retval = MPI_SUCCESS;
1220   }
1221   smpi_bench_begin();
1222   return retval;
1223 }
1224
1225 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1226   int retval;
1227   smpi_bench_end();
1228
1229   if (status == NULL) {
1230     retval = MPI_ERR_ARG;
1231   } else if (comm == MPI_COMM_NULL) {
1232     retval = MPI_ERR_COMM;
1233   } else if (source == MPI_PROC_NULL) {
1234     smpi_empty_status(status);
1235     status->MPI_SOURCE = MPI_PROC_NULL;
1236     retval = MPI_SUCCESS;
1237   } else {
1238     smpi_mpi_probe(source, tag, comm, status);
1239     retval = MPI_SUCCESS;
1240   }
1241   smpi_bench_begin();
1242   return retval;
1243 }
1244
1245
1246 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1247   int retval;
1248   smpi_bench_end();
1249
1250   if (flag == NULL) {
1251     retval = MPI_ERR_ARG;
1252   } else if (status == NULL) {
1253     retval = MPI_ERR_ARG;
1254   } else if (comm == MPI_COMM_NULL) {
1255     retval = MPI_ERR_COMM;
1256   } else if (source == MPI_PROC_NULL) {
1257     smpi_empty_status(status);
1258     status->MPI_SOURCE = MPI_PROC_NULL;
1259     retval = MPI_SUCCESS;
1260   } else {
1261     smpi_mpi_iprobe(source, tag, comm, flag, status);
1262     retval = MPI_SUCCESS;
1263   }
1264   smpi_bench_begin();
1265   return retval;
1266 }
1267
1268 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1269 {
1270   int retval;
1271
1272   smpi_bench_end();
1273
1274   if (request == NULL) {
1275     retval = MPI_ERR_ARG;
1276   } else if (*request == MPI_REQUEST_NULL) {
1277     retval = MPI_ERR_REQUEST;
1278   } else {
1279
1280 #ifdef HAVE_TRACING
1281   int rank = request && (*request)->comm != MPI_COMM_NULL
1282       ? smpi_process_index()
1283       : -1;
1284   TRACE_smpi_computing_out(rank);
1285
1286   MPI_Group group = smpi_comm_group((*request)->comm);
1287   int src_traced = smpi_group_index(group, (*request)->src);
1288   int dst_traced = smpi_group_index(group, (*request)->dst);
1289   int is_wait_for_receive = (*request)->recv;
1290   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1291 #endif
1292
1293     smpi_mpi_wait(request, status);
1294     retval = MPI_SUCCESS;
1295
1296 #ifdef HAVE_TRACING
1297   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1298   if (is_wait_for_receive) {
1299     TRACE_smpi_recv(rank, src_traced, dst_traced);
1300   }
1301   TRACE_smpi_computing_in(rank);
1302 #endif
1303
1304   }
1305
1306   smpi_bench_begin();
1307   return retval;
1308 }
1309
1310 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1311 {
1312   int retval;
1313
1314   smpi_bench_end();
1315 #ifdef HAVE_TRACING
1316   //save requests information for tracing
1317   int i;
1318   xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
1319   xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
1320   xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
1321   for (i = 0; i < count; i++) {
1322     MPI_Request req = requests[i];      //already received requests are no longer valid
1323     if (req) {
1324       int *asrc = xbt_new(int, 1);
1325       int *adst = xbt_new(int, 1);
1326       int *arecv = xbt_new(int, 1);
1327       *asrc = req->src;
1328       *adst = req->dst;
1329       *arecv = req->recv;
1330       xbt_dynar_insert_at(srcs, i, asrc);
1331       xbt_dynar_insert_at(dsts, i, adst);
1332       xbt_dynar_insert_at(recvs, i, arecv);
1333       xbt_free(asrc);
1334       xbt_free(adst);
1335       xbt_free(arecv);
1336     } else {
1337       int *t = xbt_new(int, 1);
1338       xbt_dynar_insert_at(srcs, i, t);
1339       xbt_dynar_insert_at(dsts, i, t);
1340       xbt_dynar_insert_at(recvs, i, t);
1341       xbt_free(t);
1342     }
1343   }
1344   int rank_traced = smpi_process_index();
1345   TRACE_smpi_computing_out(rank_traced);
1346
1347   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1348
1349 #endif
1350   if (index == NULL) {
1351     retval = MPI_ERR_ARG;
1352   } else {
1353     *index = smpi_mpi_waitany(count, requests, status);
1354     retval = MPI_SUCCESS;
1355   }
1356 #ifdef HAVE_TRACING
1357   if(*index!=MPI_UNDEFINED){
1358     int src_traced, dst_traced, is_wait_for_receive;
1359     xbt_dynar_get_cpy(srcs, *index, &src_traced);
1360     xbt_dynar_get_cpy(dsts, *index, &dst_traced);
1361     xbt_dynar_get_cpy(recvs, *index, &is_wait_for_receive);
1362     if (is_wait_for_receive) {
1363       TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1364     }
1365     TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1366     //clean-up of dynars
1367     xbt_dynar_free(&srcs);
1368     xbt_dynar_free(&dsts);
1369     xbt_dynar_free(&recvs);
1370   }
1371   TRACE_smpi_computing_in(rank_traced);
1372
1373
1374 #endif
1375   smpi_bench_begin();
1376   return retval;
1377 }
1378
1379 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1380 {
1381
1382   smpi_bench_end();
1383 #ifdef HAVE_TRACING
1384   //save information from requests
1385   int i;
1386   xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
1387   xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
1388   xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
1389   for (i = 0; i < count; i++) {
1390     MPI_Request req = requests[i];
1391     if(req){
1392       int *asrc = xbt_new(int, 1);
1393       int *adst = xbt_new(int, 1);
1394       int *arecv = xbt_new(int, 1);
1395       *asrc = req->src;
1396       *adst = req->dst;
1397       *arecv = req->recv;
1398       xbt_dynar_insert_at(srcs, i, asrc);
1399       xbt_dynar_insert_at(dsts, i, adst);
1400       xbt_dynar_insert_at(recvs, i, arecv);
1401       xbt_free(asrc);
1402       xbt_free(adst);
1403       xbt_free(arecv);
1404     }else {
1405       int *t = xbt_new(int, 1);
1406       xbt_dynar_insert_at(srcs, i, t);
1407       xbt_dynar_insert_at(dsts, i, t);
1408       xbt_dynar_insert_at(recvs, i, t);
1409       xbt_free(t);
1410     }
1411   }
1412   int rank_traced = smpi_process_index();
1413   TRACE_smpi_computing_out(rank_traced);
1414
1415   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1416 #endif
1417   int retval = smpi_mpi_waitall(count, requests, status);
1418 #ifdef HAVE_TRACING
1419   for (i = 0; i < count; i++) {
1420     int src_traced, dst_traced, is_wait_for_receive;
1421     xbt_dynar_get_cpy(srcs, i, &src_traced);
1422     xbt_dynar_get_cpy(dsts, i, &dst_traced);
1423     xbt_dynar_get_cpy(recvs, i, &is_wait_for_receive);
1424     if (is_wait_for_receive) {
1425       TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1426     }
1427   }
1428   TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1429   //clean-up of dynars
1430   xbt_dynar_free(&srcs);
1431   xbt_dynar_free(&dsts);
1432   xbt_dynar_free(&recvs);
1433   TRACE_smpi_computing_in(rank_traced);
1434 #endif
1435   smpi_bench_begin();
1436   return retval;
1437 }
1438
1439 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1440                  int *indices, MPI_Status status[])
1441 {
1442   int retval;
1443
1444   smpi_bench_end();
1445   if (outcount == NULL || indices == NULL) {
1446     retval = MPI_ERR_ARG;
1447   } else {
1448     *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1449     retval = MPI_SUCCESS;
1450   }
1451   smpi_bench_begin();
1452   return retval;
1453 }
1454
1455 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1456                  int* indices, MPI_Status status[])
1457 {
1458   int retval;
1459
1460    smpi_bench_end();
1461    if (outcount == NULL || indices == NULL) {
1462      retval = MPI_ERR_ARG;
1463    } else {
1464      *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1465      retval = MPI_SUCCESS;
1466    }
1467    smpi_bench_begin();
1468    return retval;
1469 }
1470
1471
1472 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1473 {
1474   int retval;
1475
1476   smpi_bench_end();
1477 #ifdef HAVE_TRACING
1478   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1479   TRACE_smpi_computing_out(rank);
1480   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1481   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1482 #endif
1483   if (comm == MPI_COMM_NULL) {
1484     retval = MPI_ERR_COMM;
1485   } else {
1486     smpi_mpi_bcast(buf, count, datatype, root, comm);
1487     retval = MPI_SUCCESS;
1488   }
1489 #ifdef HAVE_TRACING
1490   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1491   TRACE_smpi_computing_in(rank);
1492 #endif
1493   smpi_bench_begin();
1494   return retval;
1495 }
1496
1497 int PMPI_Barrier(MPI_Comm comm)
1498 {
1499   int retval;
1500
1501   smpi_bench_end();
1502 #ifdef HAVE_TRACING
1503   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1504   TRACE_smpi_computing_out(rank);
1505   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1506 #endif
1507   if (comm == MPI_COMM_NULL) {
1508     retval = MPI_ERR_COMM;
1509   } else {
1510     smpi_mpi_barrier(comm);
1511     retval = MPI_SUCCESS;
1512   }
1513 #ifdef HAVE_TRACING
1514   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1515   TRACE_smpi_computing_in(rank);
1516 #endif
1517   smpi_bench_begin();
1518   return retval;
1519 }
1520
1521 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1522                void *recvbuf, int recvcount, MPI_Datatype recvtype,
1523                int root, MPI_Comm comm)
1524 {
1525   int retval;
1526
1527   smpi_bench_end();
1528 #ifdef HAVE_TRACING
1529   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1530   TRACE_smpi_computing_out(rank);
1531   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1532   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1533 #endif
1534   if (comm == MPI_COMM_NULL) {
1535     retval = MPI_ERR_COMM;
1536   } else if (sendtype == MPI_DATATYPE_NULL
1537              || recvtype == MPI_DATATYPE_NULL) {
1538     retval = MPI_ERR_TYPE;
1539   } else {
1540     smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1541                     recvtype, root, comm);
1542     retval = MPI_SUCCESS;
1543   }
1544 #ifdef HAVE_TRACING
1545   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1546   TRACE_smpi_computing_in(rank);
1547 #endif
1548   smpi_bench_begin();
1549   return retval;
1550 }
1551
1552 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1553                 void *recvbuf, int *recvcounts, int *displs,
1554                 MPI_Datatype recvtype, int root, MPI_Comm comm)
1555 {
1556   int retval;
1557
1558   smpi_bench_end();
1559 #ifdef HAVE_TRACING
1560   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1561   TRACE_smpi_computing_out(rank);
1562   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1563   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1564 #endif
1565   if (comm == MPI_COMM_NULL) {
1566     retval = MPI_ERR_COMM;
1567   } else if (sendtype == MPI_DATATYPE_NULL
1568              || recvtype == MPI_DATATYPE_NULL) {
1569     retval = MPI_ERR_TYPE;
1570   } else if (recvcounts == NULL || displs == NULL) {
1571     retval = MPI_ERR_ARG;
1572   } else {
1573     smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1574                      displs, recvtype, root, comm);
1575     retval = MPI_SUCCESS;
1576   }
1577 #ifdef HAVE_TRACING
1578   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1579   TRACE_smpi_computing_in(rank);
1580 #endif
1581   smpi_bench_begin();
1582   return retval;
1583 }
1584
1585 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1586                   void *recvbuf, int recvcount, MPI_Datatype recvtype,
1587                   MPI_Comm comm)
1588 {
1589   int retval;
1590
1591   smpi_bench_end();
1592 #ifdef HAVE_TRACING
1593   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1594   TRACE_smpi_computing_out(rank);
1595   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1596 #endif
1597   if (comm == MPI_COMM_NULL) {
1598     retval = MPI_ERR_COMM;
1599   } else if (sendtype == MPI_DATATYPE_NULL
1600              || recvtype == MPI_DATATYPE_NULL) {
1601     retval = MPI_ERR_TYPE;
1602   } else {
1603     smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1604                        recvtype, comm);
1605     retval = MPI_SUCCESS;
1606   }
1607 #ifdef HAVE_TRACING
1608   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1609 #endif
1610   smpi_bench_begin();
1611   return retval;
1612 }
1613
1614 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1615                    void *recvbuf, int *recvcounts, int *displs,
1616                    MPI_Datatype recvtype, MPI_Comm comm)
1617 {
1618   int retval;
1619
1620   smpi_bench_end();
1621 #ifdef HAVE_TRACING
1622   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1623   TRACE_smpi_computing_out(rank);
1624   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1625 #endif
1626   if (comm == MPI_COMM_NULL) {
1627     retval = MPI_ERR_COMM;
1628   } else if (sendtype == MPI_DATATYPE_NULL
1629              || recvtype == MPI_DATATYPE_NULL) {
1630     retval = MPI_ERR_TYPE;
1631   } else if (recvcounts == NULL || displs == NULL) {
1632     retval = MPI_ERR_ARG;
1633   } else {
1634     smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1635                         displs, recvtype, comm);
1636     retval = MPI_SUCCESS;
1637   }
1638 #ifdef HAVE_TRACING
1639   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1640   TRACE_smpi_computing_in(rank);
1641 #endif
1642   smpi_bench_begin();
1643   return retval;
1644 }
1645
1646 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1647                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1648                 int root, MPI_Comm comm)
1649 {
1650   int retval;
1651
1652   smpi_bench_end();
1653 #ifdef HAVE_TRACING
1654   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1655   TRACE_smpi_computing_out(rank);
1656   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1657
1658   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1659 #endif
1660   if (comm == MPI_COMM_NULL) {
1661     retval = MPI_ERR_COMM;
1662   } else if (sendtype == MPI_DATATYPE_NULL
1663              || recvtype == MPI_DATATYPE_NULL) {
1664     retval = MPI_ERR_TYPE;
1665   } else {
1666     smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1667                      recvtype, root, comm);
1668     retval = MPI_SUCCESS;
1669   }
1670 #ifdef HAVE_TRACING
1671   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1672   TRACE_smpi_computing_in(rank);
1673 #endif
1674   smpi_bench_begin();
1675   return retval;
1676 }
1677
1678 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1679                  MPI_Datatype sendtype, void *recvbuf, int recvcount,
1680                  MPI_Datatype recvtype, int root, MPI_Comm comm)
1681 {
1682   int retval;
1683
1684   smpi_bench_end();
1685 #ifdef HAVE_TRACING
1686   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1687   TRACE_smpi_computing_out(rank);
1688   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1689   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1690 #endif
1691   if (comm == MPI_COMM_NULL) {
1692     retval = MPI_ERR_COMM;
1693   } else if (sendtype == MPI_DATATYPE_NULL
1694              || recvtype == MPI_DATATYPE_NULL) {
1695     retval = MPI_ERR_TYPE;
1696   } else if (sendcounts == NULL || displs == NULL) {
1697     retval = MPI_ERR_ARG;
1698   } else {
1699     smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
1700                       recvcount, recvtype, root, comm);
1701     retval = MPI_SUCCESS;
1702   }
1703 #ifdef HAVE_TRACING
1704   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1705   TRACE_smpi_computing_in(rank);
1706 #endif
1707   smpi_bench_begin();
1708   return retval;
1709 }
1710
1711 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
1712                MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1713 {
1714   int retval;
1715
1716   smpi_bench_end();
1717 #ifdef HAVE_TRACING
1718   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1719   TRACE_smpi_computing_out(rank);
1720   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1721   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1722 #endif
1723   if (comm == MPI_COMM_NULL) {
1724     retval = MPI_ERR_COMM;
1725   } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
1726     retval = MPI_ERR_ARG;
1727   } else {
1728     smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
1729     retval = MPI_SUCCESS;
1730   }
1731 #ifdef HAVE_TRACING
1732   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1733   TRACE_smpi_computing_in(rank);
1734 #endif
1735   smpi_bench_begin();
1736   return retval;
1737 }
1738
1739 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
1740                   MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1741 {
1742   int retval;
1743
1744   smpi_bench_end();
1745 #ifdef HAVE_TRACING
1746   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1747   TRACE_smpi_computing_out(rank);
1748   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1749 #endif
1750   if (comm == MPI_COMM_NULL) {
1751     retval = MPI_ERR_COMM;
1752   } else if (datatype == MPI_DATATYPE_NULL) {
1753     retval = MPI_ERR_TYPE;
1754   } else if (op == MPI_OP_NULL) {
1755     retval = MPI_ERR_OP;
1756   } else {
1757     smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
1758     retval = MPI_SUCCESS;
1759   }
1760 #ifdef HAVE_TRACING
1761   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1762   TRACE_smpi_computing_in(rank);
1763 #endif
1764   smpi_bench_begin();
1765   return retval;
1766 }
1767
1768 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
1769              MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1770 {
1771   int retval;
1772
1773   smpi_bench_end();
1774 #ifdef HAVE_TRACING
1775   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1776   TRACE_smpi_computing_out(rank);
1777   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1778 #endif
1779   if (comm == MPI_COMM_NULL) {
1780     retval = MPI_ERR_COMM;
1781   } else if (datatype == MPI_DATATYPE_NULL) {
1782     retval = MPI_ERR_TYPE;
1783   } else if (op == MPI_OP_NULL) {
1784     retval = MPI_ERR_OP;
1785   } else {
1786     smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
1787     retval = MPI_SUCCESS;
1788   }
1789 #ifdef HAVE_TRACING
1790   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1791   TRACE_smpi_computing_in(rank);
1792 #endif
1793   smpi_bench_begin();
1794   return retval;
1795 }
1796
1797 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
1798                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1799 {
1800   int retval, i, size, count;
1801   int *displs;
1802   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1803
1804   smpi_bench_end();
1805 #ifdef HAVE_TRACING
1806   TRACE_smpi_computing_out(rank);
1807   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1808 #endif
1809   if (comm == MPI_COMM_NULL) {
1810     retval = MPI_ERR_COMM;
1811   } else if (datatype == MPI_DATATYPE_NULL) {
1812     retval = MPI_ERR_TYPE;
1813   } else if (op == MPI_OP_NULL) {
1814     retval = MPI_ERR_OP;
1815   } else if (recvcounts == NULL) {
1816     retval = MPI_ERR_ARG;
1817   } else {
1818     /* arbitrarily choose root as rank 0 */
1819     /* TODO: faster direct implementation ? */
1820     size = smpi_comm_size(comm);
1821     count = 0;
1822     displs = xbt_new(int, size);
1823     for (i = 0; i < size; i++) {
1824       count += recvcounts[i];
1825       displs[i] = 0;
1826     }
1827     smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
1828     smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf,
1829                       recvcounts[rank], datatype, 0, comm);
1830     xbt_free(displs);
1831     retval = MPI_SUCCESS;
1832   }
1833 #ifdef HAVE_TRACING
1834   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1835   TRACE_smpi_computing_in(rank);
1836 #endif
1837   smpi_bench_begin();
1838   return retval;
1839 }
1840
1841 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1842                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
1843                  MPI_Comm comm)
1844 {
1845   int retval, size, sendsize;
1846
1847   smpi_bench_end();
1848 #ifdef HAVE_TRACING
1849   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1850   TRACE_smpi_computing_out(rank);
1851   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1852 #endif
1853   if (comm == MPI_COMM_NULL) {
1854     retval = MPI_ERR_COMM;
1855   } else if (sendtype == MPI_DATATYPE_NULL
1856              || recvtype == MPI_DATATYPE_NULL) {
1857     retval = MPI_ERR_TYPE;
1858   } else {
1859     size = smpi_comm_size(comm);
1860     sendsize = smpi_datatype_size(sendtype) * sendcount;
1861     if (sendsize < 200 && size > 12) {
1862       retval =
1863           smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype,
1864                                          recvbuf, recvcount, recvtype,
1865                                          comm);
1866     } else if (sendsize < 3000) {
1867       retval =
1868           smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount,
1869                                                 sendtype, recvbuf,
1870                                                 recvcount, recvtype, comm);
1871     } else {
1872       retval =
1873           smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype,
1874                                             recvbuf, recvcount, recvtype,
1875                                             comm);
1876     }
1877   }
1878 #ifdef HAVE_TRACING
1879   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1880   TRACE_smpi_computing_in(rank);
1881 #endif
1882   smpi_bench_begin();
1883   return retval;
1884 }
1885
1886 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
1887                   MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
1888                   int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
1889 {
1890   int retval;
1891
1892   smpi_bench_end();
1893 #ifdef HAVE_TRACING
1894   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1895   TRACE_smpi_computing_out(rank);
1896   TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1897 #endif
1898   if (comm == MPI_COMM_NULL) {
1899     retval = MPI_ERR_COMM;
1900   } else if (sendtype == MPI_DATATYPE_NULL
1901              || recvtype == MPI_DATATYPE_NULL) {
1902     retval = MPI_ERR_TYPE;
1903   } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
1904              || recvdisps == NULL) {
1905     retval = MPI_ERR_ARG;
1906   } else {
1907     retval =
1908         smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype,
1909                                   recvbuf, recvcounts, recvdisps, recvtype,
1910                                   comm);
1911   }
1912 #ifdef HAVE_TRACING
1913   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1914   TRACE_smpi_computing_in(rank);
1915 #endif
1916   smpi_bench_begin();
1917   return retval;
1918 }
1919
1920
1921 int PMPI_Get_processor_name(char *name, int *resultlen)
1922 {
1923   int retval = MPI_SUCCESS;
1924
1925   smpi_bench_end();
1926   strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
1927           strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
1928           strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
1929           MPI_MAX_PROCESSOR_NAME - 1 );
1930   *resultlen =
1931       strlen(name) >
1932       MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
1933
1934   smpi_bench_begin();
1935   return retval;
1936 }
1937
1938 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
1939 {
1940   int retval = MPI_SUCCESS;
1941   size_t size;
1942
1943   smpi_bench_end();
1944   if (status == NULL || count == NULL) {
1945     retval = MPI_ERR_ARG;
1946   } else if (datatype == MPI_DATATYPE_NULL) {
1947     retval = MPI_ERR_TYPE;
1948   } else {
1949     size = smpi_datatype_size(datatype);
1950     if (size == 0) {
1951       *count = 0;
1952     } else if (status->count % size != 0) {
1953       retval = MPI_UNDEFINED;
1954     } else {
1955       *count = smpi_mpi_get_count(status, datatype);
1956     }
1957   }
1958   smpi_bench_begin();
1959   return retval;
1960 }
1961
1962 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
1963   int retval;
1964
1965   smpi_bench_end();
1966   if (old_type == MPI_DATATYPE_NULL) {
1967     retval = MPI_ERR_TYPE;
1968   } else if (count<0){
1969     retval = MPI_ERR_COUNT;
1970   } else {
1971     retval = smpi_datatype_contiguous(count, old_type, new_type);
1972   }
1973   smpi_bench_begin();
1974   return retval;
1975 }
1976
1977 int PMPI_Type_commit(MPI_Datatype* datatype) {
1978   int retval;
1979
1980   smpi_bench_end();
1981   if (datatype == MPI_DATATYPE_NULL) {
1982     retval = MPI_ERR_TYPE;
1983   } else {
1984     smpi_datatype_commit(datatype);
1985     retval = MPI_SUCCESS;
1986   }
1987   smpi_bench_begin();
1988   return retval;
1989 }
1990
1991
1992 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
1993   int retval;
1994
1995   smpi_bench_end();
1996   if (old_type == MPI_DATATYPE_NULL) {
1997     retval = MPI_ERR_TYPE;
1998   } else if (count<0 || blocklen<0){
1999     retval = MPI_ERR_COUNT;
2000   } else {
2001     retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2002   }
2003   smpi_bench_begin();
2004   return retval;
2005 }
2006
2007 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2008   int retval;
2009
2010   smpi_bench_end();
2011   if (old_type == MPI_DATATYPE_NULL) {
2012     retval = MPI_ERR_TYPE;
2013   } else if (count<0 || blocklen<0){
2014     retval = MPI_ERR_COUNT;
2015   } else {
2016     retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2017   }
2018   smpi_bench_begin();
2019   return retval;
2020 }
2021
2022
2023 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2024   int retval;
2025
2026   smpi_bench_end();
2027   if (old_type == MPI_DATATYPE_NULL) {
2028     retval = MPI_ERR_TYPE;
2029   } else if (count<0){
2030     retval = MPI_ERR_COUNT;
2031   } else {
2032     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2033   }
2034   smpi_bench_begin();
2035   return retval;
2036 }
2037
2038 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2039   int retval;
2040
2041   smpi_bench_end();
2042   if (old_type == MPI_DATATYPE_NULL) {
2043     retval = MPI_ERR_TYPE;
2044   } else if (count<0){
2045     retval = MPI_ERR_COUNT;
2046   } else {
2047     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2048   }
2049   smpi_bench_begin();
2050   return retval;
2051 }
2052
2053
2054 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2055   int retval;
2056
2057   smpi_bench_end();
2058   if (count<0){
2059     retval = MPI_ERR_COUNT;
2060   } else {
2061     retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2062   }
2063   smpi_bench_begin();
2064   return retval;}
2065
2066 int PMPI_Error_class(int errorcode, int* errorclass) {
2067   // assume smpi uses only standard mpi error codes
2068   *errorclass=errorcode;
2069   return MPI_SUCCESS;
2070 }
2071
2072 /* The following calls are not yet implemented and will fail at runtime. */
2073 /* Once implemented, please move them above this notice. */
2074
2075 static int not_yet_implemented(void) {
2076           XBT_WARN("Not yet implemented");
2077    return MPI_SUCCESS;
2078 }
2079
2080 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2081    return not_yet_implemented();
2082 }
2083
2084 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2085    return not_yet_implemented();
2086 }
2087
2088 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periods, int reorder, MPI_Comm* comm_cart) {
2089    return not_yet_implemented();
2090 }
2091
2092 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2093    return not_yet_implemented();
2094 }
2095
2096 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2097    return not_yet_implemented();
2098 }
2099
2100 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2101    return not_yet_implemented();
2102 }
2103
2104 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2105    return not_yet_implemented();
2106 }
2107
2108 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2109    return not_yet_implemented();
2110 }
2111
2112 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2113    return not_yet_implemented();
2114 }
2115
2116 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2117    return not_yet_implemented();
2118 }
2119
2120 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2121    return not_yet_implemented();
2122 }
2123
2124 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2125    return not_yet_implemented();
2126 }
2127
2128 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2129    return not_yet_implemented();
2130 }
2131
2132 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2133    return not_yet_implemented();
2134 }
2135
2136 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2137    return not_yet_implemented();
2138 }
2139
2140 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2141    return not_yet_implemented();
2142 }
2143
2144 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2145    return not_yet_implemented();
2146 }
2147
2148 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2149    return not_yet_implemented();
2150 }
2151
2152 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2153    return not_yet_implemented();
2154 }
2155
2156 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2157    return not_yet_implemented();
2158 }
2159
2160 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2161    return not_yet_implemented();
2162 }
2163
2164
2165 int PMPI_Cancel(MPI_Request* request) {
2166    return not_yet_implemented();
2167 }
2168
2169 int PMPI_Buffer_attach(void* buffer, int size) {
2170    return not_yet_implemented();
2171 }
2172
2173 int PMPI_Buffer_detach(void* buffer, int* size) {
2174    return not_yet_implemented();
2175 }
2176
2177 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2178    return not_yet_implemented();
2179 }
2180
2181 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2182 {
2183    return not_yet_implemented();
2184 }
2185
2186 int PMPI_Pcontrol(const int level )
2187 {
2188    return not_yet_implemented();
2189 }
2190
2191 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2192    return not_yet_implemented();
2193 }
2194
2195 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2196    return not_yet_implemented();
2197 }
2198
2199 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2200    return not_yet_implemented();
2201 }
2202
2203 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2204    return not_yet_implemented();
2205 }
2206
2207 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2208    return not_yet_implemented();
2209 }
2210
2211 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2212    return not_yet_implemented();
2213 }
2214
2215 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2216    return not_yet_implemented();
2217 }
2218
2219 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2220    return not_yet_implemented();
2221 }
2222
2223 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2224    return not_yet_implemented();
2225 }
2226
2227 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2228    return not_yet_implemented();
2229 }
2230
2231 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2232    return not_yet_implemented();
2233 }
2234
2235
2236 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2237    return not_yet_implemented();
2238 }
2239
2240 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2241    return not_yet_implemented();
2242 }
2243
2244 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2245    return not_yet_implemented();
2246 }
2247
2248 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2249    return not_yet_implemented();
2250 }
2251
2252 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2253    return not_yet_implemented();
2254 }
2255
2256 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2257    return not_yet_implemented();
2258 }
2259
2260 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2261    return not_yet_implemented();
2262 }
2263
2264 int PMPI_Keyval_free(int* keyval) {
2265    return not_yet_implemented();
2266 }
2267
2268 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2269    return not_yet_implemented();
2270 }
2271
2272 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2273    return not_yet_implemented();
2274 }
2275
2276 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2277    return not_yet_implemented();
2278 }
2279
2280 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2281    return not_yet_implemented();
2282 }
2283
2284 int PMPI_Initialized(int* flag) {
2285    return not_yet_implemented();
2286 }