Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cddc0206d451ae0636f9e4358b74706730f52bdb
[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=MPI_REQUEST_NULL;
927   return retval;
928 }
929
930 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
931                   int tag, MPI_Comm comm, MPI_Request * request)
932 {
933   int retval = 0;
934
935   smpi_bench_end();
936   if (request == NULL) {
937     retval = MPI_ERR_ARG;
938   } else if (comm == MPI_COMM_NULL) {
939     retval = MPI_ERR_COMM;
940   } else if (src == MPI_PROC_NULL) {
941       retval = MPI_SUCCESS;
942   } else {
943     *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
944     retval = MPI_SUCCESS;
945   }
946   smpi_bench_begin();
947   if(retval!=MPI_SUCCESS)*request=MPI_REQUEST_NULL;
948   return retval;
949 }
950
951 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
952   int retval = 0;
953
954     smpi_bench_end();
955     if (request == NULL) {
956       retval = MPI_ERR_ARG;
957     } else if (comm == MPI_COMM_NULL) {
958       retval = MPI_ERR_COMM;
959     } else if (dst == MPI_PROC_NULL) {
960       retval = MPI_SUCCESS;
961     } else {
962       *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
963       retval = MPI_SUCCESS;
964     }
965     smpi_bench_begin();
966     if(retval!=MPI_SUCCESS)*request=MPI_REQUEST_NULL;
967     return retval;
968 }
969
970 int PMPI_Start(MPI_Request * request)
971 {
972   int retval = 0;
973
974   smpi_bench_end();
975   if (request == NULL || *request == MPI_REQUEST_NULL) {
976     retval = MPI_ERR_ARG;
977   } else {
978     smpi_mpi_start(*request);
979     retval = MPI_SUCCESS;
980   }
981   smpi_bench_begin();
982   return retval;
983 }
984
985 int PMPI_Startall(int count, MPI_Request * requests)
986 {
987   int retval = 0;
988
989   smpi_bench_end();
990   if (requests == NULL) {
991     retval = MPI_ERR_ARG;
992   } else {
993     smpi_mpi_startall(count, requests);
994     retval = MPI_SUCCESS;
995   }
996   smpi_bench_begin();
997   return retval;
998 }
999
1000 int PMPI_Request_free(MPI_Request * request)
1001 {
1002   int retval = 0;
1003
1004   smpi_bench_end();
1005   if (*request == MPI_REQUEST_NULL) {
1006     retval = MPI_ERR_ARG;
1007   } else {
1008     if((*request)->flags & PERSISTENT)(*request)->refcount--;
1009     smpi_mpi_request_free(request);
1010     retval = MPI_SUCCESS;
1011   }
1012   smpi_bench_begin();
1013   return retval;
1014 }
1015
1016 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
1017               int tag, MPI_Comm comm, MPI_Request * request)
1018 {
1019   int retval = 0;
1020
1021   smpi_bench_end();
1022
1023   if (request == NULL) {
1024     retval = MPI_ERR_ARG;
1025   } else if (comm == MPI_COMM_NULL) {
1026     retval = MPI_ERR_COMM;
1027   } else if (src == MPI_PROC_NULL) {
1028     *request = MPI_REQUEST_NULL;
1029     retval = MPI_SUCCESS;
1030   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1031     retval = MPI_ERR_COMM;
1032   } else if (count < 0) {
1033     retval = MPI_ERR_COUNT;
1034   } else if (buf==NULL && count > 0) {
1035     retval = MPI_ERR_COUNT;
1036   } else if (datatype == MPI_DATATYPE_NULL){
1037     retval = MPI_ERR_TYPE;
1038   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1039     retval = MPI_ERR_TAG;
1040   } else {
1041
1042 #ifdef HAVE_TRACING
1043   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1044   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1045   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, count*smpi_datatype_size(datatype));
1046 #endif
1047
1048     *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1049     retval = MPI_SUCCESS;
1050
1051 #ifdef HAVE_TRACING
1052   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1053   (*request)->recv = 1;
1054 #endif
1055   }
1056
1057   smpi_bench_begin();
1058   if(retval!=MPI_SUCCESS)*request=MPI_REQUEST_NULL;
1059   return retval;
1060 }
1061
1062
1063 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1064               int tag, MPI_Comm comm, MPI_Request * request)
1065 {
1066   int retval = 0;
1067
1068   smpi_bench_end();
1069   if (request == NULL) {
1070     retval = MPI_ERR_ARG;
1071   } else if (comm == MPI_COMM_NULL) {
1072     retval = MPI_ERR_COMM;
1073   } else if (dst == MPI_PROC_NULL) {
1074     *request = MPI_REQUEST_NULL;
1075     retval = MPI_SUCCESS;
1076   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1077     retval = MPI_ERR_RANK;
1078   } else if (count < 0) {
1079     retval = MPI_ERR_COUNT;
1080   } else if (buf==NULL && count > 0) {
1081     retval = MPI_ERR_COUNT;
1082   } else if (datatype == MPI_DATATYPE_NULL){
1083     retval = MPI_ERR_TYPE;
1084   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1085     retval = MPI_ERR_TAG;
1086   } else {
1087
1088 #ifdef HAVE_TRACING
1089   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1090   TRACE_smpi_computing_out(rank);
1091   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1092   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, count*smpi_datatype_size(datatype));
1093   TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1094 #endif
1095
1096     *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1097     retval = MPI_SUCCESS;
1098
1099 #ifdef HAVE_TRACING
1100   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1101   (*request)->send = 1;
1102   TRACE_smpi_computing_in(rank);
1103 #endif
1104   }
1105
1106   smpi_bench_begin();
1107   if(retval!=MPI_SUCCESS)*request=MPI_REQUEST_NULL;
1108   return retval;
1109 }
1110
1111 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
1112   int retval = 0;
1113
1114   smpi_bench_end();
1115   if (request == NULL) {
1116     retval = MPI_ERR_ARG;
1117   } else if (comm == MPI_COMM_NULL) {
1118     retval = MPI_ERR_COMM;
1119   } else if (dst == MPI_PROC_NULL) {
1120     *request = MPI_REQUEST_NULL;
1121     retval = MPI_SUCCESS;
1122   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1123     retval = MPI_ERR_RANK;
1124   } else if (count < 0) {
1125     retval = MPI_ERR_COUNT;
1126   } else if (buf==NULL && count > 0) {
1127     retval = MPI_ERR_COUNT;
1128   } else if (datatype == MPI_DATATYPE_NULL){
1129     retval = MPI_ERR_TYPE;
1130   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1131     retval = MPI_ERR_TAG;
1132   } else {
1133
1134 #ifdef HAVE_TRACING
1135   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1136   TRACE_smpi_computing_out(rank);
1137   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1138   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, count*smpi_datatype_size(datatype));
1139   TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1140 #endif
1141
1142     *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1143     retval = MPI_SUCCESS;
1144
1145 #ifdef HAVE_TRACING
1146   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1147   (*request)->send = 1;
1148   TRACE_smpi_computing_in(rank);
1149 #endif
1150   }
1151
1152   smpi_bench_begin();
1153   if(retval!=MPI_SUCCESS)*request=MPI_REQUEST_NULL;
1154   return retval;
1155 }
1156
1157 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1158              MPI_Comm comm, MPI_Status * status)
1159 {
1160   int retval = 0;
1161
1162   smpi_bench_end();
1163   if (comm == MPI_COMM_NULL) {
1164     retval = MPI_ERR_COMM;
1165   } else if (src == MPI_PROC_NULL) {
1166     smpi_empty_status(status);
1167     status->MPI_SOURCE = MPI_PROC_NULL;
1168     retval = MPI_SUCCESS;
1169   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1170     retval = MPI_ERR_RANK;
1171   } else if (count < 0) {
1172     retval = MPI_ERR_COUNT;
1173   } else if (buf==NULL && count > 0) {
1174     retval = MPI_ERR_COUNT;
1175   } else if (datatype == MPI_DATATYPE_NULL){
1176     retval = MPI_ERR_TYPE;
1177   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1178     retval = MPI_ERR_TAG;
1179   } else {
1180 #ifdef HAVE_TRACING
1181   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1182   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1183   TRACE_smpi_computing_out(rank);
1184   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, count*smpi_datatype_size(datatype));
1185 #endif
1186
1187     smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1188     retval = MPI_SUCCESS;
1189
1190 #ifdef HAVE_TRACING
1191   //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1192   if(status!=MPI_STATUS_IGNORE)src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1193   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1194   TRACE_smpi_recv(rank, src_traced, rank);
1195   TRACE_smpi_computing_in(rank);
1196 #endif
1197   }
1198
1199   smpi_bench_begin();
1200   return retval;
1201 }
1202
1203 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1204              MPI_Comm comm)
1205 {
1206   int retval = 0;
1207
1208   smpi_bench_end();
1209
1210   if (comm == MPI_COMM_NULL) {
1211     retval = MPI_ERR_COMM;
1212   } else if (dst == MPI_PROC_NULL) {
1213     retval = MPI_SUCCESS;
1214   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1215     retval = MPI_ERR_RANK;
1216   } else if (count < 0) {
1217     retval = MPI_ERR_COUNT;
1218   } else if (buf==NULL && count > 0) {
1219     retval = MPI_ERR_COUNT;
1220   } else if (datatype == MPI_DATATYPE_NULL){
1221     retval = MPI_ERR_TYPE;
1222   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1223     retval = MPI_ERR_TAG;
1224   } else {
1225
1226 #ifdef HAVE_TRACING
1227   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1228   TRACE_smpi_computing_out(rank);
1229   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1230   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, count*smpi_datatype_size(datatype));
1231   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1232 #endif
1233
1234     smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1235     retval = MPI_SUCCESS;
1236
1237 #ifdef HAVE_TRACING
1238   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1239   TRACE_smpi_computing_in(rank);
1240 #endif
1241   }
1242
1243   smpi_bench_begin();
1244   return retval;
1245 }
1246
1247
1248
1249 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1250   int retval = 0;
1251
1252    smpi_bench_end();
1253
1254    if (comm == MPI_COMM_NULL) {
1255      retval = MPI_ERR_COMM;
1256    } else if (dst == MPI_PROC_NULL) {
1257      retval = MPI_SUCCESS;
1258    } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1259      retval = MPI_ERR_RANK;
1260    } else if (count < 0) {
1261      retval = MPI_ERR_COUNT;
1262    } else if (buf==NULL && count > 0) {
1263      retval = MPI_ERR_COUNT;
1264    } else if (datatype == MPI_DATATYPE_NULL){
1265      retval = MPI_ERR_TYPE;
1266    } else if(tag<0 && tag !=  MPI_ANY_TAG){
1267      retval = MPI_ERR_TAG;
1268    } else {
1269
1270  #ifdef HAVE_TRACING
1271    int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1272    TRACE_smpi_computing_out(rank);
1273    int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1274    TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, count*smpi_datatype_size(datatype));
1275    TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1276  #endif
1277
1278      smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1279      retval = MPI_SUCCESS;
1280
1281  #ifdef HAVE_TRACING
1282    TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1283    TRACE_smpi_computing_in(rank);
1284  #endif
1285    }
1286
1287    smpi_bench_begin();
1288    return retval;}
1289
1290
1291 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1292                  int dst, int sendtag, void *recvbuf, int recvcount,
1293                  MPI_Datatype recvtype, int src, int recvtag,
1294                  MPI_Comm comm, MPI_Status * status)
1295 {
1296   int retval = 0;
1297
1298   smpi_bench_end();
1299
1300   if (comm == MPI_COMM_NULL) {
1301     retval = MPI_ERR_COMM;
1302   } else if (sendtype == MPI_DATATYPE_NULL
1303              || recvtype == MPI_DATATYPE_NULL) {
1304     retval = MPI_ERR_TYPE;
1305   } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1306       smpi_empty_status(status);
1307       status->MPI_SOURCE = MPI_PROC_NULL;
1308       retval = MPI_SUCCESS;
1309   }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1310       (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1311     retval = MPI_ERR_RANK;
1312   } else if (sendcount < 0 || recvcount<0) {
1313       retval = MPI_ERR_COUNT;
1314   } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1315     retval = MPI_ERR_COUNT;
1316   } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1317     retval = MPI_ERR_TAG;
1318   } else {
1319
1320 #ifdef HAVE_TRACING
1321   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1322   TRACE_smpi_computing_out(rank);
1323   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1324   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1325   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, sendcount*smpi_datatype_size(sendtype));
1326   TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1327 #endif
1328
1329
1330     smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1331                       recvcount, recvtype, src, recvtag, comm, status);
1332     retval = MPI_SUCCESS;
1333
1334 #ifdef HAVE_TRACING
1335   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1336   TRACE_smpi_recv(rank, src_traced, rank);
1337   TRACE_smpi_computing_in(rank);
1338 #endif
1339
1340   }
1341
1342   smpi_bench_begin();
1343   return retval;
1344 }
1345
1346 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1347                          int dst, int sendtag, int src, int recvtag,
1348                          MPI_Comm comm, MPI_Status * status)
1349 {
1350   //TODO: suboptimal implementation
1351   void *recvbuf;
1352   int retval = 0;
1353   if (datatype == MPI_DATATYPE_NULL) {
1354       retval = MPI_ERR_TYPE;
1355   } else if (count < 0) {
1356       retval = MPI_ERR_COUNT;
1357   } else {
1358     int size = smpi_datatype_get_extent(datatype) * count;
1359     recvbuf = xbt_new(char, size);
1360     retval =
1361         MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1362                      datatype, src, recvtag, comm, status);
1363     if(retval==MPI_SUCCESS){
1364         smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1365     }
1366     xbt_free(recvbuf);
1367
1368   }
1369   return retval;
1370 }
1371
1372 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1373 {
1374   int retval = 0;
1375
1376   smpi_bench_end();
1377   if (*request == MPI_REQUEST_NULL || flag == NULL) {
1378     retval = MPI_ERR_ARG;
1379   } else if (*request == MPI_REQUEST_NULL) {
1380     *flag= TRUE;
1381     retval = MPI_ERR_REQUEST;
1382   } else {
1383     *flag = smpi_mpi_test(request, status);
1384     retval = MPI_SUCCESS;
1385   }
1386   smpi_bench_begin();
1387   return retval;
1388 }
1389
1390 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1391                 MPI_Status * status)
1392 {
1393   int retval = 0;
1394
1395   smpi_bench_end();
1396   if (index == NULL || flag == NULL) {
1397     retval = MPI_ERR_ARG;
1398   } else {
1399     *flag = smpi_mpi_testany(count, requests, index, status);
1400     retval = MPI_SUCCESS;
1401   }
1402   smpi_bench_begin();
1403   return retval;
1404 }
1405
1406 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1407 {
1408   int retval = 0;
1409
1410   smpi_bench_end();
1411   if (flag == NULL) {
1412     retval = MPI_ERR_ARG;
1413   } else {
1414     *flag = smpi_mpi_testall(count, requests, statuses);
1415     retval = MPI_SUCCESS;
1416   }
1417   smpi_bench_begin();
1418   return retval;
1419 }
1420
1421 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1422   int retval = 0;
1423   smpi_bench_end();
1424
1425   if (status == NULL) {
1426     retval = MPI_ERR_ARG;
1427   } else if (comm == MPI_COMM_NULL) {
1428     retval = MPI_ERR_COMM;
1429   } else if (source == MPI_PROC_NULL) {
1430     smpi_empty_status(status);
1431     status->MPI_SOURCE = MPI_PROC_NULL;
1432     retval = MPI_SUCCESS;
1433   } else {
1434     smpi_mpi_probe(source, tag, comm, status);
1435     retval = MPI_SUCCESS;
1436   }
1437   smpi_bench_begin();
1438   return retval;
1439 }
1440
1441
1442 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1443   int retval = 0;
1444   smpi_bench_end();
1445
1446   if (flag == NULL) {
1447     retval = MPI_ERR_ARG;
1448   } else if (status == NULL) {
1449     retval = MPI_ERR_ARG;
1450   } else if (comm == MPI_COMM_NULL) {
1451     retval = MPI_ERR_COMM;
1452   } else if (source == MPI_PROC_NULL) {
1453     *flag=TRUE;
1454     smpi_empty_status(status);
1455     status->MPI_SOURCE = MPI_PROC_NULL;
1456     retval = MPI_SUCCESS;
1457   } else {
1458     smpi_mpi_iprobe(source, tag, comm, flag, status);
1459     retval = MPI_SUCCESS;
1460   }
1461   smpi_bench_begin();
1462   return retval;
1463 }
1464
1465 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1466 {
1467   int retval = 0;
1468
1469   smpi_bench_end();
1470
1471   if (request == NULL) {
1472     retval = MPI_ERR_ARG;
1473   } else if (*request == MPI_REQUEST_NULL) {
1474     retval = MPI_ERR_REQUEST;
1475   } else {
1476
1477 #ifdef HAVE_TRACING
1478   int rank = request && (*request)->comm != MPI_COMM_NULL
1479       ? smpi_process_index()
1480       : -1;
1481   TRACE_smpi_computing_out(rank);
1482
1483   int src_traced = (*request)->src;
1484   int dst_traced = (*request)->dst;
1485   MPI_Comm comm = (*request)->comm;
1486   int is_wait_for_receive = (*request)->recv;
1487   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__,-1);
1488 #endif
1489
1490     smpi_mpi_wait(request, status);
1491     retval = MPI_SUCCESS;
1492
1493 #ifdef HAVE_TRACING
1494   //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1495   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1496   if (is_wait_for_receive) {
1497     if(src_traced==MPI_ANY_SOURCE)
1498     src_traced = (status!=MPI_STATUS_IGNORE) ?
1499                                 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1500                                 src_traced;
1501     TRACE_smpi_recv(rank, src_traced, dst_traced);
1502   }
1503   TRACE_smpi_computing_in(rank);
1504 #endif
1505
1506   }
1507
1508   smpi_bench_begin();
1509   return retval;
1510 }
1511
1512 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1513 {
1514   int retval = 0;
1515
1516   smpi_bench_end();
1517 #ifdef HAVE_TRACING
1518   //save requests information for tracing
1519   int i;
1520   int *srcs = xbt_new(int, count);
1521   int *dsts = xbt_new(int, count);
1522   int *recvs = xbt_new(int, count);
1523   MPI_Comm *comms = xbt_new(MPI_Comm, count);
1524
1525   for (i = 0; i < count; i++) {
1526     MPI_Request req = requests[i];      //already received requests are no longer valid
1527     if (req) {
1528       srcs[i] = req->src;
1529       dsts[i] = req->dst;
1530       recvs[i] = req->recv;
1531       comms[i] = req->comm;
1532     }
1533   }
1534   int rank_traced = smpi_process_index();
1535   TRACE_smpi_computing_out(rank_traced);
1536
1537   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,count);
1538
1539 #endif
1540   if (index == NULL) {
1541     retval = MPI_ERR_ARG;
1542   } else {
1543     *index = smpi_mpi_waitany(count, requests, status);
1544     retval = MPI_SUCCESS;
1545   }
1546 #ifdef HAVE_TRACING
1547   if(*index!=MPI_UNDEFINED){
1548     int src_traced = srcs[*index];
1549     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1550     int dst_traced = dsts[*index];
1551     int is_wait_for_receive = recvs[*index];
1552     if (is_wait_for_receive) {
1553       if(srcs[*index]==MPI_ANY_SOURCE)
1554         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1555                       smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1556                       srcs[*index];
1557       TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1558     }
1559     TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1560     xbt_free(srcs);
1561     xbt_free(dsts);
1562     xbt_free(recvs);
1563     xbt_free(comms);
1564
1565   }
1566   TRACE_smpi_computing_in(rank_traced);
1567 #endif
1568   smpi_bench_begin();
1569   return retval;
1570 }
1571
1572 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1573 {
1574
1575   smpi_bench_end();
1576 #ifdef HAVE_TRACING
1577   //save information from requests
1578   int i;
1579   int *srcs = xbt_new(int, count);
1580   int *dsts = xbt_new(int, count);
1581   int *recvs = xbt_new(int, count);
1582   int *valid = xbt_new(int, count);
1583   MPI_Comm *comms = xbt_new(MPI_Comm, count);
1584
1585   //int valid_count = 0;
1586   for (i = 0; i < count; i++) {
1587     MPI_Request req = requests[i];
1588     if(req!=MPI_REQUEST_NULL){
1589       srcs[i] = req->src;
1590       dsts[i] = req->dst;
1591       recvs[i] = req->recv;
1592       comms[i] = req->comm;
1593       valid[i]=1;;
1594     }else{
1595       valid[i]=0;
1596     }
1597   }
1598   int rank_traced = smpi_process_index();
1599   TRACE_smpi_computing_out(rank_traced);
1600
1601   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,count);
1602 #endif
1603   int retval = smpi_mpi_waitall(count, requests, status);
1604 #ifdef HAVE_TRACING
1605   for (i = 0; i < count; i++) {
1606     if(valid[i]){
1607     //int src_traced = srcs[*index];
1608     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1609       int src_traced = srcs[i];
1610       int dst_traced = dsts[i];
1611       int is_wait_for_receive = recvs[i];
1612       if (is_wait_for_receive) {
1613         if(src_traced==MPI_ANY_SOURCE)
1614         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1615                           smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1616                           srcs[i];
1617         TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1618       }
1619     }
1620   }
1621   TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1622   xbt_free(srcs);
1623   xbt_free(dsts);
1624   xbt_free(recvs);
1625   xbt_free(valid);
1626   xbt_free(comms);
1627
1628   TRACE_smpi_computing_in(rank_traced);
1629 #endif
1630   smpi_bench_begin();
1631   return retval;
1632 }
1633
1634 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1635                  int *indices, MPI_Status status[])
1636 {
1637   int retval = 0;
1638
1639   smpi_bench_end();
1640   if (outcount == NULL) {
1641     retval = MPI_ERR_ARG;
1642   } else {
1643     *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1644     retval = MPI_SUCCESS;
1645   }
1646   smpi_bench_begin();
1647   return retval;
1648 }
1649
1650 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1651                  int* indices, MPI_Status status[])
1652 {
1653   int retval = 0;
1654
1655    smpi_bench_end();
1656    if (outcount == NULL) {
1657      retval = MPI_ERR_ARG;
1658    } else {
1659      *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1660      retval = MPI_SUCCESS;
1661    }
1662    smpi_bench_begin();
1663    return retval;
1664 }
1665
1666
1667 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1668 {
1669   int retval = 0;
1670
1671   smpi_bench_end();
1672
1673   if (comm == MPI_COMM_NULL) {
1674     retval = MPI_ERR_COMM;
1675   } else {
1676 #ifdef HAVE_TRACING
1677   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1678   TRACE_smpi_computing_out(rank);
1679   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1680   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, count*smpi_datatype_size(datatype));
1681 #endif
1682     mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1683     retval = MPI_SUCCESS;
1684 #ifdef HAVE_TRACING
1685   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1686   TRACE_smpi_computing_in(rank);
1687 #endif
1688   }
1689
1690   smpi_bench_begin();
1691   return retval;
1692 }
1693
1694 int PMPI_Barrier(MPI_Comm comm)
1695 {
1696   int retval = 0;
1697
1698   smpi_bench_end();
1699
1700   if (comm == MPI_COMM_NULL) {
1701     retval = MPI_ERR_COMM;
1702   } else {
1703 #ifdef HAVE_TRACING
1704   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1705   TRACE_smpi_computing_out(rank);
1706   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, smpi_comm_size(comm));
1707 #endif
1708     mpi_coll_barrier_fun(comm);
1709     retval = MPI_SUCCESS;
1710 #ifdef HAVE_TRACING
1711   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1712   TRACE_smpi_computing_in(rank);
1713 #endif
1714   }
1715
1716   smpi_bench_begin();
1717   return retval;
1718 }
1719
1720 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1721                void *recvbuf, int recvcount, MPI_Datatype recvtype,
1722                int root, MPI_Comm comm)
1723 {
1724   int retval = 0;
1725
1726   smpi_bench_end();
1727
1728   if (comm == MPI_COMM_NULL) {
1729     retval = MPI_ERR_COMM;
1730   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1731             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1732     retval = MPI_ERR_TYPE;
1733   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1734             ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1735     retval = MPI_ERR_COUNT;
1736   } else {
1737
1738     char* sendtmpbuf = (char*) sendbuf;
1739     int sendtmpcount = sendcount;
1740     MPI_Datatype sendtmptype = sendtype;
1741     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1742       sendtmpcount=0;
1743       sendtmptype=recvtype;
1744     }
1745 #ifdef HAVE_TRACING
1746   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1747   TRACE_smpi_computing_out(rank);
1748   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1749   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,sendcount*smpi_datatype_size(sendtmptype));
1750 #endif
1751     mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1752                     recvtype, root, comm);
1753
1754
1755     retval = MPI_SUCCESS;
1756 #ifdef HAVE_TRACING
1757   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1758   TRACE_smpi_computing_in(rank);
1759 #endif
1760   }
1761
1762   smpi_bench_begin();
1763   return retval;
1764 }
1765
1766 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1767                 void *recvbuf, int *recvcounts, int *displs,
1768                 MPI_Datatype recvtype, int root, MPI_Comm comm)
1769 {
1770   int retval = 0;
1771
1772   smpi_bench_end();
1773
1774   if (comm == MPI_COMM_NULL) {
1775     retval = MPI_ERR_COMM;
1776   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1777             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1778     retval = MPI_ERR_TYPE;
1779   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1780     retval = MPI_ERR_COUNT;
1781   } else if (recvcounts == NULL || displs == NULL) {
1782     retval = MPI_ERR_ARG;
1783   } else {
1784     char* sendtmpbuf = (char*) sendbuf;
1785     int sendtmpcount = sendcount;
1786     MPI_Datatype sendtmptype = sendtype;
1787     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1788       sendtmpcount=0;
1789       sendtmptype=recvtype;
1790     }
1791
1792 #ifdef HAVE_TRACING
1793   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1794   TRACE_smpi_computing_out(rank);
1795   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1796   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,sendcount*smpi_datatype_size(sendtmptype));
1797 #endif
1798     smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1799                      displs, recvtype, root, comm);
1800     retval = MPI_SUCCESS;
1801 #ifdef HAVE_TRACING
1802   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1803   TRACE_smpi_computing_in(rank);
1804 #endif
1805   }
1806
1807   smpi_bench_begin();
1808   return retval;
1809 }
1810
1811 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1812                   void *recvbuf, int recvcount, MPI_Datatype recvtype,
1813                   MPI_Comm comm)
1814 {
1815   int retval = 0;
1816
1817   smpi_bench_end();
1818
1819   if (comm == MPI_COMM_NULL) {
1820     retval = MPI_ERR_COMM;
1821   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1822             (recvtype == MPI_DATATYPE_NULL)){
1823     retval = MPI_ERR_TYPE;
1824   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1825             (recvcount <0)){
1826     retval = MPI_ERR_COUNT;
1827   } else {
1828     if(sendbuf == MPI_IN_PLACE) {
1829       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1830       sendcount=recvcount;
1831       sendtype=recvtype;
1832     }
1833 #ifdef HAVE_TRACING
1834   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1835   TRACE_smpi_computing_out(rank);
1836   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,sendcount*smpi_datatype_size(sendtype));
1837 #endif
1838     mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1839                            recvtype, comm);
1840     retval = MPI_SUCCESS;
1841
1842 #ifdef HAVE_TRACING
1843   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1844 #endif
1845   }
1846   smpi_bench_begin();
1847   return retval;
1848 }
1849
1850 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1851                    void *recvbuf, int *recvcounts, int *displs,
1852                    MPI_Datatype recvtype, MPI_Comm comm)
1853 {
1854   int retval = 0;
1855
1856   smpi_bench_end();
1857
1858   if (comm == MPI_COMM_NULL) {
1859     retval = MPI_ERR_COMM;
1860   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1861             (recvtype == MPI_DATATYPE_NULL)){
1862     retval = MPI_ERR_TYPE;
1863   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1864     retval = MPI_ERR_COUNT;
1865   } else if (recvcounts == NULL || displs == NULL) {
1866     retval = MPI_ERR_ARG;
1867   } else {
1868
1869     if(sendbuf == MPI_IN_PLACE) {
1870       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1871       sendcount=recvcounts[smpi_comm_rank(comm)];
1872       sendtype=recvtype;
1873     }
1874 #ifdef HAVE_TRACING
1875   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1876   TRACE_smpi_computing_out(rank);
1877   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,sendcount*smpi_datatype_size(sendtype));
1878 #endif
1879     mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1880                         displs, recvtype, comm);
1881     retval = MPI_SUCCESS;
1882 #ifdef HAVE_TRACING
1883   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1884   TRACE_smpi_computing_in(rank);
1885 #endif
1886   }
1887
1888   smpi_bench_begin();
1889   return retval;
1890 }
1891
1892 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1893                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1894                 int root, MPI_Comm comm)
1895 {
1896   int retval = 0;
1897
1898   smpi_bench_end();
1899
1900   if (comm == MPI_COMM_NULL) {
1901     retval = MPI_ERR_COMM;
1902   } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1903              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1904     retval = MPI_ERR_TYPE;
1905   } else {
1906
1907     if (recvbuf == MPI_IN_PLACE) {
1908         recvtype=sendtype;
1909         recvcount=sendcount;
1910     }
1911 #ifdef HAVE_TRACING
1912   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1913   TRACE_smpi_computing_out(rank);
1914   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1915
1916   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,sendcount*smpi_datatype_size(recvtype));
1917 #endif
1918     mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1919                      recvtype, root, comm);
1920     retval = MPI_SUCCESS;
1921 #ifdef HAVE_TRACING
1922   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1923   TRACE_smpi_computing_in(rank);
1924 #endif
1925   }
1926
1927   smpi_bench_begin();
1928   return retval;
1929 }
1930
1931 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1932                  MPI_Datatype sendtype, void *recvbuf, int recvcount,
1933                  MPI_Datatype recvtype, int root, MPI_Comm comm)
1934 {
1935   int retval = 0;
1936
1937   smpi_bench_end();
1938
1939   if (comm == MPI_COMM_NULL) {
1940     retval = MPI_ERR_COMM;
1941   } else if (sendcounts == NULL || displs == NULL) {
1942     retval = MPI_ERR_ARG;
1943   } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1944              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1945     retval = MPI_ERR_TYPE;
1946   } else {
1947     if (recvbuf == MPI_IN_PLACE) {
1948         recvtype=sendtype;
1949         recvcount=sendcounts[smpi_comm_rank(comm)];
1950     }
1951 #ifdef HAVE_TRACING
1952   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1953   TRACE_smpi_computing_out(rank);
1954   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1955   int count=0, i;
1956   for(i=0; i<smpi_comm_size(comm);i++)count+=sendcounts[i];
1957   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, count*smpi_datatype_size(sendtype));
1958 #endif
1959     smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
1960                       recvcount, recvtype, root, comm);
1961     retval = MPI_SUCCESS;
1962 #ifdef HAVE_TRACING
1963   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1964   TRACE_smpi_computing_in(rank);
1965 #endif
1966   }
1967
1968   smpi_bench_begin();
1969   return retval;
1970 }
1971
1972 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
1973                MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1974 {
1975   int retval = 0;
1976
1977   smpi_bench_end();
1978
1979   if (comm == MPI_COMM_NULL) {
1980     retval = MPI_ERR_COMM;
1981   } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
1982     retval = MPI_ERR_ARG;
1983   } else {
1984 #ifdef HAVE_TRACING
1985   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1986   TRACE_smpi_computing_out(rank);
1987   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1988   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, count*smpi_datatype_size(datatype));
1989 #endif
1990     mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
1991
1992     retval = MPI_SUCCESS;
1993 #ifdef HAVE_TRACING
1994   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1995   TRACE_smpi_computing_in(rank);
1996 #endif
1997   }
1998
1999   smpi_bench_begin();
2000   return retval;
2001 }
2002
2003 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2004     MPI_Datatype datatype, MPI_Op op){
2005   int retval = 0;
2006
2007     smpi_bench_end();
2008     if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
2009       retval = MPI_ERR_ARG;
2010     } else {
2011       smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2012       retval=MPI_SUCCESS;
2013     }
2014     smpi_bench_begin();
2015     return retval;
2016 }
2017
2018 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2019                   MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2020 {
2021   int retval = 0;
2022
2023   smpi_bench_end();
2024
2025   if (comm == MPI_COMM_NULL) {
2026     retval = MPI_ERR_COMM;
2027   } else if (datatype == MPI_DATATYPE_NULL) {
2028     retval = MPI_ERR_TYPE;
2029   } else if (op == MPI_OP_NULL) {
2030     retval = MPI_ERR_OP;
2031   } else {
2032
2033     char* sendtmpbuf = (char*) sendbuf;
2034     if( sendbuf == MPI_IN_PLACE ) {
2035       sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2036       smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2037     }
2038 #ifdef HAVE_TRACING
2039   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2040   TRACE_smpi_computing_out(rank);
2041   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, count*smpi_datatype_size(datatype));
2042 #endif
2043     mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2044
2045     if( sendbuf == MPI_IN_PLACE ) {
2046       xbt_free(sendtmpbuf);
2047     }
2048
2049     retval = MPI_SUCCESS;
2050 #ifdef HAVE_TRACING
2051   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2052   TRACE_smpi_computing_in(rank);
2053 #endif
2054   }
2055
2056   smpi_bench_begin();
2057   return retval;
2058 }
2059
2060 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2061              MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2062 {
2063   int retval = 0;
2064
2065   smpi_bench_end();
2066
2067   if (comm == MPI_COMM_NULL) {
2068     retval = MPI_ERR_COMM;
2069   } else if (datatype == MPI_DATATYPE_NULL) {
2070     retval = MPI_ERR_TYPE;
2071   } else if (op == MPI_OP_NULL) {
2072     retval = MPI_ERR_OP;
2073   } else {
2074 #ifdef HAVE_TRACING
2075   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2076   TRACE_smpi_computing_out(rank);
2077   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, count*smpi_datatype_size(datatype));
2078 #endif
2079     smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2080     retval = MPI_SUCCESS;
2081 #ifdef HAVE_TRACING
2082   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2083   TRACE_smpi_computing_in(rank);
2084 #endif
2085   }
2086
2087   smpi_bench_begin();
2088   return retval;
2089 }
2090
2091 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2092                 MPI_Op op, MPI_Comm comm){
2093   int retval = 0;
2094
2095   smpi_bench_end();
2096
2097   if (comm == MPI_COMM_NULL) {
2098     retval = MPI_ERR_COMM;
2099   } else if (datatype == MPI_DATATYPE_NULL) {
2100     retval = MPI_ERR_TYPE;
2101   } else if (op == MPI_OP_NULL) {
2102     retval = MPI_ERR_OP;
2103   } else {
2104 #ifdef HAVE_TRACING
2105   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2106   TRACE_smpi_computing_out(rank);
2107   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, count*smpi_datatype_size(datatype));
2108 #endif
2109     smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2110     retval = MPI_SUCCESS;
2111 #ifdef HAVE_TRACING
2112   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2113   TRACE_smpi_computing_in(rank);
2114 #endif
2115   }
2116
2117   smpi_bench_begin();
2118   return retval;
2119 }
2120
2121 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2122                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2123 {
2124   int retval = 0;
2125   smpi_bench_end();
2126
2127   if (comm == MPI_COMM_NULL) {
2128     retval = MPI_ERR_COMM;
2129   } else if (datatype == MPI_DATATYPE_NULL) {
2130     retval = MPI_ERR_TYPE;
2131   } else if (op == MPI_OP_NULL) {
2132     retval = MPI_ERR_OP;
2133   } else if (recvcounts == NULL) {
2134     retval = MPI_ERR_ARG;
2135   } else {
2136 #ifdef HAVE_TRACING
2137   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2138   TRACE_smpi_computing_out(rank);
2139   int count=0, i;
2140   for(i=0; i<smpi_comm_size(comm);i++)count+=recvcounts[i];
2141   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, count*smpi_datatype_size(datatype));
2142 #endif
2143     void* sendtmpbuf=sendbuf;
2144     if(sendbuf==MPI_IN_PLACE){
2145       sendtmpbuf=recvbuf;
2146     }
2147
2148     mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2149                        datatype,  op, comm);
2150     retval = MPI_SUCCESS;
2151 #ifdef HAVE_TRACING
2152   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2153   TRACE_smpi_computing_in(rank);
2154 #endif
2155   }
2156
2157   smpi_bench_begin();
2158   return retval;
2159 }
2160
2161 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2162                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2163 {
2164   int retval,i;
2165   smpi_bench_end();
2166
2167   if (comm == MPI_COMM_NULL) {
2168     retval = MPI_ERR_COMM;
2169   } else if (datatype == MPI_DATATYPE_NULL) {
2170     retval = MPI_ERR_TYPE;
2171   } else if (op == MPI_OP_NULL) {
2172     retval = MPI_ERR_OP;
2173   } else if (recvcount < 0) {
2174     retval = MPI_ERR_ARG;
2175   } else {
2176 #ifdef HAVE_TRACING
2177   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2178   TRACE_smpi_computing_out(rank);
2179   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, recvcount*smpi_comm_size(comm)*smpi_datatype_size(datatype));
2180 #endif
2181     int count=smpi_comm_size(comm);
2182     int* recvcounts=(int*)xbt_malloc(count);
2183     for (i=0; i<count;i++)recvcounts[i]=recvcount;
2184     mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2185                        datatype,  op, comm);
2186     xbt_free(recvcounts);
2187     retval = MPI_SUCCESS;
2188 #ifdef HAVE_TRACING
2189   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2190   TRACE_smpi_computing_in(rank);
2191 #endif
2192   }
2193
2194   smpi_bench_begin();
2195   return retval;
2196 }
2197
2198 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2199                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
2200                  MPI_Comm comm)
2201 {
2202   int retval = 0;
2203
2204   smpi_bench_end();
2205
2206   if (comm == MPI_COMM_NULL) {
2207     retval = MPI_ERR_COMM;
2208   } else if (sendtype == MPI_DATATYPE_NULL
2209              || recvtype == MPI_DATATYPE_NULL) {
2210     retval = MPI_ERR_TYPE;
2211   } else {
2212 #ifdef HAVE_TRACING
2213   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2214   TRACE_smpi_computing_out(rank);
2215   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, sendcount*smpi_datatype_size(sendtype));
2216 #endif
2217     retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2218 #ifdef HAVE_TRACING
2219   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2220   TRACE_smpi_computing_in(rank);
2221 #endif
2222   }
2223
2224   smpi_bench_begin();
2225   return retval;
2226 }
2227
2228 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2229                   MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2230                   int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2231 {
2232   int retval = 0;
2233
2234   smpi_bench_end();
2235
2236   if (comm == MPI_COMM_NULL) {
2237     retval = MPI_ERR_COMM;
2238   } else if (sendtype == MPI_DATATYPE_NULL
2239              || recvtype == MPI_DATATYPE_NULL) {
2240     retval = MPI_ERR_TYPE;
2241   } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2242              || recvdisps == NULL) {
2243     retval = MPI_ERR_ARG;
2244   } else {
2245 #ifdef HAVE_TRACING
2246   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2247   TRACE_smpi_computing_out(rank);
2248   int i, size=0;
2249   for(i=0; i< smpi_comm_size(comm);i++)size+=sendcounts[i];
2250   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, size*smpi_datatype_size(sendtype));
2251 #endif
2252     retval =
2253         mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2254                                   recvbuf, recvcounts, recvdisps, recvtype,
2255                                   comm);
2256 #ifdef HAVE_TRACING
2257   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2258   TRACE_smpi_computing_in(rank);
2259 #endif
2260   }
2261
2262   smpi_bench_begin();
2263   return retval;
2264 }
2265
2266
2267 int PMPI_Get_processor_name(char *name, int *resultlen)
2268 {
2269   int retval = MPI_SUCCESS;
2270
2271   smpi_bench_end();
2272   strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2273           strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2274           strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2275           MPI_MAX_PROCESSOR_NAME - 1 );
2276   *resultlen =
2277       strlen(name) >
2278       MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2279
2280   smpi_bench_begin();
2281   return retval;
2282 }
2283
2284 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2285 {
2286   int retval = MPI_SUCCESS;
2287   size_t size;
2288
2289   smpi_bench_end();
2290   if (status == NULL || count == NULL) {
2291     retval = MPI_ERR_ARG;
2292   } else if (datatype == MPI_DATATYPE_NULL) {
2293     retval = MPI_ERR_TYPE;
2294   } else {
2295     size = smpi_datatype_size(datatype);
2296     if (size == 0) {
2297       *count = 0;
2298     } else if (status->count % size != 0) {
2299       retval = MPI_UNDEFINED;
2300     } else {
2301       *count = smpi_mpi_get_count(status, datatype);
2302     }
2303   }
2304   smpi_bench_begin();
2305   return retval;
2306 }
2307
2308 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2309   int retval = 0;
2310
2311   smpi_bench_end();
2312   if (old_type == MPI_DATATYPE_NULL) {
2313     retval = MPI_ERR_TYPE;
2314   } else if (count<0){
2315     retval = MPI_ERR_COUNT;
2316   } else {
2317     retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2318   }
2319   smpi_bench_begin();
2320   return retval;
2321 }
2322
2323 int PMPI_Type_commit(MPI_Datatype* datatype) {
2324   int retval = 0;
2325
2326   smpi_bench_end();
2327   if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2328     retval = MPI_ERR_TYPE;
2329   } else {
2330     smpi_datatype_commit(datatype);
2331     retval = MPI_SUCCESS;
2332   }
2333   smpi_bench_begin();
2334   return retval;
2335 }
2336
2337
2338 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2339   int retval = 0;
2340
2341   smpi_bench_end();
2342   if (old_type == MPI_DATATYPE_NULL) {
2343     retval = MPI_ERR_TYPE;
2344   } else if (count<0 || blocklen<0){
2345     retval = MPI_ERR_COUNT;
2346   } else {
2347     retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2348   }
2349   smpi_bench_begin();
2350   return retval;
2351 }
2352
2353 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2354   int retval = 0;
2355
2356   smpi_bench_end();
2357   if (old_type == MPI_DATATYPE_NULL) {
2358     retval = MPI_ERR_TYPE;
2359   } else if (count<0 || blocklen<0){
2360     retval = MPI_ERR_COUNT;
2361   } else {
2362     retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2363   }
2364   smpi_bench_begin();
2365   return retval;
2366 }
2367
2368 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2369   return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2370 }
2371
2372 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2373   int retval = 0;
2374
2375   smpi_bench_end();
2376   if (old_type == MPI_DATATYPE_NULL) {
2377     retval = MPI_ERR_TYPE;
2378   } else if (count<0){
2379     retval = MPI_ERR_COUNT;
2380   } else {
2381     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2382   }
2383   smpi_bench_begin();
2384   return retval;
2385 }
2386
2387 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2388   int retval = 0;
2389
2390   smpi_bench_end();
2391   if (old_type == MPI_DATATYPE_NULL) {
2392     retval = MPI_ERR_TYPE;
2393   } else if (count<0){
2394     retval = MPI_ERR_COUNT;
2395   } else {
2396     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2397   }
2398   smpi_bench_begin();
2399   return retval;
2400 }
2401
2402 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2403   int retval,i;
2404
2405   smpi_bench_end();
2406   if (old_type == MPI_DATATYPE_NULL) {
2407     retval = MPI_ERR_TYPE;
2408   } else if (count<0){
2409     retval = MPI_ERR_COUNT;
2410   } else {
2411     int* blocklens=(int*)xbt_malloc(blocklength*count);
2412     for (i=0; i<count;i++)blocklens[i]=blocklength;
2413     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2414     xbt_free(blocklens);
2415   }
2416   smpi_bench_begin();
2417   return retval;
2418 }
2419
2420
2421 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2422   int retval = 0;
2423
2424   smpi_bench_end();
2425   if (old_type == MPI_DATATYPE_NULL) {
2426     retval = MPI_ERR_TYPE;
2427   } else if (count<0){
2428     retval = MPI_ERR_COUNT;
2429   } else {
2430     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2431   }
2432   smpi_bench_begin();
2433   return retval;
2434 }
2435
2436 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2437   return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2438 }
2439
2440 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2441   int retval,i;
2442
2443   smpi_bench_end();
2444   if (old_type == MPI_DATATYPE_NULL) {
2445     retval = MPI_ERR_TYPE;
2446   } else if (count<0){
2447     retval = MPI_ERR_COUNT;
2448   } else {
2449     int* blocklens=(int*)xbt_malloc(blocklength*count);
2450     for (i=0; i<count;i++)blocklens[i]=blocklength;
2451     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2452     xbt_free(blocklens);
2453   }
2454   smpi_bench_begin();
2455   return retval;
2456 }
2457
2458
2459 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2460   int retval = 0;
2461
2462   smpi_bench_end();
2463   if (count<0){
2464     retval = MPI_ERR_COUNT;
2465   } else {
2466     retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2467   }
2468   smpi_bench_begin();
2469   return retval;
2470 }
2471
2472 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2473   return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2474 }
2475
2476
2477 int PMPI_Error_class(int errorcode, int* errorclass) {
2478   // assume smpi uses only standard mpi error codes
2479   *errorclass=errorcode;
2480   return MPI_SUCCESS;
2481 }
2482
2483
2484 int PMPI_Initialized(int* flag) {
2485    *flag=smpi_process_initialized();
2486    return MPI_SUCCESS;
2487 }
2488
2489 /* The following calls are not yet implemented and will fail at runtime. */
2490 /* Once implemented, please move them above this notice. */
2491
2492 #define NOT_YET_IMPLEMENTED {\
2493         XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__);\
2494         return MPI_SUCCESS;\
2495         }
2496
2497
2498 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
2499   NOT_YET_IMPLEMENTED
2500 }
2501
2502 int PMPI_Type_set_name(MPI_Datatype  datatype, char * name)
2503 {
2504   NOT_YET_IMPLEMENTED
2505 }
2506
2507 int PMPI_Type_get_name(MPI_Datatype  datatype, char * name, int* len)
2508 {
2509   NOT_YET_IMPLEMENTED
2510 }
2511
2512 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2513    NOT_YET_IMPLEMENTED
2514 }
2515
2516 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2517    NOT_YET_IMPLEMENTED
2518 }
2519
2520 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periods, int reorder, MPI_Comm* comm_cart) {
2521    NOT_YET_IMPLEMENTED
2522 }
2523
2524 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2525    NOT_YET_IMPLEMENTED
2526 }
2527
2528 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2529    NOT_YET_IMPLEMENTED
2530 }
2531
2532 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2533    NOT_YET_IMPLEMENTED
2534 }
2535
2536 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2537    NOT_YET_IMPLEMENTED
2538 }
2539
2540 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2541    NOT_YET_IMPLEMENTED
2542 }
2543
2544 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2545    NOT_YET_IMPLEMENTED
2546 }
2547
2548 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2549    NOT_YET_IMPLEMENTED
2550 }
2551
2552 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2553    NOT_YET_IMPLEMENTED
2554 }
2555
2556 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2557    NOT_YET_IMPLEMENTED
2558 }
2559
2560 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2561    NOT_YET_IMPLEMENTED
2562 }
2563
2564 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2565    NOT_YET_IMPLEMENTED
2566 }
2567
2568 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2569    NOT_YET_IMPLEMENTED
2570 }
2571
2572 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2573    NOT_YET_IMPLEMENTED
2574 }
2575
2576 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2577    NOT_YET_IMPLEMENTED
2578 }
2579
2580 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2581    NOT_YET_IMPLEMENTED
2582 }
2583
2584 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2585    NOT_YET_IMPLEMENTED
2586 }
2587
2588 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2589    NOT_YET_IMPLEMENTED
2590 }
2591
2592 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2593    NOT_YET_IMPLEMENTED
2594 }
2595
2596 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
2597    NOT_YET_IMPLEMENTED
2598 }
2599
2600 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
2601    NOT_YET_IMPLEMENTED
2602 }
2603
2604 int PMPI_Cancel(MPI_Request* request) {
2605    NOT_YET_IMPLEMENTED
2606 }
2607
2608 int PMPI_Buffer_attach(void* buffer, int size) {
2609    NOT_YET_IMPLEMENTED
2610 }
2611
2612 int PMPI_Buffer_detach(void* buffer, int* size) {
2613    NOT_YET_IMPLEMENTED
2614 }
2615
2616 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2617    NOT_YET_IMPLEMENTED
2618 }
2619
2620 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2621 {
2622    NOT_YET_IMPLEMENTED
2623 }
2624
2625 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
2626 {
2627    NOT_YET_IMPLEMENTED
2628 }
2629
2630 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
2631 {
2632    NOT_YET_IMPLEMENTED
2633 }
2634
2635 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
2636 {
2637    NOT_YET_IMPLEMENTED
2638 }
2639
2640 int PMPI_Comm_free_keyval(int* keyval) {
2641    NOT_YET_IMPLEMENTED
2642 }
2643
2644 int PMPI_Pcontrol(const int level )
2645 {
2646    NOT_YET_IMPLEMENTED
2647 }
2648
2649 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2650    NOT_YET_IMPLEMENTED
2651 }
2652
2653 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
2654 {
2655   NOT_YET_IMPLEMENTED
2656 }
2657
2658 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
2659 {
2660   NOT_YET_IMPLEMENTED
2661 }
2662
2663 int PMPI_Type_delete_attr (MPI_Datatype type, int comm_keyval)
2664 {
2665   NOT_YET_IMPLEMENTED
2666 }
2667
2668 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
2669 {
2670   NOT_YET_IMPLEMENTED
2671 }
2672
2673 int PMPI_Type_free_keyval(int* keyval) {
2674   NOT_YET_IMPLEMENTED
2675 }
2676
2677 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2678    NOT_YET_IMPLEMENTED
2679 }
2680
2681 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2682    NOT_YET_IMPLEMENTED
2683 }
2684
2685 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2686    NOT_YET_IMPLEMENTED
2687 }
2688
2689 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2690    NOT_YET_IMPLEMENTED
2691 }
2692
2693 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2694    NOT_YET_IMPLEMENTED
2695 }
2696
2697 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2698    NOT_YET_IMPLEMENTED
2699 }
2700
2701 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2702    NOT_YET_IMPLEMENTED
2703 }
2704
2705 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2706    NOT_YET_IMPLEMENTED
2707 }
2708
2709 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2710    NOT_YET_IMPLEMENTED
2711 }
2712
2713 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2714    NOT_YET_IMPLEMENTED
2715 }
2716
2717 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2718    NOT_YET_IMPLEMENTED
2719 }
2720
2721 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2722    NOT_YET_IMPLEMENTED
2723 }
2724
2725 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2726    NOT_YET_IMPLEMENTED
2727 }
2728
2729 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2730    NOT_YET_IMPLEMENTED
2731 }
2732
2733 int PMPI_Keyval_free(int* keyval) {
2734    NOT_YET_IMPLEMENTED
2735 }
2736
2737 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2738    NOT_YET_IMPLEMENTED
2739 }
2740
2741 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2742    NOT_YET_IMPLEMENTED
2743 }
2744
2745 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
2746   NOT_YET_IMPLEMENTED
2747 }
2748
2749 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
2750   NOT_YET_IMPLEMENTED
2751 }
2752
2753 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
2754   NOT_YET_IMPLEMENTED
2755 }
2756
2757 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2758    NOT_YET_IMPLEMENTED
2759 }
2760
2761 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2762    NOT_YET_IMPLEMENTED
2763 }
2764
2765 int PMPI_Win_fence( int assert,  MPI_Win win){
2766    NOT_YET_IMPLEMENTED
2767 }
2768
2769 int PMPI_Win_free( MPI_Win* win){
2770    NOT_YET_IMPLEMENTED
2771 }
2772
2773 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2774   NOT_YET_IMPLEMENTED
2775 }
2776
2777 int PMPI_Info_create( MPI_Info *info){
2778   NOT_YET_IMPLEMENTED
2779 }
2780
2781 int PMPI_Info_set( MPI_Info info, char *key, char *value){
2782   NOT_YET_IMPLEMENTED
2783 }
2784
2785 int PMPI_Info_free( MPI_Info *info){
2786   NOT_YET_IMPLEMENTED
2787 }
2788
2789 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2790     MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2791   NOT_YET_IMPLEMENTED
2792 }
2793
2794 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
2795                           int *num_addresses, int *num_datatypes, int *combiner){
2796   NOT_YET_IMPLEMENTED
2797 }
2798
2799 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
2800                           int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
2801                           MPI_Datatype* array_of_datatypes){
2802   NOT_YET_IMPLEMENTED
2803 }
2804
2805 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
2806                             int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
2807                             int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
2808   NOT_YET_IMPLEMENTED
2809 }
2810
2811 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2812   NOT_YET_IMPLEMENTED
2813 }
2814
2815 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){
2816   NOT_YET_IMPLEMENTED
2817 }
2818
2819 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
2820   NOT_YET_IMPLEMENTED
2821 }
2822
2823 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
2824                    void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
2825                    MPI_Comm comm){
2826   NOT_YET_IMPLEMENTED
2827 }
2828
2829 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
2830   NOT_YET_IMPLEMENTED
2831 }
2832
2833 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
2834   NOT_YET_IMPLEMENTED
2835 }
2836
2837 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
2838   NOT_YET_IMPLEMENTED
2839 }
2840
2841 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
2842   NOT_YET_IMPLEMENTED
2843 }
2844
2845 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
2846   NOT_YET_IMPLEMENTED
2847 }
2848
2849 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
2850   NOT_YET_IMPLEMENTED
2851 }
2852
2853 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
2854   NOT_YET_IMPLEMENTED
2855 }
2856
2857 int PMPI_Add_error_class( int *errorclass){
2858   NOT_YET_IMPLEMENTED
2859 }
2860
2861 int PMPI_Add_error_code(  int errorclass, int *errorcode){
2862   NOT_YET_IMPLEMENTED
2863 }
2864
2865 int PMPI_Add_error_string( int errorcode, char *string){
2866   NOT_YET_IMPLEMENTED
2867 }
2868
2869 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
2870   NOT_YET_IMPLEMENTED
2871 }
2872
2873 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
2874   NOT_YET_IMPLEMENTED
2875 }
2876
2877 int PMPI_Info_delete(MPI_Info info, char *key){
2878   NOT_YET_IMPLEMENTED
2879 }
2880
2881 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
2882   NOT_YET_IMPLEMENTED
2883 }
2884
2885 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
2886   NOT_YET_IMPLEMENTED
2887 }
2888
2889 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
2890   NOT_YET_IMPLEMENTED
2891 }
2892
2893 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
2894   NOT_YET_IMPLEMENTED
2895 }
2896
2897 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){
2898   NOT_YET_IMPLEMENTED
2899 }
2900
2901 int PMPI_Grequest_complete( MPI_Request request){
2902   NOT_YET_IMPLEMENTED
2903 }
2904
2905 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
2906   NOT_YET_IMPLEMENTED
2907 }
2908
2909 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
2910   NOT_YET_IMPLEMENTED
2911 }
2912
2913 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
2914   NOT_YET_IMPLEMENTED
2915 }
2916
2917 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
2918   NOT_YET_IMPLEMENTED
2919 }
2920
2921 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
2922   NOT_YET_IMPLEMENTED
2923 }
2924
2925 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
2926   NOT_YET_IMPLEMENTED
2927 }
2928
2929 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
2930   NOT_YET_IMPLEMENTED
2931 }
2932
2933 int PMPI_Open_port( MPI_Info info, char *port_name){
2934   NOT_YET_IMPLEMENTED
2935 }
2936
2937 int PMPI_Close_port(char *port_name){
2938   NOT_YET_IMPLEMENTED
2939 }
2940
2941 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
2942   NOT_YET_IMPLEMENTED
2943 }
2944
2945 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){
2946   NOT_YET_IMPLEMENTED
2947 }
2948
2949 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
2950                              int* array_of_maxprocs, MPI_Info* array_of_info, int root,
2951                              MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
2952   NOT_YET_IMPLEMENTED
2953 }
2954
2955 int PMPI_Comm_get_parent( MPI_Comm *parent){
2956   NOT_YET_IMPLEMENTED
2957 }