Logo AND Algorithmique Numérique Distribuée

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