Logo AND Algorithmique Numérique Distribuée

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