Logo AND Algorithmique Numérique Distribuée

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