Logo AND Algorithmique Numérique Distribuée

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