Logo AND Algorithmique Numérique Distribuée

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