Logo AND Algorithmique Numérique Distribuée

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