Logo AND Algorithmique Numérique Distribuée

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