Logo AND Algorithmique Numérique Distribuée

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