Logo AND Algorithmique Numérique Distribuée

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