Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : MUTEX_UNLOCK is invisible for MC
[simgrid.git] / src / smpi / smpi_pmpi.c
1
2 /* Copyright (c) 2007-2014. The SimGrid Team.
3  * All rights reserved.                                                     */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "private.h"
9 #include "smpi_mpi_dt_private.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
12                                 "Logging specific to SMPI (pmpi)");
13
14 #ifdef HAVE_TRACING
15 //this function need to be here because of the calls to smpi_bench
16 void TRACE_smpi_set_category(const char *category)
17 {
18   //need to end bench otherwise categories for execution tasks are wrong
19   smpi_bench_end();
20   TRACE_internal_smpi_set_category (category);
21   //begin bench after changing process's category
22   smpi_bench_begin();
23 }
24 #endif
25
26 /* PMPI User level calls */
27
28 int PMPI_Init(int *argc, char ***argv)
29 {
30   smpi_process_init(argc, argv);
31   smpi_process_mark_as_initialized();
32 #ifdef HAVE_TRACING
33   int rank = smpi_process_index();
34   TRACE_smpi_init(rank);
35   TRACE_smpi_computing_init(rank);
36   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
37   extra->type = TRACING_INIT;
38   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
39   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
40 #endif
41   smpi_bench_begin();
42   return MPI_SUCCESS;
43 }
44
45 int PMPI_Finalize(void)
46 {
47   smpi_bench_end();
48 #ifdef HAVE_TRACING
49   int rank = smpi_process_index();
50   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
51   extra->type = TRACING_FINALIZE;
52   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
53 #endif
54   smpi_process_finalize();
55 #ifdef HAVE_TRACING
56   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
57   TRACE_smpi_finalize(smpi_process_index());
58 #endif
59   smpi_process_destroy();
60   return MPI_SUCCESS;
61 }
62
63 int PMPI_Finalized(int* flag)
64 {
65   *flag=smpi_process_finalized();
66   return MPI_SUCCESS;
67 }
68
69 int PMPI_Get_version (int *version,int *subversion){
70   *version = MPI_VERSION;
71   *subversion= MPI_SUBVERSION;
72   return MPI_SUCCESS;
73 }
74
75 int PMPI_Get_library_version (char *version,int *len){
76   int retval = MPI_SUCCESS;
77   smpi_bench_end();
78   snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2014",SIMGRID_VERSION_MAJOR,
79           SIMGRID_VERSION_MINOR);
80   *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
81   smpi_bench_begin();
82   return retval;
83 }
84
85 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
86 {
87   if (provided != NULL) {
88     *provided = MPI_THREAD_MULTIPLE;
89   }
90   return MPI_Init(argc, argv);
91 }
92
93 int PMPI_Query_thread(int *provided)
94 {
95   int retval = 0;
96
97   if (provided == NULL) {
98     retval = MPI_ERR_ARG;
99   } else {
100     *provided = MPI_THREAD_MULTIPLE;
101     retval = MPI_SUCCESS;
102   }
103   return retval;
104 }
105
106 int PMPI_Is_thread_main(int *flag)
107 {
108   int retval = 0;
109
110   if (flag == NULL) {
111     retval = MPI_ERR_ARG;
112   } else {
113     *flag = smpi_process_index() == 0;
114     retval = MPI_SUCCESS;
115   }
116   return retval;
117 }
118
119 int PMPI_Abort(MPI_Comm comm, int errorcode)
120 {
121   smpi_bench_end();
122   smpi_process_destroy();
123   // FIXME: should kill all processes in comm instead
124   simcall_process_kill(SIMIX_process_self());
125   return MPI_SUCCESS;
126 }
127
128 double PMPI_Wtime(void)
129 {
130   return smpi_mpi_wtime();
131 }
132
133 extern double sg_maxmin_precision;
134 double PMPI_Wtick(void)
135 {
136   return sg_maxmin_precision;
137 }
138
139 int PMPI_Address(void *location, MPI_Aint * address)
140 {
141   int retval = 0;
142
143   if (!address) {
144     retval = MPI_ERR_ARG;
145   } else {
146     *address = (MPI_Aint) location;
147     retval = MPI_SUCCESS;
148   }
149   return retval;
150 }
151
152 int PMPI_Get_address(void *location, MPI_Aint * address)
153 {
154   return PMPI_Address(location, address);
155 }
156
157 int PMPI_Type_free(MPI_Datatype * datatype)
158 {
159   int retval = 0;
160   /* Free a predefined datatype is an error according to the standard, and
161      should be checked for */
162   if (*datatype == MPI_DATATYPE_NULL) {
163     retval = MPI_ERR_ARG;
164   } else {
165     smpi_datatype_free(datatype);
166     retval = MPI_SUCCESS;
167   }
168   return retval;
169 }
170
171 int PMPI_Type_size(MPI_Datatype datatype, int *size)
172 {
173   int retval = 0;
174
175   if (datatype == MPI_DATATYPE_NULL) {
176     retval = MPI_ERR_TYPE;
177   } else if (size == NULL) {
178     retval = MPI_ERR_ARG;
179   } else {
180     *size = (int) smpi_datatype_size(datatype);
181     retval = MPI_SUCCESS;
182   }
183   return retval;
184 }
185
186 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
187 {
188   int retval = 0;
189
190   if (datatype == MPI_DATATYPE_NULL) {
191     retval = MPI_ERR_TYPE;
192   } else if (lb == NULL || extent == NULL) {
193     retval = MPI_ERR_ARG;
194   } else {
195     retval = smpi_datatype_extent(datatype, lb, extent);
196   }
197   return retval;
198 }
199
200 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
201 {
202   return PMPI_Type_get_extent(datatype, lb, extent);
203 }
204
205 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
206 {
207   int retval = 0;
208
209   if (datatype == MPI_DATATYPE_NULL) {
210     retval = MPI_ERR_TYPE;
211   } else if (extent == NULL) {
212     retval = MPI_ERR_ARG;
213   } else {
214     *extent = smpi_datatype_get_extent(datatype);
215     retval = MPI_SUCCESS;
216   }
217   return retval;
218 }
219
220 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
221 {
222   int retval = 0;
223
224   if (datatype == MPI_DATATYPE_NULL) {
225     retval = MPI_ERR_TYPE;
226   } else if (disp == NULL) {
227     retval = MPI_ERR_ARG;
228   } else {
229     *disp = smpi_datatype_lb(datatype);
230     retval = MPI_SUCCESS;
231   }
232   return retval;
233 }
234
235 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
236 {
237   int retval = 0;
238
239   if (datatype == MPI_DATATYPE_NULL) {
240     retval = MPI_ERR_TYPE;
241   } else if (disp == NULL) {
242     retval = MPI_ERR_ARG;
243   } else {
244     *disp = smpi_datatype_ub(datatype);
245     retval = MPI_SUCCESS;
246   }
247   return retval;
248 }
249
250 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
251   int retval = 0;
252
253   if (datatype == MPI_DATATYPE_NULL) {
254     retval = MPI_ERR_TYPE;
255   } else {
256     retval = smpi_datatype_dup(datatype, newtype);
257   }
258   return retval;
259 }
260
261 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
262 {
263   int retval = 0;
264
265   if (function == NULL || op == NULL) {
266     retval = MPI_ERR_ARG;
267   } else {
268     *op = smpi_op_new(function, commute);
269     retval = MPI_SUCCESS;
270   }
271   return retval;
272 }
273
274 int PMPI_Op_free(MPI_Op * op)
275 {
276   int retval = 0;
277
278   if (op == NULL) {
279     retval = MPI_ERR_ARG;
280   } else if (*op == MPI_OP_NULL) {
281     retval = MPI_ERR_OP;
282   } else {
283     smpi_op_destroy(*op);
284     *op = MPI_OP_NULL;
285     retval = MPI_SUCCESS;
286   }
287   return retval;
288 }
289
290 int PMPI_Group_free(MPI_Group * group)
291 {
292   int retval = 0;
293
294   if (group == NULL) {
295     retval = MPI_ERR_ARG;
296   } else {
297     smpi_group_destroy(*group);
298     *group = MPI_GROUP_NULL;
299     retval = MPI_SUCCESS;
300   }
301   return retval;
302 }
303
304 int PMPI_Group_size(MPI_Group group, int *size)
305 {
306   int retval = 0;
307
308   if (group == MPI_GROUP_NULL) {
309     retval = MPI_ERR_GROUP;
310   } else if (size == NULL) {
311     retval = MPI_ERR_ARG;
312   } else {
313     *size = smpi_group_size(group);
314     retval = MPI_SUCCESS;
315   }
316   return retval;
317 }
318
319 int PMPI_Group_rank(MPI_Group group, int *rank)
320 {
321   int retval = 0;
322
323   if (group == MPI_GROUP_NULL) {
324     retval = MPI_ERR_GROUP;
325   } else if (rank == NULL) {
326     retval = MPI_ERR_ARG;
327   } else {
328     *rank = smpi_group_rank(group, smpi_process_index());
329     retval = MPI_SUCCESS;
330   }
331   return retval;
332 }
333
334 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
335                               MPI_Group group2, int *ranks2)
336 {
337   int retval, i, index;
338   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
339     retval = MPI_ERR_GROUP;
340   } else {
341     for (i = 0; i < n; i++) {
342       if(ranks1[i]==MPI_PROC_NULL){
343         ranks2[i]=MPI_PROC_NULL;
344       }else{
345         index = smpi_group_index(group1, ranks1[i]);
346         ranks2[i] = smpi_group_rank(group2, index);
347       }
348     }
349     retval = MPI_SUCCESS;
350   }
351   return retval;
352 }
353
354 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
355 {
356   int retval = 0;
357
358   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
359     retval = MPI_ERR_GROUP;
360   } else if (result == NULL) {
361     retval = MPI_ERR_ARG;
362   } else {
363     *result = smpi_group_compare(group1, group2);
364     retval = MPI_SUCCESS;
365   }
366   return retval;
367 }
368
369 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
370                     MPI_Group * newgroup)
371 {
372   int retval, i, proc1, proc2, size, size2;
373
374   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
375     retval = MPI_ERR_GROUP;
376   } else if (newgroup == NULL) {
377     retval = MPI_ERR_ARG;
378   } else {
379     size = smpi_group_size(group1);
380     size2 = smpi_group_size(group2);
381     for (i = 0; i < size2; i++) {
382       proc2 = smpi_group_index(group2, i);
383       proc1 = smpi_group_rank(group1, proc2);
384       if (proc1 == MPI_UNDEFINED) {
385         size++;
386       }
387     }
388     if (size == 0) {
389       *newgroup = MPI_GROUP_EMPTY;
390     } else {
391       *newgroup = smpi_group_new(size);
392       size2 = smpi_group_size(group1);
393       for (i = 0; i < size2; i++) {
394         proc1 = smpi_group_index(group1, i);
395         smpi_group_set_mapping(*newgroup, proc1, i);
396       }
397       for (i = size2; i < size; i++) {
398         proc2 = smpi_group_index(group2, i - size2);
399         smpi_group_set_mapping(*newgroup, proc2, i);
400       }
401     }
402     retval = MPI_SUCCESS;
403   }
404   return retval;
405 }
406
407 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
408                            MPI_Group * newgroup)
409 {
410   int retval, i, proc1, proc2, size;
411
412   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
413     retval = MPI_ERR_GROUP;
414   } else if (newgroup == NULL) {
415     retval = MPI_ERR_ARG;
416   } else {
417     size = smpi_group_size(group2);
418     for (i = 0; i < size; i++) {
419       proc2 = smpi_group_index(group2, i);
420       proc1 = smpi_group_rank(group1, proc2);
421       if (proc1 == MPI_UNDEFINED) {
422         size--;
423       }
424     }
425     if (size == 0) {
426       *newgroup = MPI_GROUP_EMPTY;
427     } else {
428       *newgroup = smpi_group_new(size);
429       int j=0;
430       for (i = 0; i < smpi_group_size(group2); i++) {
431         proc2 = smpi_group_index(group2, i);
432         proc1 = smpi_group_rank(group1, proc2);
433         if (proc1 != MPI_UNDEFINED) {
434           smpi_group_set_mapping(*newgroup, proc2, j);
435           j++;
436         }
437       }
438     }
439     retval = MPI_SUCCESS;
440   }
441   return retval;
442 }
443
444 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
445 {
446   int retval, i, proc1, proc2, size, size2;
447
448   if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
449     retval = MPI_ERR_GROUP;
450   } else if (newgroup == NULL) {
451     retval = MPI_ERR_ARG;
452   } else {
453     size = size2 = smpi_group_size(group1);
454     for (i = 0; i < size2; i++) {
455       proc1 = smpi_group_index(group1, i);
456       proc2 = smpi_group_rank(group2, proc1);
457       if (proc2 != MPI_UNDEFINED) {
458         size--;
459       }
460     }
461     if (size == 0) {
462       *newgroup = MPI_GROUP_EMPTY;
463     } else {
464       *newgroup = smpi_group_new(size);
465       for (i = 0; i < size2; i++) {
466         proc1 = smpi_group_index(group1, i);
467         proc2 = smpi_group_rank(group2, proc1);
468         if (proc2 == MPI_UNDEFINED) {
469           smpi_group_set_mapping(*newgroup, proc1, i);
470         }
471       }
472     }
473     retval = MPI_SUCCESS;
474   }
475   return retval;
476 }
477
478 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
479 {
480   int retval;
481
482   if (group == MPI_GROUP_NULL) {
483     retval = MPI_ERR_GROUP;
484   } else if (newgroup == NULL) {
485     retval = MPI_ERR_ARG;
486   } else {
487     retval = smpi_group_incl(group, n, ranks, newgroup);
488   }
489   return retval;
490 }
491
492 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
493 {
494   int retval, i, j, newsize, oldsize, index;
495
496   if (group == MPI_GROUP_NULL) {
497     retval = MPI_ERR_GROUP;
498   } else if (newgroup == NULL) {
499     retval = MPI_ERR_ARG;
500   } else {
501     if (n == 0) {
502       *newgroup = group;
503       if(group!= smpi_comm_group(MPI_COMM_WORLD)
504                 && group != MPI_GROUP_NULL
505                 && group != smpi_comm_group(MPI_COMM_SELF)
506                 && group != MPI_GROUP_EMPTY)
507       smpi_group_use(group);
508     } else if (n == smpi_group_size(group)) {
509       *newgroup = MPI_GROUP_EMPTY;
510     } else {
511       oldsize=smpi_group_size(group);
512       newsize = oldsize - n;
513       *newgroup = smpi_group_new(newsize);
514
515       int* to_exclude=xbt_new0(int, smpi_group_size(group));
516       for(i=0; i<oldsize; i++)
517         to_exclude[i]=0;
518       for(i=0; i<n; i++)
519         to_exclude[ranks[i]]=1;
520
521       j=0;
522       for(i=0; i<oldsize; i++){
523         if(to_exclude[i]==0){
524           index = smpi_group_index(group, i);
525           smpi_group_set_mapping(*newgroup, index, j);
526           j++;
527         }
528       }
529
530       xbt_free(to_exclude);
531     }
532     retval = MPI_SUCCESS;
533   }
534   return retval;
535 }
536
537 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
538                          MPI_Group * newgroup)
539 {
540   int retval, i, j, rank, size, index;
541
542   if (group == MPI_GROUP_NULL) {
543     retval = MPI_ERR_GROUP;
544   } else if (newgroup == NULL) {
545     retval = MPI_ERR_ARG;
546   } else {
547     if (n == 0) {
548       *newgroup = MPI_GROUP_EMPTY;
549     } else {
550       size = 0;
551       for (i = 0; i < n; i++) {
552         for (rank = ranges[i][0];       /* First */
553              rank >= 0 && rank < smpi_group_size(group); /* Last */
554               ) {
555           size++;
556           if(rank == ranges[i][1]){/*already last ?*/
557             break;
558           }
559           rank += ranges[i][2]; /* Stride */
560           if (ranges[i][0]<ranges[i][1]){
561               if(rank > ranges[i][1])
562                 break;
563           }else{
564               if(rank < ranges[i][1])
565                 break;
566           }
567         }
568       }
569
570       *newgroup = smpi_group_new(size);
571       j = 0;
572       for (i = 0; i < n; i++) {
573         for (rank = ranges[i][0];     /* First */
574              rank >= 0 && rank < smpi_group_size(group); /* Last */
575              ) {
576           index = smpi_group_index(group, rank);
577           smpi_group_set_mapping(*newgroup, index, j);
578           j++;
579           if(rank == ranges[i][1]){/*already last ?*/
580             break;
581           }
582           rank += ranges[i][2]; /* Stride */
583           if (ranges[i][0]<ranges[i][1]){
584             if(rank > ranges[i][1])
585               break;
586           }else{
587             if(rank < ranges[i][1])
588               break;
589           }
590         }
591       }
592     }
593     retval = MPI_SUCCESS;
594   }
595   return retval;
596 }
597
598 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
599                          MPI_Group * newgroup)
600 {
601   int retval, i, rank, newrank,oldrank, size, index, add;
602
603   if (group == MPI_GROUP_NULL) {
604     retval = MPI_ERR_GROUP;
605   } else if (newgroup == NULL) {
606     retval = MPI_ERR_ARG;
607   } else {
608     if (n == 0) {
609       *newgroup = group;
610       if(group!= smpi_comm_group(MPI_COMM_WORLD)
611                 && group != MPI_GROUP_NULL
612                 && group != smpi_comm_group(MPI_COMM_SELF)
613                 && group != MPI_GROUP_EMPTY)
614       smpi_group_use(group);
615     } else {
616       size = smpi_group_size(group);
617       for (i = 0; i < n; i++) {
618         for (rank = ranges[i][0];       /* First */
619              rank >= 0 && rank < smpi_group_size(group); /* Last */
620               ) {
621           size--;
622           if(rank == ranges[i][1]){/*already last ?*/
623             break;
624           }
625           rank += ranges[i][2]; /* Stride */
626           if (ranges[i][0]<ranges[i][1]){
627               if(rank > ranges[i][1])
628                 break;
629           }else{
630               if(rank < ranges[i][1])
631                 break;
632           }
633         }
634       }
635       if (size == 0) {
636         *newgroup = MPI_GROUP_EMPTY;
637       } else {
638         *newgroup = smpi_group_new(size);
639         newrank=0;
640         oldrank=0;
641         while (newrank < size) {
642           add=1;
643           for (i = 0; i < n; i++) {
644             for (rank = ranges[i][0];
645                 rank >= 0 && rank < smpi_group_size(group);
646                 ){
647               if(rank==oldrank){
648                   add=0;
649                   break;
650               }
651               if(rank == ranges[i][1]){/*already last ?*/
652                 break;
653               }
654               rank += ranges[i][2]; /* Stride */
655               if (ranges[i][0]<ranges[i][1]){
656                   if(rank > ranges[i][1])
657                     break;
658               }else{
659                   if(rank < ranges[i][1])
660                     break;
661               }
662             }
663           }
664           if(add==1){
665             index = smpi_group_index(group, oldrank);
666             smpi_group_set_mapping(*newgroup, index, newrank);
667             newrank++;
668           }
669           oldrank++;
670         }
671       }
672     }
673
674     retval = MPI_SUCCESS;
675   }
676   return retval;
677 }
678
679 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
680 {
681   int retval = 0;
682   if (comm == MPI_COMM_NULL) {
683     retval = MPI_ERR_COMM;
684   } else if (rank == NULL) {
685     retval = MPI_ERR_ARG;
686   } else {
687     *rank = smpi_comm_rank(comm);
688     retval = MPI_SUCCESS;
689   }
690   return retval;
691 }
692
693 int PMPI_Comm_size(MPI_Comm comm, int *size)
694 {
695   int retval = 0;
696   if (comm == MPI_COMM_NULL) {
697     retval = MPI_ERR_COMM;
698   } else if (size == NULL) {
699     retval = MPI_ERR_ARG;
700   } else {
701     *size = smpi_comm_size(comm);
702     retval = MPI_SUCCESS;
703   }
704   return retval;
705 }
706
707 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
708 {
709   int retval = 0;
710
711   if (comm == MPI_COMM_NULL)  {
712     retval = MPI_ERR_COMM;
713   } else if (name == NULL || len == NULL)  {
714     retval = MPI_ERR_ARG;
715   } else {
716     smpi_comm_get_name(comm, name, len);
717     retval = MPI_SUCCESS;
718   }
719   return retval;
720 }
721
722 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
723 {
724   int retval = 0;
725
726   if (comm == MPI_COMM_NULL) {
727     retval = MPI_ERR_COMM;
728   } else if (group == NULL) {
729     retval = MPI_ERR_ARG;
730   } else {
731     *group = smpi_comm_group(comm);
732     if(*group!= smpi_comm_group(MPI_COMM_WORLD)
733               && *group != MPI_GROUP_NULL
734               && *group != smpi_comm_group(MPI_COMM_SELF)
735               && *group != MPI_GROUP_EMPTY)
736     smpi_group_use(*group);
737     retval = MPI_SUCCESS;
738   }
739   return retval;
740 }
741
742 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
743 {
744   int retval = 0;
745
746   if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
747     retval = MPI_ERR_COMM;
748   } else if (result == NULL) {
749     retval = MPI_ERR_ARG;
750   } else {
751     if (comm1 == comm2) {       /* Same communicators means same groups */
752       *result = MPI_IDENT;
753     } else {
754       *result =
755           smpi_group_compare(smpi_comm_group(comm1),
756                              smpi_comm_group(comm2));
757       if (*result == MPI_IDENT) {
758         *result = MPI_CONGRUENT;
759       }
760     }
761     retval = MPI_SUCCESS;
762   }
763   return retval;
764 }
765
766 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
767 {
768   int retval = 0;
769
770   if (comm == MPI_COMM_NULL) {
771     retval = MPI_ERR_COMM;
772   } else if (newcomm == NULL) {
773     retval = MPI_ERR_ARG;
774   } else {
775     retval = smpi_comm_dup(comm, newcomm);
776   }
777   return retval;
778 }
779
780 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
781 {
782   int retval = 0;
783
784   if (comm == MPI_COMM_NULL) {
785     retval = MPI_ERR_COMM;
786   } else if (group == MPI_GROUP_NULL) {
787     retval = MPI_ERR_GROUP;
788   } else if (newcomm == NULL) {
789     retval = MPI_ERR_ARG;
790   } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
791     *newcomm= MPI_COMM_NULL;
792     retval = MPI_SUCCESS;
793   }else{
794
795     *newcomm = smpi_comm_new(group, NULL);
796     retval = MPI_SUCCESS;
797   }
798   return retval;
799 }
800
801 int PMPI_Comm_free(MPI_Comm * comm)
802 {
803   int retval = 0;
804
805   if (comm == NULL) {
806     retval = MPI_ERR_ARG;
807   } else if (*comm == MPI_COMM_NULL) {
808     retval = MPI_ERR_COMM;
809   } else {
810     smpi_comm_destroy(*comm);
811     *comm = MPI_COMM_NULL;
812     retval = MPI_SUCCESS;
813   }
814   return retval;
815 }
816
817 int PMPI_Comm_disconnect(MPI_Comm * comm)
818 {
819   /* TODO: wait until all communication in comm are done */
820   int retval = 0;
821
822   if (comm == NULL) {
823     retval = MPI_ERR_ARG;
824   } else if (*comm == MPI_COMM_NULL) {
825     retval = MPI_ERR_COMM;
826   } else {
827     smpi_comm_destroy(*comm);
828     *comm = MPI_COMM_NULL;
829     retval = MPI_SUCCESS;
830   }
831   return retval;
832 }
833
834 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
835 {
836   int retval = 0;
837   smpi_bench_end();
838
839   if (comm_out == NULL) {
840     retval = MPI_ERR_ARG;
841   } else if (comm == MPI_COMM_NULL) {
842     retval = MPI_ERR_COMM;
843   } else {
844     *comm_out = smpi_comm_split(comm, color, key);
845     retval = MPI_SUCCESS;
846   }
847   smpi_bench_begin();
848
849   return retval;
850 }
851
852 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
853                    int tag, MPI_Comm comm, MPI_Request * request)
854 {
855   int retval = 0;
856
857   smpi_bench_end();
858   if (request == NULL) {
859       retval = MPI_ERR_ARG;
860   } else if (comm == MPI_COMM_NULL) {
861       retval = MPI_ERR_COMM;
862   } else if (!is_datatype_valid(datatype)) {
863       retval = MPI_ERR_TYPE;
864   } else if (dst == MPI_PROC_NULL) {
865       retval = MPI_SUCCESS;
866   } else {
867       *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
868       retval = MPI_SUCCESS;
869   }
870   smpi_bench_begin();
871   if (retval != MPI_SUCCESS && request)
872     *request = MPI_REQUEST_NULL;
873   return retval;
874 }
875
876 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
877                    int tag, MPI_Comm comm, MPI_Request * request)
878 {
879   int retval = 0;
880
881   smpi_bench_end();
882   if (request == NULL) {
883     retval = MPI_ERR_ARG;
884   } else if (comm == MPI_COMM_NULL) {
885     retval = MPI_ERR_COMM;
886   } else if (!is_datatype_valid(datatype)) {
887       retval = MPI_ERR_TYPE;
888   } else if (src == MPI_PROC_NULL) {
889     retval = MPI_SUCCESS;
890   } else {
891     *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
892     retval = MPI_SUCCESS;
893   }
894   smpi_bench_begin();
895   if (retval != MPI_SUCCESS && request)
896     *request = MPI_REQUEST_NULL;
897   return retval;
898 }
899
900 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
901                     int dst, int tag, MPI_Comm comm, MPI_Request* request)
902 {
903   int retval = 0;
904
905   smpi_bench_end();
906   if (request == NULL) {
907     retval = MPI_ERR_ARG;
908   } else if (comm == MPI_COMM_NULL) {
909     retval = MPI_ERR_COMM;
910   } else if (!is_datatype_valid(datatype)) {
911       retval = MPI_ERR_TYPE;
912   } else if (dst == MPI_PROC_NULL) {
913     retval = MPI_SUCCESS;
914   } else {
915     *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
916     retval = MPI_SUCCESS;
917   }
918   smpi_bench_begin();
919   if (retval != MPI_SUCCESS && request)
920     *request = MPI_REQUEST_NULL;
921   return retval;
922 }
923
924 int PMPI_Start(MPI_Request * request)
925 {
926   int retval = 0;
927
928   smpi_bench_end();
929   if (request == NULL || *request == MPI_REQUEST_NULL) {
930     retval = MPI_ERR_REQUEST;
931   } else {
932     smpi_mpi_start(*request);
933     retval = MPI_SUCCESS;
934   }
935   smpi_bench_begin();
936   return retval;
937 }
938
939 int PMPI_Startall(int count, MPI_Request * requests)
940 {
941   int retval;
942   int i = 0;
943   smpi_bench_end();
944   if (requests == NULL) {
945     retval = MPI_ERR_ARG;
946   } else {
947     retval = MPI_SUCCESS;
948     for (i = 0 ;  i < count ; i++) {
949       if(requests[i] == MPI_REQUEST_NULL) {
950         retval = MPI_ERR_REQUEST;
951       }
952     }
953     if(retval != MPI_ERR_REQUEST) {
954       smpi_mpi_startall(count, requests);
955     }
956   }
957   smpi_bench_begin();
958   return retval;
959 }
960
961 int PMPI_Request_free(MPI_Request * request)
962 {
963   int retval = 0;
964
965   smpi_bench_end();
966   if (*request == MPI_REQUEST_NULL) {
967     retval = MPI_ERR_ARG;
968   } else {
969     smpi_mpi_request_free(request);
970     retval = MPI_SUCCESS;
971   }
972   smpi_bench_begin();
973   return retval;
974 }
975
976 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
977                int tag, MPI_Comm comm, MPI_Request * request)
978 {
979   int retval = 0;
980
981   smpi_bench_end();
982
983   if (request == NULL) {
984     retval = MPI_ERR_ARG;
985   } else if (comm == MPI_COMM_NULL) {
986     retval = MPI_ERR_COMM;
987   } else if (src == MPI_PROC_NULL) {
988     *request = MPI_REQUEST_NULL;
989     retval = MPI_SUCCESS;
990   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
991     retval = MPI_ERR_RANK;
992   } else if (count < 0) {
993     retval = MPI_ERR_COUNT;
994   } else if (buf==NULL && count > 0) {
995     retval = MPI_ERR_COUNT;
996   } else if (!is_datatype_valid(datatype)) {
997       retval = MPI_ERR_TYPE;
998   } else if(tag<0 && tag !=  MPI_ANY_TAG){
999     retval = MPI_ERR_TAG;
1000   } else {
1001
1002 #ifdef HAVE_TRACING
1003     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1004     int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1005
1006     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1007     extra->type = TRACING_IRECV;
1008     extra->src = src_traced;
1009     extra->dst = rank;
1010     int known=0;
1011     extra->datatype1 = encode_datatype(datatype, &known);
1012     int dt_size_send = 1;
1013     if(!known)
1014       dt_size_send = smpi_datatype_size(datatype);
1015     extra->send_size = count*dt_size_send;
1016     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1017 #endif
1018
1019     *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1020     retval = MPI_SUCCESS;
1021
1022 #ifdef HAVE_TRACING
1023     TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1024     (*request)->recv = 1;
1025 #endif
1026   }
1027
1028   smpi_bench_begin();
1029   if (retval != MPI_SUCCESS && request)
1030     *request = MPI_REQUEST_NULL;
1031   return retval;
1032 }
1033
1034
1035 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1036                int tag, MPI_Comm comm, MPI_Request * request)
1037 {
1038   int retval = 0;
1039
1040   smpi_bench_end();
1041   if (request == NULL) {
1042     retval = MPI_ERR_ARG;
1043   } else if (comm == MPI_COMM_NULL) {
1044     retval = MPI_ERR_COMM;
1045   } else if (dst == MPI_PROC_NULL) {
1046     *request = MPI_REQUEST_NULL;
1047     retval = MPI_SUCCESS;
1048   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1049     retval = MPI_ERR_RANK;
1050   } else if (count < 0) {
1051     retval = MPI_ERR_COUNT;
1052   } else if (buf==NULL && count > 0) {
1053     retval = MPI_ERR_COUNT;
1054   } else if (!is_datatype_valid(datatype)) {
1055       retval = MPI_ERR_TYPE;
1056   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1057     retval = MPI_ERR_TAG;
1058   } else {
1059
1060 #ifdef HAVE_TRACING
1061     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1062     int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1063     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1064     extra->type = TRACING_ISEND;
1065     extra->src = rank;
1066     extra->dst = dst_traced;
1067     int known=0;
1068     extra->datatype1 = encode_datatype(datatype, &known);
1069     int dt_size_send = 1;
1070     if(!known)
1071       dt_size_send = smpi_datatype_size(datatype);
1072     extra->send_size = count*dt_size_send;
1073     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1074     TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1075 #endif
1076
1077     *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1078     retval = MPI_SUCCESS;
1079
1080 #ifdef HAVE_TRACING
1081     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1082     (*request)->send = 1;
1083 #endif
1084   }
1085
1086   smpi_bench_begin();
1087   if (retval != MPI_SUCCESS && request)
1088     *request = MPI_REQUEST_NULL;
1089   return retval;
1090 }
1091
1092 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1093                 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1094 {
1095   int retval = 0;
1096
1097   smpi_bench_end();
1098   if (request == NULL) {
1099     retval = MPI_ERR_ARG;
1100   } else if (comm == MPI_COMM_NULL) {
1101     retval = MPI_ERR_COMM;
1102   } else if (dst == MPI_PROC_NULL) {
1103     *request = MPI_REQUEST_NULL;
1104     retval = MPI_SUCCESS;
1105   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1106     retval = MPI_ERR_RANK;
1107   } else if (count < 0) {
1108     retval = MPI_ERR_COUNT;
1109   } else if (buf==NULL && count > 0) {
1110     retval = MPI_ERR_COUNT;
1111   } else if (!is_datatype_valid(datatype)) {
1112       retval = MPI_ERR_TYPE;
1113   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1114     retval = MPI_ERR_TAG;
1115   } else {
1116
1117 #ifdef HAVE_TRACING
1118     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1119     int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1120     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1121     extra->type = TRACING_ISSEND;
1122     extra->src = rank;
1123     extra->dst = dst_traced;
1124     int known=0;
1125     extra->datatype1 = encode_datatype(datatype, &known);
1126     int dt_size_send = 1;
1127     if(!known)
1128       dt_size_send = smpi_datatype_size(datatype);
1129     extra->send_size = count*dt_size_send;
1130     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1131     TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1132 #endif
1133
1134     *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1135     retval = MPI_SUCCESS;
1136
1137 #ifdef HAVE_TRACING
1138     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1139     (*request)->send = 1;
1140 #endif
1141   }
1142
1143   smpi_bench_begin();
1144   if (retval != MPI_SUCCESS && request)
1145     *request = MPI_REQUEST_NULL;
1146   return retval;
1147 }
1148
1149 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1150              MPI_Comm comm, MPI_Status * status)
1151 {
1152   int retval = 0;
1153
1154   smpi_bench_end();
1155   if (comm == MPI_COMM_NULL) {
1156     retval = MPI_ERR_COMM;
1157   } else if (src == MPI_PROC_NULL) {
1158     smpi_empty_status(status);
1159     status->MPI_SOURCE = MPI_PROC_NULL;
1160     retval = MPI_SUCCESS;
1161   } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1162     retval = MPI_ERR_RANK;
1163   } else if (count < 0) {
1164     retval = MPI_ERR_COUNT;
1165   } else if (buf==NULL && count > 0) {
1166     retval = MPI_ERR_COUNT;
1167   } else if (!is_datatype_valid(datatype)) {
1168       retval = MPI_ERR_TYPE;
1169   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1170     retval = MPI_ERR_TAG;
1171   } else {
1172 #ifdef HAVE_TRACING
1173   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1174   int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1175   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1176   extra->type = TRACING_RECV;
1177   extra->src = src_traced;
1178   extra->dst = rank;
1179   int known=0;
1180   extra->datatype1 = encode_datatype(datatype, &known);
1181   int dt_size_send = 1;
1182   if(!known)
1183     dt_size_send = smpi_datatype_size(datatype);
1184   extra->send_size = count*dt_size_send;
1185   TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1186 #endif
1187
1188     smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1189     retval = MPI_SUCCESS;
1190
1191 #ifdef HAVE_TRACING
1192   //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1193   if(status!=MPI_STATUS_IGNORE){
1194     src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1195     TRACE_smpi_recv(rank, src_traced, rank);
1196   }
1197   TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1198 #endif
1199   }
1200
1201   smpi_bench_begin();
1202   return retval;
1203 }
1204
1205 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1206              MPI_Comm comm)
1207 {
1208   int retval = 0;
1209
1210   smpi_bench_end();
1211
1212   if (comm == MPI_COMM_NULL) {
1213     retval = MPI_ERR_COMM;
1214   } else if (dst == MPI_PROC_NULL) {
1215     retval = MPI_SUCCESS;
1216   } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1217     retval = MPI_ERR_RANK;
1218   } else if (count < 0) {
1219     retval = MPI_ERR_COUNT;
1220   } else if (buf==NULL && count > 0) {
1221     retval = MPI_ERR_COUNT;
1222   } else if (!is_datatype_valid(datatype)) {
1223       retval = MPI_ERR_TYPE;
1224   } else if(tag<0 && tag !=  MPI_ANY_TAG){
1225     retval = MPI_ERR_TAG;
1226   } else {
1227
1228 #ifdef HAVE_TRACING
1229   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1230   int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1231   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1232   extra->type = TRACING_SEND;
1233   extra->src = rank;
1234   extra->dst = dst_traced;
1235   int known=0;
1236   extra->datatype1 = encode_datatype(datatype, &known);
1237   int dt_size_send = 1;
1238   if(!known)
1239     dt_size_send = smpi_datatype_size(datatype);
1240   extra->send_size = count*dt_size_send;
1241   TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1242   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1243 #endif
1244
1245     smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1246     retval = MPI_SUCCESS;
1247
1248 #ifdef HAVE_TRACING
1249   TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1250 #endif
1251   }
1252
1253   smpi_bench_begin();
1254   return retval;
1255 }
1256
1257
1258
1259 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1260   int retval = 0;
1261
1262    smpi_bench_end();
1263
1264    if (comm == MPI_COMM_NULL) {
1265      retval = MPI_ERR_COMM;
1266    } else if (dst == MPI_PROC_NULL) {
1267      retval = MPI_SUCCESS;
1268    } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1269      retval = MPI_ERR_RANK;
1270    } else if (count < 0) {
1271      retval = MPI_ERR_COUNT;
1272    } else if (buf==NULL && count > 0) {
1273      retval = MPI_ERR_COUNT;
1274    } else if (!is_datatype_valid(datatype)){
1275      retval = MPI_ERR_TYPE;
1276    } else if(tag<0 && tag !=  MPI_ANY_TAG){
1277      retval = MPI_ERR_TAG;
1278    } else {
1279
1280  #ifdef HAVE_TRACING
1281    int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1282    int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1283    instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1284    extra->type = TRACING_SSEND;
1285    extra->src = rank;
1286    extra->dst = dst_traced;
1287    int known=0;
1288    extra->datatype1 = encode_datatype(datatype, &known);
1289    int dt_size_send = 1;
1290    if(!known)
1291      dt_size_send = smpi_datatype_size(datatype);
1292    extra->send_size = count*dt_size_send;
1293    TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);   TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1294  #endif
1295
1296      smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1297      retval = MPI_SUCCESS;
1298
1299  #ifdef HAVE_TRACING
1300    TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1301  #endif
1302    }
1303
1304    smpi_bench_begin();
1305    return retval;}
1306
1307
1308 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1309                  int dst, int sendtag, void *recvbuf, int recvcount,
1310                  MPI_Datatype recvtype, int src, int recvtag,
1311                  MPI_Comm comm, MPI_Status * status)
1312 {
1313   int retval = 0;
1314
1315   smpi_bench_end();
1316
1317   if (comm == MPI_COMM_NULL) {
1318     retval = MPI_ERR_COMM;
1319   } else if (!is_datatype_valid(sendtype)
1320              || !is_datatype_valid(recvtype)) {
1321     retval = MPI_ERR_TYPE;
1322   } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1323       smpi_empty_status(status);
1324       status->MPI_SOURCE = MPI_PROC_NULL;
1325       retval = MPI_SUCCESS;
1326   }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1327       (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1328     retval = MPI_ERR_RANK;
1329   } else if (sendcount < 0 || recvcount<0) {
1330       retval = MPI_ERR_COUNT;
1331   } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1332     retval = MPI_ERR_COUNT;
1333   } else if((sendtag<0 && sendtag !=  MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1334     retval = MPI_ERR_TAG;
1335   } else {
1336
1337 #ifdef HAVE_TRACING
1338   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
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   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1342   extra->type = TRACING_SENDRECV;
1343   extra->src = src_traced;
1344   extra->dst = dst_traced;
1345   int known=0;
1346   extra->datatype1 = encode_datatype(sendtype, &known);
1347   int dt_size_send = 1;
1348   if(!known)
1349     dt_size_send = smpi_datatype_size(sendtype);
1350   extra->send_size = sendcount*dt_size_send;
1351   extra->datatype2 = encode_datatype(recvtype, &known);
1352   int dt_size_recv = 1;
1353   if(!known)
1354     dt_size_recv = smpi_datatype_size(recvtype);
1355   extra->recv_size = recvcount*dt_size_recv;
1356
1357   TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1358   TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1359 #endif
1360
1361
1362     smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1363                       recvcount, recvtype, src, recvtag, comm, status);
1364     retval = MPI_SUCCESS;
1365
1366 #ifdef HAVE_TRACING
1367   TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1368   TRACE_smpi_recv(rank, src_traced, rank);
1369 #endif
1370
1371   }
1372
1373   smpi_bench_begin();
1374   return retval;
1375 }
1376
1377 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1378                          int dst, int sendtag, int src, int recvtag,
1379                          MPI_Comm comm, MPI_Status * status)
1380 {
1381   //TODO: suboptimal implementation
1382   void *recvbuf;
1383   int retval = 0;
1384   if (!is_datatype_valid(datatype)) {
1385       retval = MPI_ERR_TYPE;
1386   } else if (count < 0) {
1387       retval = MPI_ERR_COUNT;
1388   } else {
1389     int size = smpi_datatype_get_extent(datatype) * count;
1390     recvbuf = xbt_new0(char, size);
1391     retval =
1392         MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1393                      datatype, src, recvtag, comm, status);
1394     if(retval==MPI_SUCCESS){
1395         smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1396     }
1397     xbt_free(recvbuf);
1398
1399   }
1400   return retval;
1401 }
1402
1403 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1404 {
1405   int retval = 0;
1406   smpi_bench_end();
1407   if (request == NULL || flag == NULL) {
1408     retval = MPI_ERR_ARG;
1409   } else if (*request == MPI_REQUEST_NULL) {
1410     *flag= TRUE;
1411     smpi_empty_status(status);
1412     retval = MPI_SUCCESS;
1413   } else {
1414 #ifdef HAVE_TRACING
1415     int rank = request && (*request)->comm != MPI_COMM_NULL
1416       ? smpi_process_index()
1417       : -1;
1418
1419     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1420     extra->type = TRACING_TEST;
1421     TRACE_smpi_testing_in(rank, extra);
1422 #endif
1423     *flag = smpi_mpi_test(request, status);
1424 #ifdef HAVE_TRACING
1425     TRACE_smpi_testing_out(rank);
1426 #endif
1427     retval = MPI_SUCCESS;
1428   }
1429   smpi_bench_begin();
1430   return retval;
1431 }
1432
1433 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1434                 MPI_Status * status)
1435 {
1436   int retval = 0;
1437
1438   smpi_bench_end();
1439   if (index == NULL || flag == NULL) {
1440     retval = MPI_ERR_ARG;
1441   } else {
1442     *flag = smpi_mpi_testany(count, requests, index, status);
1443     retval = MPI_SUCCESS;
1444   }
1445   smpi_bench_begin();
1446   return retval;
1447 }
1448
1449 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1450 {
1451   int retval = 0;
1452
1453   smpi_bench_end();
1454   if (flag == NULL) {
1455     retval = MPI_ERR_ARG;
1456   } else {
1457     *flag = smpi_mpi_testall(count, requests, statuses);
1458     retval = MPI_SUCCESS;
1459   }
1460   smpi_bench_begin();
1461   return retval;
1462 }
1463
1464 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1465   int retval = 0;
1466   smpi_bench_end();
1467
1468   if (status == NULL) {
1469     retval = MPI_ERR_ARG;
1470   } else if (comm == MPI_COMM_NULL) {
1471     retval = MPI_ERR_COMM;
1472   } else if (source == MPI_PROC_NULL) {
1473     smpi_empty_status(status);
1474     status->MPI_SOURCE = MPI_PROC_NULL;
1475     retval = MPI_SUCCESS;
1476   } else {
1477     smpi_mpi_probe(source, tag, comm, status);
1478     retval = MPI_SUCCESS;
1479   }
1480   smpi_bench_begin();
1481   return retval;
1482 }
1483
1484
1485 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1486   int retval = 0;
1487   smpi_bench_end();
1488
1489   if (flag == NULL) {
1490     retval = MPI_ERR_ARG;
1491   } else if (status == NULL) {
1492     retval = MPI_ERR_ARG;
1493   } else if (comm == MPI_COMM_NULL) {
1494     retval = MPI_ERR_COMM;
1495   } else if (source == MPI_PROC_NULL) {
1496     *flag=TRUE;
1497     smpi_empty_status(status);
1498     status->MPI_SOURCE = MPI_PROC_NULL;
1499     retval = MPI_SUCCESS;
1500   } else {
1501     smpi_mpi_iprobe(source, tag, comm, flag, status);
1502     retval = MPI_SUCCESS;
1503   }
1504   smpi_bench_begin();
1505   return retval;
1506 }
1507
1508 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1509 {
1510   int retval = 0;
1511
1512   smpi_bench_end();
1513
1514   smpi_empty_status(status);
1515
1516   if (request == NULL) {
1517     retval = MPI_ERR_ARG;
1518   } else if (*request == MPI_REQUEST_NULL) {
1519     retval = MPI_SUCCESS;
1520   } else {
1521
1522 #ifdef HAVE_TRACING
1523     int rank = request && (*request)->comm != MPI_COMM_NULL
1524       ? smpi_process_index()
1525       : -1;
1526
1527     int src_traced = (*request)->src;
1528     int dst_traced = (*request)->dst;
1529     MPI_Comm comm = (*request)->comm;
1530     int is_wait_for_receive = (*request)->recv;
1531     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1532     extra->type = TRACING_WAIT;
1533     TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1534 #endif
1535
1536     smpi_mpi_wait(request, status);
1537     retval = MPI_SUCCESS;
1538
1539 #ifdef HAVE_TRACING
1540     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1541     TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1542     if (is_wait_for_receive) {
1543       if(src_traced==MPI_ANY_SOURCE)
1544         src_traced = (status!=MPI_STATUS_IGNORE) ?
1545           smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1546           src_traced;
1547       TRACE_smpi_recv(rank, src_traced, dst_traced);
1548     }
1549 #endif
1550
1551   }
1552
1553   smpi_bench_begin();
1554   return retval;
1555 }
1556
1557 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1558 {
1559   if (index == NULL)
1560     return MPI_ERR_ARG;
1561
1562   smpi_bench_end();
1563 #ifdef HAVE_TRACING
1564   //save requests information for tracing
1565   int i;
1566   int *srcs = xbt_new0(int, count);
1567   int *dsts = xbt_new0(int, count);
1568   int *recvs = xbt_new0(int, count);
1569   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1570
1571   for (i = 0; i < count; i++) {
1572     MPI_Request req = requests[i];      //already received requests are no longer valid
1573     if (req) {
1574       srcs[i] = req->src;
1575       dsts[i] = req->dst;
1576       recvs[i] = req->recv;
1577       comms[i] = req->comm;
1578     }
1579   }
1580   int rank_traced = smpi_process_index();
1581   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1582   extra->type = TRACING_WAITANY;
1583   extra->send_size=count;
1584   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1585
1586 #endif
1587   *index = smpi_mpi_waitany(count, requests, status);
1588 #ifdef HAVE_TRACING
1589   if(*index!=MPI_UNDEFINED){
1590     int src_traced = srcs[*index];
1591     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1592     int dst_traced = dsts[*index];
1593     int is_wait_for_receive = recvs[*index];
1594     if (is_wait_for_receive) {
1595       if(srcs[*index]==MPI_ANY_SOURCE)
1596         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1597                       smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1598                       srcs[*index];
1599       TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1600     }
1601     TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1602     xbt_free(srcs);
1603     xbt_free(dsts);
1604     xbt_free(recvs);
1605     xbt_free(comms);
1606
1607   }
1608 #endif
1609   smpi_bench_begin();
1610   return MPI_SUCCESS;
1611 }
1612
1613 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1614 {
1615
1616   smpi_bench_end();
1617 #ifdef HAVE_TRACING
1618   //save information from requests
1619   int i;
1620   int *srcs = xbt_new0(int, count);
1621   int *dsts = xbt_new0(int, count);
1622   int *recvs = xbt_new0(int, count);
1623   int *valid = xbt_new0(int, count);
1624   MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1625
1626   //int valid_count = 0;
1627   for (i = 0; i < count; i++) {
1628     MPI_Request req = requests[i];
1629     if(req!=MPI_REQUEST_NULL){
1630       srcs[i] = req->src;
1631       dsts[i] = req->dst;
1632       recvs[i] = req->recv;
1633       comms[i] = req->comm;
1634       valid[i]=1;;
1635     }else{
1636       valid[i]=0;
1637     }
1638   }
1639   int rank_traced = smpi_process_index();
1640   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1641   extra->type = TRACING_WAITALL;
1642   extra->send_size=count;
1643   TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1644 #endif
1645   int retval = smpi_mpi_waitall(count, requests, status);
1646 #ifdef HAVE_TRACING
1647   for (i = 0; i < count; i++) {
1648     if(valid[i]){
1649     //int src_traced = srcs[*index];
1650     //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1651       int src_traced = srcs[i];
1652       int dst_traced = dsts[i];
1653       int is_wait_for_receive = recvs[i];
1654       if (is_wait_for_receive) {
1655         if(src_traced==MPI_ANY_SOURCE)
1656         src_traced = (status!=MPI_STATUSES_IGNORE) ?
1657                           smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1658                           srcs[i];
1659         TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1660       }
1661     }
1662   }
1663   TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1664   xbt_free(srcs);
1665   xbt_free(dsts);
1666   xbt_free(recvs);
1667   xbt_free(valid);
1668   xbt_free(comms);
1669
1670 #endif
1671   smpi_bench_begin();
1672   return retval;
1673 }
1674
1675 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1676                  int *indices, MPI_Status status[])
1677 {
1678   int retval = 0;
1679
1680   smpi_bench_end();
1681   if (outcount == NULL) {
1682     retval = MPI_ERR_ARG;
1683   } else {
1684     *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1685     retval = MPI_SUCCESS;
1686   }
1687   smpi_bench_begin();
1688   return retval;
1689 }
1690
1691 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1692                  int* indices, MPI_Status status[])
1693 {
1694   int retval = 0;
1695
1696    smpi_bench_end();
1697    if (outcount == NULL) {
1698      retval = MPI_ERR_ARG;
1699    } else {
1700      *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1701      retval = MPI_SUCCESS;
1702    }
1703    smpi_bench_begin();
1704    return retval;
1705 }
1706
1707
1708 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1709 {
1710   int retval = 0;
1711
1712   smpi_bench_end();
1713
1714   if (comm == MPI_COMM_NULL) {
1715     retval = MPI_ERR_COMM;
1716   } else if (!is_datatype_valid(datatype)) {
1717       retval = MPI_ERR_ARG;
1718   } else {
1719 #ifdef HAVE_TRACING
1720   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1721   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1722
1723   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1724   extra->type = TRACING_BCAST;
1725   extra->root = root_traced;
1726   int known=0;
1727   extra->datatype1 = encode_datatype(datatype, &known);
1728   int dt_size_send = 1;
1729   if(!known)
1730     dt_size_send = smpi_datatype_size(datatype);
1731   extra->send_size = count*dt_size_send;
1732   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1733
1734 #endif
1735     mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1736     retval = MPI_SUCCESS;
1737 #ifdef HAVE_TRACING
1738   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1739 #endif
1740   }
1741
1742   smpi_bench_begin();
1743   return retval;
1744 }
1745
1746 int PMPI_Barrier(MPI_Comm comm)
1747 {
1748   int retval = 0;
1749
1750   smpi_bench_end();
1751
1752   if (comm == MPI_COMM_NULL) {
1753     retval = MPI_ERR_COMM;
1754   } else {
1755 #ifdef HAVE_TRACING
1756   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1757   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1758   extra->type = TRACING_BARRIER;
1759   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1760 #endif
1761     mpi_coll_barrier_fun(comm);
1762     retval = MPI_SUCCESS;
1763 #ifdef HAVE_TRACING
1764   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1765 #endif
1766   }
1767
1768   smpi_bench_begin();
1769   return retval;
1770 }
1771
1772 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1773                void *recvbuf, int recvcount, MPI_Datatype recvtype,
1774                int root, MPI_Comm comm)
1775 {
1776   int retval = 0;
1777
1778   smpi_bench_end();
1779
1780   if (comm == MPI_COMM_NULL) {
1781     retval = MPI_ERR_COMM;
1782   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1783             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1784     retval = MPI_ERR_TYPE;
1785   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1786             ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1787     retval = MPI_ERR_COUNT;
1788   } else {
1789
1790     char* sendtmpbuf = (char*) sendbuf;
1791     int sendtmpcount = sendcount;
1792     MPI_Datatype sendtmptype = sendtype;
1793     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1794       sendtmpcount=0;
1795       sendtmptype=recvtype;
1796     }
1797 #ifdef HAVE_TRACING
1798   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1799   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1800   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1801   extra->type = TRACING_GATHER;
1802   extra->root = root_traced;
1803   int known=0;
1804   extra->datatype1 = encode_datatype(sendtmptype, &known);
1805   int dt_size_send = 1;
1806   if(!known)
1807     dt_size_send = smpi_datatype_size(sendtmptype);
1808   extra->send_size = sendtmpcount*dt_size_send;
1809   extra->datatype2 = encode_datatype(recvtype, &known);
1810   int dt_size_recv = 1;
1811   if((smpi_comm_rank(comm)==root) && !known)
1812     dt_size_recv = smpi_datatype_size(recvtype);
1813   extra->recv_size = recvcount*dt_size_recv;
1814
1815   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1816 #endif
1817     mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1818                     recvtype, root, comm);
1819
1820
1821     retval = MPI_SUCCESS;
1822 #ifdef HAVE_TRACING
1823   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1824 #endif
1825   }
1826
1827   smpi_bench_begin();
1828   return retval;
1829 }
1830
1831 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1832                 void *recvbuf, int *recvcounts, int *displs,
1833                 MPI_Datatype recvtype, int root, MPI_Comm comm)
1834 {
1835   int retval = 0;
1836
1837   smpi_bench_end();
1838
1839   if (comm == MPI_COMM_NULL) {
1840     retval = MPI_ERR_COMM;
1841   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1842             ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1843     retval = MPI_ERR_TYPE;
1844   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1845     retval = MPI_ERR_COUNT;
1846   } else if (recvcounts == NULL || displs == NULL) {
1847     retval = MPI_ERR_ARG;
1848   } else {
1849     char* sendtmpbuf = (char*) sendbuf;
1850     int sendtmpcount = sendcount;
1851     MPI_Datatype sendtmptype = sendtype;
1852     if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1853       sendtmpcount=0;
1854       sendtmptype=recvtype;
1855     }
1856
1857 #ifdef HAVE_TRACING
1858   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1859   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1860   int i=0;
1861   int size = smpi_comm_size(comm);
1862   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1863   extra->type = TRACING_GATHERV;
1864   extra->num_processes = size;
1865   extra->root = root_traced;
1866   int known=0;
1867   extra->datatype1 = encode_datatype(sendtmptype, &known);
1868   int dt_size_send = 1;
1869   if(!known)
1870     dt_size_send = smpi_datatype_size(sendtype);
1871   extra->send_size = sendtmpcount*dt_size_send;
1872   extra->datatype2 = encode_datatype(recvtype, &known);
1873   int dt_size_recv = 1;
1874   if(!known)
1875     dt_size_recv = smpi_datatype_size(recvtype);
1876   extra->recvcounts= xbt_malloc(size*sizeof(int));
1877   for(i=0; i< size; i++)//copy data to avoid bad free
1878     extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1879
1880   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1881 #endif
1882     smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1883                      displs, recvtype, root, comm);
1884     retval = MPI_SUCCESS;
1885 #ifdef HAVE_TRACING
1886   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1887 #endif
1888   }
1889
1890   smpi_bench_begin();
1891   return retval;
1892 }
1893
1894 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1895                   void *recvbuf, int recvcount, MPI_Datatype recvtype,
1896                   MPI_Comm comm)
1897 {
1898   int retval = 0;
1899
1900   smpi_bench_end();
1901
1902   if (comm == MPI_COMM_NULL) {
1903     retval = MPI_ERR_COMM;
1904   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1905             (recvtype == MPI_DATATYPE_NULL)){
1906     retval = MPI_ERR_TYPE;
1907   } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1908             (recvcount <0)){
1909     retval = MPI_ERR_COUNT;
1910   } else {
1911     if(sendbuf == MPI_IN_PLACE) {
1912       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1913       sendcount=recvcount;
1914       sendtype=recvtype;
1915     }
1916 #ifdef HAVE_TRACING
1917   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1918   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1919   extra->type = TRACING_ALLGATHER;
1920   int known=0;
1921   extra->datatype1 = encode_datatype(sendtype, &known);
1922   int dt_size_send = 1;
1923   if(!known)
1924     dt_size_send = smpi_datatype_size(sendtype);
1925   extra->send_size = sendcount*dt_size_send;
1926   extra->datatype2 = encode_datatype(recvtype, &known);
1927   int dt_size_recv = 1;
1928   if(!known)
1929     dt_size_recv = smpi_datatype_size(recvtype);
1930   extra->recv_size = recvcount*dt_size_recv;
1931
1932   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1933 #endif
1934     mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1935                            recvtype, comm);
1936     retval = MPI_SUCCESS;
1937
1938 #ifdef HAVE_TRACING
1939   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1940 #endif
1941   }
1942   smpi_bench_begin();
1943   return retval;
1944 }
1945
1946 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1947                    void *recvbuf, int *recvcounts, int *displs,
1948                    MPI_Datatype recvtype, MPI_Comm comm)
1949 {
1950   int retval = 0;
1951
1952   smpi_bench_end();
1953
1954   if (comm == MPI_COMM_NULL) {
1955     retval = MPI_ERR_COMM;
1956   } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1957             (recvtype == MPI_DATATYPE_NULL)){
1958     retval = MPI_ERR_TYPE;
1959   } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1960     retval = MPI_ERR_COUNT;
1961   } else if (recvcounts == NULL || displs == NULL) {
1962     retval = MPI_ERR_ARG;
1963   } else {
1964
1965     if(sendbuf == MPI_IN_PLACE) {
1966       sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1967       sendcount=recvcounts[smpi_comm_rank(comm)];
1968       sendtype=recvtype;
1969     }
1970 #ifdef HAVE_TRACING
1971   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1972   int i=0;
1973   int size = smpi_comm_size(comm);
1974   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1975   extra->type = TRACING_ALLGATHERV;
1976   extra->num_processes = size;
1977   int known=0;
1978   extra->datatype1 = encode_datatype(sendtype, &known);
1979   int dt_size_send = 1;
1980   if(!known)
1981     dt_size_send = smpi_datatype_size(sendtype);
1982   extra->send_size = sendcount*dt_size_send;
1983   extra->datatype2 = encode_datatype(recvtype, &known);
1984   int dt_size_recv = 1;
1985   if(!known)
1986     dt_size_recv = smpi_datatype_size(recvtype);
1987   extra->recvcounts= xbt_malloc(size*sizeof(int));
1988   for(i=0; i< size; i++)//copy data to avoid bad free
1989     extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1990
1991   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1992 #endif
1993     mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1994                         displs, recvtype, comm);
1995     retval = MPI_SUCCESS;
1996 #ifdef HAVE_TRACING
1997   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1998 #endif
1999   }
2000
2001   smpi_bench_begin();
2002   return retval;
2003 }
2004
2005 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2006                 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2007                 int root, MPI_Comm comm)
2008 {
2009   int retval = 0;
2010
2011   smpi_bench_end();
2012
2013   if (comm == MPI_COMM_NULL) {
2014     retval = MPI_ERR_COMM;
2015   } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
2016              || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
2017     retval = MPI_ERR_TYPE;
2018   } else if ((sendbuf == recvbuf) ||
2019       ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
2020     retval = MPI_ERR_BUFFER;
2021   }else {
2022
2023     if (recvbuf == MPI_IN_PLACE) {
2024         recvtype=sendtype;
2025         recvcount=sendcount;
2026     }
2027 #ifdef HAVE_TRACING
2028   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2029   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2030   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2031   extra->type = TRACING_SCATTER;
2032   extra->root = root_traced;
2033   int known=0;
2034   extra->datatype1 = encode_datatype(sendtype, &known);
2035   int dt_size_send = 1;
2036   if((smpi_comm_rank(comm)==root) && !known)
2037     dt_size_send = smpi_datatype_size(sendtype);
2038   extra->send_size = sendcount*dt_size_send;
2039   extra->datatype2 = encode_datatype(recvtype, &known);
2040   int dt_size_recv = 1;
2041   if(!known)
2042     dt_size_recv = smpi_datatype_size(recvtype);
2043   extra->recv_size = recvcount*dt_size_recv;
2044   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2045 #endif
2046     mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
2047                      recvtype, root, comm);
2048     retval = MPI_SUCCESS;
2049 #ifdef HAVE_TRACING
2050   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2051 #endif
2052   }
2053
2054   smpi_bench_begin();
2055   return retval;
2056 }
2057
2058 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
2059                  MPI_Datatype sendtype, void *recvbuf, int recvcount,
2060                  MPI_Datatype recvtype, int root, MPI_Comm comm)
2061 {
2062   int retval = 0;
2063
2064   smpi_bench_end();
2065
2066   if (comm == MPI_COMM_NULL) {
2067     retval = MPI_ERR_COMM;
2068   } else if (sendcounts == NULL || displs == NULL) {
2069     retval = MPI_ERR_ARG;
2070   } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2071              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2072     retval = MPI_ERR_TYPE;
2073   } else {
2074     if (recvbuf == MPI_IN_PLACE) {
2075         recvtype=sendtype;
2076         recvcount=sendcounts[smpi_comm_rank(comm)];
2077     }
2078 #ifdef HAVE_TRACING
2079   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2080   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2081   int i=0;
2082   int size = smpi_comm_size(comm);
2083   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2084   extra->type = TRACING_SCATTERV;
2085   extra->num_processes = size;
2086   extra->root = root_traced;
2087   int known=0;
2088   extra->datatype1 = encode_datatype(sendtype, &known);
2089   int dt_size_send = 1;
2090   if(!known)
2091     dt_size_send = smpi_datatype_size(sendtype);
2092   extra->sendcounts= xbt_malloc(size*sizeof(int));
2093   for(i=0; i< size; i++)//copy data to avoid bad free
2094     extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2095   extra->datatype2 = encode_datatype(recvtype, &known);
2096   int dt_size_recv = 1;
2097   if(!known)
2098     dt_size_recv = smpi_datatype_size(recvtype);
2099   extra->recv_size = recvcount*dt_size_recv;
2100   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2101
2102 #endif
2103     smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2104                       recvcount, recvtype, root, comm);
2105     retval = MPI_SUCCESS;
2106 #ifdef HAVE_TRACING
2107   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2108 #endif
2109   }
2110
2111   smpi_bench_begin();
2112   return retval;
2113 }
2114
2115 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2116                MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2117 {
2118   int retval = 0;
2119
2120   smpi_bench_end();
2121
2122   if (comm == MPI_COMM_NULL) {
2123     retval = MPI_ERR_COMM;
2124   } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2125     retval = MPI_ERR_ARG;
2126   } else {
2127 #ifdef HAVE_TRACING
2128   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2129   int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2130   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2131   extra->type = TRACING_REDUCE;
2132   int known=0;
2133   extra->datatype1 = encode_datatype(datatype, &known);
2134   int dt_size_send = 1;
2135   if(!known)
2136     dt_size_send = smpi_datatype_size(datatype);
2137   extra->send_size = count*dt_size_send;
2138   extra->root = root_traced;
2139
2140   TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2141 #endif
2142     mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2143
2144     retval = MPI_SUCCESS;
2145 #ifdef HAVE_TRACING
2146   TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2147 #endif
2148   }
2149
2150   smpi_bench_begin();
2151   return retval;
2152 }
2153
2154 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2155     MPI_Datatype datatype, MPI_Op op){
2156   int retval = 0;
2157
2158     smpi_bench_end();
2159     if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2160       retval = MPI_ERR_ARG;
2161     } else {
2162       smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2163       retval=MPI_SUCCESS;
2164     }
2165     smpi_bench_begin();
2166     return retval;
2167 }
2168
2169 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2170                   MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2171 {
2172   int retval = 0;
2173
2174   smpi_bench_end();
2175
2176   if (comm == MPI_COMM_NULL) {
2177     retval = MPI_ERR_COMM;
2178   } else if (!is_datatype_valid(datatype)) {
2179     retval = MPI_ERR_TYPE;
2180   } else if (op == MPI_OP_NULL) {
2181     retval = MPI_ERR_OP;
2182   } else {
2183
2184     char* sendtmpbuf = (char*) sendbuf;
2185     if( sendbuf == MPI_IN_PLACE ) {
2186       sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2187       smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2188     }
2189 #ifdef HAVE_TRACING
2190   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2191   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2192   extra->type = TRACING_ALLREDUCE;
2193   int known=0;
2194   extra->datatype1 = encode_datatype(datatype, &known);
2195   int dt_size_send = 1;
2196   if(!known)
2197     dt_size_send = smpi_datatype_size(datatype);
2198   extra->send_size = count*dt_size_send;
2199
2200   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2201 #endif
2202     mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2203
2204     if( sendbuf == MPI_IN_PLACE ) {
2205       xbt_free(sendtmpbuf);
2206     }
2207
2208     retval = MPI_SUCCESS;
2209 #ifdef HAVE_TRACING
2210   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2211 #endif
2212   }
2213
2214   smpi_bench_begin();
2215   return retval;
2216 }
2217
2218 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2219              MPI_Datatype datatype, MPI_Op op, 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 (!is_datatype_valid(datatype)) {
2228     retval = MPI_ERR_TYPE;
2229   } else if (op == MPI_OP_NULL) {
2230     retval = MPI_ERR_OP;
2231   } else {
2232 #ifdef HAVE_TRACING
2233   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2234   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2235   extra->type = TRACING_SCAN;
2236   int known=0;
2237   extra->datatype1 = encode_datatype(datatype, &known);
2238   int dt_size_send = 1;
2239   if(!known)
2240     dt_size_send = smpi_datatype_size(datatype);
2241   extra->send_size = count*dt_size_send;
2242
2243   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2244 #endif
2245     smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2246     retval = MPI_SUCCESS;
2247 #ifdef HAVE_TRACING
2248   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2249 #endif
2250   }
2251
2252   smpi_bench_begin();
2253   return retval;
2254 }
2255
2256 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2257                 MPI_Op op, MPI_Comm comm){
2258   int retval = 0;
2259
2260   smpi_bench_end();
2261
2262   if (comm == MPI_COMM_NULL) {
2263     retval = MPI_ERR_COMM;
2264   } else if (!is_datatype_valid(datatype)) {
2265     retval = MPI_ERR_TYPE;
2266   } else if (op == MPI_OP_NULL) {
2267     retval = MPI_ERR_OP;
2268   } else {
2269 #ifdef HAVE_TRACING
2270   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2271   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2272   extra->type = TRACING_EXSCAN;
2273   int known=0;
2274   extra->datatype1 = encode_datatype(datatype, &known);
2275   int dt_size_send = 1;
2276   if(!known)
2277     dt_size_send = smpi_datatype_size(datatype);
2278   extra->send_size = count*dt_size_send;
2279   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2280 #endif
2281     smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2282     retval = MPI_SUCCESS;
2283 #ifdef HAVE_TRACING
2284   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2285 #endif
2286   }
2287
2288   smpi_bench_begin();
2289   return retval;
2290 }
2291
2292 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2293                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2294 {
2295   int retval = 0;
2296   smpi_bench_end();
2297
2298   if (comm == MPI_COMM_NULL) {
2299     retval = MPI_ERR_COMM;
2300   } else if (!is_datatype_valid(datatype)) {
2301     retval = MPI_ERR_TYPE;
2302   } else if (op == MPI_OP_NULL) {
2303     retval = MPI_ERR_OP;
2304   } else if (recvcounts == NULL) {
2305     retval = MPI_ERR_ARG;
2306   } else {
2307 #ifdef HAVE_TRACING
2308   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2309   int i=0;
2310   int size = smpi_comm_size(comm);
2311   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2312   extra->type = TRACING_REDUCE_SCATTER;
2313   extra->num_processes = size;
2314   int known=0;
2315   extra->datatype1 = encode_datatype(datatype, &known);
2316   int dt_size_send = 1;
2317   if(!known)
2318     dt_size_send = smpi_datatype_size(datatype);
2319   extra->send_size = 0;
2320   extra->recvcounts= xbt_malloc(size*sizeof(int));
2321   for(i=0; i< size; i++)//copy data to avoid bad free
2322     extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2323   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2324 #endif
2325     void* sendtmpbuf=sendbuf;
2326     if(sendbuf==MPI_IN_PLACE){
2327       sendtmpbuf=recvbuf;
2328     }
2329
2330     mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2331                        datatype,  op, comm);
2332     retval = MPI_SUCCESS;
2333 #ifdef HAVE_TRACING
2334   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2335 #endif
2336   }
2337
2338   smpi_bench_begin();
2339   return retval;
2340 }
2341
2342 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2343                        MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2344 {
2345   int retval,i;
2346   smpi_bench_end();
2347
2348   if (comm == MPI_COMM_NULL) {
2349     retval = MPI_ERR_COMM;
2350   } else if (!is_datatype_valid(datatype)) {
2351     retval = MPI_ERR_TYPE;
2352   } else if (op == MPI_OP_NULL) {
2353     retval = MPI_ERR_OP;
2354   } else if (recvcount < 0) {
2355     retval = MPI_ERR_ARG;
2356   } else {
2357     int count=smpi_comm_size(comm);
2358
2359 #ifdef HAVE_TRACING
2360   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2361   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2362   extra->type = TRACING_REDUCE_SCATTER;
2363   extra->num_processes = count;
2364   int known=0;
2365   extra->datatype1 = encode_datatype(datatype, &known);
2366   int dt_size_send = 1;
2367   if(!known)
2368     dt_size_send = smpi_datatype_size(datatype);
2369   extra->send_size = 0;
2370   extra->recvcounts= xbt_malloc(count*sizeof(int));
2371   for(i=0; i< count; i++)//copy data to avoid bad free
2372     extra->recvcounts[i] = recvcount*dt_size_send;
2373
2374   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2375 #endif
2376     int* recvcounts=(int*)xbt_malloc(count);
2377     for (i=0; i<count;i++)recvcounts[i]=recvcount;
2378     mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2379                        datatype,  op, comm);
2380     xbt_free(recvcounts);
2381     retval = MPI_SUCCESS;
2382 #ifdef HAVE_TRACING
2383   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2384 #endif
2385   }
2386
2387   smpi_bench_begin();
2388   return retval;
2389 }
2390
2391 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2392                  void *recvbuf, int recvcount, MPI_Datatype recvtype,
2393                  MPI_Comm comm)
2394 {
2395   int retval = 0;
2396
2397   smpi_bench_end();
2398
2399   if (comm == MPI_COMM_NULL) {
2400     retval = MPI_ERR_COMM;
2401   } else if (sendtype == MPI_DATATYPE_NULL
2402              || recvtype == MPI_DATATYPE_NULL) {
2403     retval = MPI_ERR_TYPE;
2404   } else {
2405 #ifdef HAVE_TRACING
2406   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2407   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2408   extra->type = TRACING_ALLTOALL;
2409   int known=0;
2410   extra->datatype1 = encode_datatype(sendtype, &known);
2411   if(!known)
2412     extra->send_size = sendcount*smpi_datatype_size(sendtype);
2413   else
2414     extra->send_size = sendcount;
2415   extra->datatype2 = encode_datatype(recvtype, &known);
2416   if(!known)
2417     extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2418   else
2419     extra->recv_size = recvcount;
2420   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2421 #endif
2422     retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2423 #ifdef HAVE_TRACING
2424   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2425 #endif
2426   }
2427
2428   smpi_bench_begin();
2429   return retval;
2430 }
2431
2432 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2433                   MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2434                   int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2435 {
2436   int retval = 0;
2437
2438   smpi_bench_end();
2439
2440   if (comm == MPI_COMM_NULL) {
2441     retval = MPI_ERR_COMM;
2442   } else if (sendtype == MPI_DATATYPE_NULL
2443              || recvtype == MPI_DATATYPE_NULL) {
2444     retval = MPI_ERR_TYPE;
2445   } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2446              || recvdisps == NULL) {
2447     retval = MPI_ERR_ARG;
2448   } else {
2449 #ifdef HAVE_TRACING
2450   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2451   int i=0;
2452   int size = smpi_comm_size(comm);
2453   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2454   extra->type = TRACING_ALLTOALLV;
2455   extra->send_size = 0;
2456   extra->recv_size = 0;
2457   extra->recvcounts= xbt_malloc(size*sizeof(int));
2458   extra->sendcounts= xbt_malloc(size*sizeof(int));
2459   int known=0;
2460   extra->datatype1 = encode_datatype(sendtype, &known);
2461   int dt_size_send = 1;
2462   if(!known)
2463     dt_size_send = smpi_datatype_size(sendtype);
2464   int dt_size_recv = 1;
2465   extra->datatype2 = encode_datatype(recvtype, &known);
2466   if(!known)
2467     dt_size_recv = smpi_datatype_size(recvtype);
2468   for(i=0; i< size; i++){//copy data to avoid bad free
2469     extra->send_size += sendcounts[i]*dt_size_send;
2470     extra->recv_size += recvcounts[i]*dt_size_recv;
2471
2472     extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2473     extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2474   }
2475   extra->num_processes = size;
2476   TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2477 #endif
2478     retval =
2479         mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2480                                   recvbuf, recvcounts, recvdisps, recvtype,
2481                                   comm);
2482 #ifdef HAVE_TRACING
2483   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2484 #endif
2485   }
2486
2487   smpi_bench_begin();
2488   return retval;
2489 }
2490
2491
2492 int PMPI_Get_processor_name(char *name, int *resultlen)
2493 {
2494   int retval = MPI_SUCCESS;
2495
2496   strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2497           strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2498           strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2499           MPI_MAX_PROCESSOR_NAME - 1 );
2500   *resultlen =
2501       strlen(name) >
2502       MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2503
2504   return retval;
2505 }
2506
2507 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2508 {
2509   int retval = MPI_SUCCESS;
2510   size_t size;
2511
2512   if (status == NULL || count == NULL) {
2513     retval = MPI_ERR_ARG;
2514   } else if (!is_datatype_valid(datatype)) {
2515     retval = MPI_ERR_TYPE;
2516   } else {
2517     size = smpi_datatype_size(datatype);
2518     if (size == 0) {
2519       *count = 0;
2520     } else if (status->count % size != 0) {
2521       retval = MPI_UNDEFINED;
2522     } else {
2523       *count = smpi_mpi_get_count(status, datatype);
2524     }
2525   }
2526   return retval;
2527 }
2528
2529 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2530   int retval = 0;
2531
2532   if (old_type == MPI_DATATYPE_NULL) {
2533     retval = MPI_ERR_TYPE;
2534   } else if (count<0){
2535     retval = MPI_ERR_COUNT;
2536   } else {
2537     retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2538   }
2539   return retval;
2540 }
2541
2542 int PMPI_Type_commit(MPI_Datatype* datatype) {
2543   int retval = 0;
2544
2545   if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2546     retval = MPI_ERR_TYPE;
2547   } else {
2548     smpi_datatype_commit(datatype);
2549     retval = MPI_SUCCESS;
2550   }
2551   return retval;
2552 }
2553
2554
2555 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2556   int retval = 0;
2557
2558   if (old_type == MPI_DATATYPE_NULL) {
2559     retval = MPI_ERR_TYPE;
2560   } else if (count<0 || blocklen<0){
2561     retval = MPI_ERR_COUNT;
2562   } else {
2563     retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2564   }
2565   return retval;
2566 }
2567
2568 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2569   int retval = 0;
2570
2571   if (old_type == MPI_DATATYPE_NULL) {
2572     retval = MPI_ERR_TYPE;
2573   } else if (count<0 || blocklen<0){
2574     retval = MPI_ERR_COUNT;
2575   } else {
2576     retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2577   }
2578   return retval;
2579 }
2580
2581 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2582   return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2583 }
2584
2585 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2586   int retval = 0;
2587
2588   if (old_type == MPI_DATATYPE_NULL) {
2589     retval = MPI_ERR_TYPE;
2590   } else if (count<0){
2591     retval = MPI_ERR_COUNT;
2592   } else {
2593     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2594   }
2595   return retval;
2596 }
2597
2598 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2599   int retval = 0;
2600
2601   if (old_type == MPI_DATATYPE_NULL) {
2602     retval = MPI_ERR_TYPE;
2603   } else if (count<0){
2604     retval = MPI_ERR_COUNT;
2605   } else {
2606     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2607   }
2608   return retval;
2609 }
2610
2611 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2612   int retval,i;
2613
2614   if (old_type == MPI_DATATYPE_NULL) {
2615     retval = MPI_ERR_TYPE;
2616   } else if (count<0){
2617     retval = MPI_ERR_COUNT;
2618   } else {
2619     int* blocklens=(int*)xbt_malloc(blocklength*count);
2620     for (i=0; i<count;i++)blocklens[i]=blocklength;
2621     retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2622     xbt_free(blocklens);
2623   }
2624   return retval;
2625 }
2626
2627
2628 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2629   int retval = 0;
2630
2631   if (old_type == MPI_DATATYPE_NULL) {
2632     retval = MPI_ERR_TYPE;
2633   } else if (count<0){
2634     retval = MPI_ERR_COUNT;
2635   } else {
2636     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2637   }
2638   return retval;
2639 }
2640
2641 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2642   return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2643 }
2644
2645 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2646   int retval,i;
2647
2648   if (old_type == MPI_DATATYPE_NULL) {
2649     retval = MPI_ERR_TYPE;
2650   } else if (count<0){
2651     retval = MPI_ERR_COUNT;
2652   } else {
2653     int* blocklens=(int*)xbt_malloc(blocklength*count);
2654     for (i=0; i<count;i++)blocklens[i]=blocklength;
2655     retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2656     xbt_free(blocklens);
2657   }
2658   return retval;
2659 }
2660
2661
2662 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2663   int retval = 0;
2664
2665   if (count<0){
2666     retval = MPI_ERR_COUNT;
2667   } else {
2668     retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2669   }
2670   return retval;
2671 }
2672
2673 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2674   return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2675 }
2676
2677
2678 int PMPI_Error_class(int errorcode, int* errorclass) {
2679   // assume smpi uses only standard mpi error codes
2680   *errorclass=errorcode;
2681   return MPI_SUCCESS;
2682 }
2683
2684
2685 int PMPI_Initialized(int* flag) {
2686    *flag=smpi_process_initialized();
2687    return MPI_SUCCESS;
2688 }
2689
2690 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2691  * will be implemented, not only should we check if the topology is NULL, but
2692  * we should check if it is the good topology type (so we have to add a
2693  *  MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2694
2695 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2696   int retval = 0;
2697   if (comm_old == MPI_COMM_NULL){
2698     retval =  MPI_ERR_COMM;
2699   } else if (ndims < 0 ||
2700            (ndims > 0 && (dims == NULL ||
2701                           periodic == NULL)) ||
2702            comm_cart == NULL) {
2703     retval = MPI_ERR_ARG;
2704   } else{
2705     retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2706   }
2707   return retval;
2708 }
2709
2710 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2711   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2712     return MPI_ERR_TOPOLOGY;
2713   }
2714   if (coords == NULL) {
2715     return MPI_ERR_ARG;
2716   }
2717   return smpi_mpi_cart_rank(comm, coords, rank);
2718 }
2719
2720 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2721   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2722     return MPI_ERR_TOPOLOGY;
2723   }
2724   if (source == NULL || dest == NULL || direction < 0 ) {
2725     return MPI_ERR_ARG;
2726   }
2727   return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2728 }
2729
2730 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2731   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2732     return MPI_ERR_TOPOLOGY;
2733   }
2734   if (rank < 0 || rank >= smpi_comm_size(comm)) {
2735     return MPI_ERR_RANK;
2736   }
2737   if (maxdims <= 0) {
2738     return MPI_ERR_ARG;
2739   }
2740   if(coords == NULL) {
2741     return MPI_ERR_ARG;
2742   }
2743   return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2744 }
2745
2746 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2747   if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2748     return MPI_ERR_TOPOLOGY;
2749   }
2750   if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2751     return MPI_ERR_ARG;
2752   }
2753   return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2754 }
2755
2756 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2757   if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2758     return MPI_ERR_TOPOLOGY;
2759   }
2760   if (ndims == NULL) {
2761     return MPI_ERR_ARG;
2762   }
2763   return smpi_mpi_cartdim_get(comm, ndims);
2764 }
2765
2766 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2767   if(dims == NULL) {
2768     return MPI_ERR_ARG;
2769   }
2770   if (ndims < 1 || nnodes < 1) {
2771     return MPI_ERR_DIMS;
2772   }
2773
2774   return smpi_mpi_dims_create(nnodes, ndims, dims);
2775 }
2776
2777 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2778   if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2779     return MPI_ERR_TOPOLOGY;
2780   }
2781   if (comm_new == NULL) {
2782     return MPI_ERR_ARG;
2783   }
2784   return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2785 }
2786
2787 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2788     if(oldtype == MPI_DATATYPE_NULL) {
2789         return MPI_ERR_TYPE;
2790     }
2791     int blocks[3] = { 1, 1, 1 };
2792     MPI_Aint disps[3] = { lb, 0, lb+extent };
2793     MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2794
2795     s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks,
2796                                                                 disps,
2797                                                                 3,
2798                                                                 types
2799                                                                 );
2800     smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2801
2802     (*newtype)->flags &= ~DT_FLAG_COMMITED;
2803     return MPI_SUCCESS;
2804 }
2805
2806
2807
2808 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2809   int retval = 0;
2810   smpi_bench_end();
2811   if (comm == MPI_COMM_NULL) {
2812     retval= MPI_ERR_COMM;
2813   }else if ((base == NULL && size != 0)
2814             || disp_unit <= 0 || size < 0 ){
2815     retval= MPI_ERR_OTHER;
2816   }else{
2817     *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2818     retval = MPI_SUCCESS;
2819   }
2820   smpi_bench_begin();
2821   return retval;
2822 }
2823
2824 int PMPI_Win_free( MPI_Win* win){
2825   int retval = 0;
2826   smpi_bench_end();
2827   if (win == NULL || *win == MPI_WIN_NULL) {
2828     retval = MPI_ERR_WIN;
2829   }else{
2830     retval=smpi_mpi_win_free(win);
2831   }
2832   smpi_bench_begin();
2833   return retval;
2834 }
2835
2836 int PMPI_Win_set_name(MPI_Win  win, char * name)
2837 {
2838   int retval = 0;
2839   if (win == MPI_WIN_NULL)  {
2840     retval = MPI_ERR_TYPE;
2841   } else if (name == NULL)  {
2842     retval = MPI_ERR_ARG;
2843   } else {
2844     smpi_mpi_win_set_name(win, name);
2845     retval = MPI_SUCCESS;
2846   }
2847   return retval;
2848 }
2849
2850 int PMPI_Win_get_name(MPI_Win  win, char * name, int* len)
2851 {
2852   int retval = MPI_SUCCESS;
2853
2854   if (win == MPI_WIN_NULL)  {
2855     retval = MPI_ERR_WIN;
2856   } else if (name == NULL)  {
2857     retval = MPI_ERR_ARG;
2858   } else {
2859     smpi_mpi_win_get_name(win, name, len);
2860   }
2861   return retval;
2862 }
2863
2864 int PMPI_Win_get_group(MPI_Win  win, MPI_Group * group){
2865   int retval = MPI_SUCCESS;
2866   if (win == MPI_WIN_NULL)  {
2867     retval = MPI_ERR_WIN;
2868   }else {
2869     smpi_mpi_win_get_group(win, group);
2870   }
2871   return retval;
2872 }
2873
2874
2875 int PMPI_Win_fence( int assert,  MPI_Win win){
2876   int retval = 0;
2877   smpi_bench_end();
2878   if (win == MPI_WIN_NULL) {
2879     retval = MPI_ERR_WIN;
2880   } else {
2881 #ifdef HAVE_TRACING
2882   int rank = smpi_process_index();
2883   TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2884 #endif
2885   retval = smpi_mpi_win_fence(assert, win);
2886 #ifdef HAVE_TRACING
2887   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2888 #endif
2889
2890   }
2891   smpi_bench_begin();
2892   return retval;
2893 }
2894
2895 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2896               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2897   int retval = 0;
2898   smpi_bench_end();
2899   if (win == MPI_WIN_NULL) {
2900     retval = MPI_ERR_WIN;
2901   } else if (target_rank == MPI_PROC_NULL) {
2902     retval = MPI_SUCCESS;
2903   } else if (target_rank <0){
2904     retval = MPI_ERR_RANK;
2905   } else if (target_disp <0){
2906       retval = MPI_ERR_ARG;
2907   } else if (origin_count < 0 || target_count < 0) {
2908     retval = MPI_ERR_COUNT;
2909   } else if (origin_addr==NULL && origin_count > 0){
2910     retval = MPI_ERR_COUNT;
2911   } else if ((!is_datatype_valid(origin_datatype)) ||
2912             (!is_datatype_valid(target_datatype))) {
2913     retval = MPI_ERR_TYPE;
2914   } else {
2915 #ifdef HAVE_TRACING
2916     int rank = smpi_process_index();
2917     MPI_Group group;
2918     smpi_mpi_win_get_group(win, &group);
2919     int src_traced = smpi_group_index(group, target_rank);
2920     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2921 #endif
2922
2923     retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2924
2925 #ifdef HAVE_TRACING
2926     TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2927 #endif
2928   }
2929   smpi_bench_begin();
2930   return retval;
2931 }
2932
2933 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2934               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2935   int retval = 0;
2936   smpi_bench_end();
2937   if (win == MPI_WIN_NULL) {
2938     retval = MPI_ERR_WIN;
2939   } else if (target_rank == MPI_PROC_NULL) {
2940     retval = MPI_SUCCESS;
2941   } else if (target_rank <0){
2942     retval = MPI_ERR_RANK;
2943   } else if (target_disp <0){
2944     retval = MPI_ERR_ARG;
2945   } else if (origin_count < 0 || target_count < 0) {
2946     retval = MPI_ERR_COUNT;
2947   } else if (origin_addr==NULL && origin_count > 0){
2948     retval = MPI_ERR_COUNT;
2949   } else if ((!is_datatype_valid(origin_datatype)) ||
2950             (!is_datatype_valid(target_datatype))) {
2951     retval = MPI_ERR_TYPE;
2952   } else {
2953 #ifdef HAVE_TRACING
2954     int rank = smpi_process_index();
2955     MPI_Group group;
2956     smpi_mpi_win_get_group(win, &group);
2957     int dst_traced = smpi_group_index(group, target_rank);
2958     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, NULL);
2959     TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2960 #endif
2961
2962     retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2963
2964 #ifdef HAVE_TRACING
2965     TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2966 #endif
2967
2968   }
2969   smpi_bench_begin();
2970   return retval;
2971 }
2972
2973
2974 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2975               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2976   int retval = 0;
2977   smpi_bench_end();
2978   if (win == MPI_WIN_NULL) {
2979     retval = MPI_ERR_WIN;
2980   } else if (target_rank == MPI_PROC_NULL) {
2981     retval = MPI_SUCCESS;
2982   } else if (target_rank <0){
2983     retval = MPI_ERR_RANK;
2984   } else if (target_disp <0){
2985     retval = MPI_ERR_ARG;
2986   } else if (origin_count < 0 || target_count < 0) {
2987     retval = MPI_ERR_COUNT;
2988   } else if (origin_addr==NULL && origin_count > 0){
2989     retval = MPI_ERR_COUNT;
2990   } else if ((!is_datatype_valid(origin_datatype)) ||
2991             (!is_datatype_valid(target_datatype))) {
2992     retval = MPI_ERR_TYPE;
2993   } else if (op == MPI_OP_NULL) {
2994     retval = MPI_ERR_OP;
2995   } else {
2996 #ifdef HAVE_TRACING
2997     int rank = smpi_process_index();
2998     MPI_Group group;
2999     smpi_mpi_win_get_group(win, &group);
3000     int src_traced = smpi_group_index(group, target_rank);
3001     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
3002 #endif
3003
3004     retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, op, win);
3005
3006 #ifdef HAVE_TRACING
3007     TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
3008 #endif
3009
3010   }
3011   smpi_bench_begin();
3012   return retval;
3013 }
3014
3015
3016 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
3017   int retval = 0;
3018   smpi_bench_end();
3019   if (win == MPI_WIN_NULL) {
3020     retval = MPI_ERR_WIN;
3021   } else if (group==MPI_GROUP_NULL){
3022     retval = MPI_ERR_GROUP;
3023   }
3024   else {
3025 #ifdef HAVE_TRACING
3026     int rank = smpi_process_index();
3027     TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
3028 #endif
3029     retval = smpi_mpi_win_post(group,assert,win);
3030 #ifdef HAVE_TRACING
3031     TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
3032 #endif
3033   }
3034   smpi_bench_begin();
3035   return retval;
3036 }
3037
3038 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
3039   int retval = 0;
3040   smpi_bench_end();
3041   if (win == MPI_WIN_NULL) {
3042     retval = MPI_ERR_WIN;
3043   } else if (group==MPI_GROUP_NULL){
3044     retval = MPI_ERR_GROUP;
3045   }
3046   else {
3047 #ifdef HAVE_TRACING
3048     int rank = smpi_process_index();
3049     TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
3050 #endif
3051     retval = smpi_mpi_win_start(group,assert,win);
3052 #ifdef HAVE_TRACING
3053     TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
3054 #endif
3055   }
3056   smpi_bench_begin();
3057   return retval;
3058 }
3059
3060
3061 int PMPI_Win_complete(MPI_Win win){
3062   int retval = 0;
3063   smpi_bench_end();
3064   if (win == MPI_WIN_NULL) {
3065     retval = MPI_ERR_WIN;
3066   }
3067   else {
3068 #ifdef HAVE_TRACING
3069     int rank = smpi_process_index();
3070     TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
3071 #endif
3072     retval = smpi_mpi_win_complete(win);
3073 #ifdef HAVE_TRACING
3074     TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
3075 #endif
3076   }
3077   smpi_bench_begin();
3078   return retval;
3079 }
3080
3081 int PMPI_Win_wait(MPI_Win win){
3082   int retval = 0;
3083   smpi_bench_end();
3084   if (win == MPI_WIN_NULL) {
3085     retval = MPI_ERR_WIN;
3086   }
3087   else {
3088 #ifdef HAVE_TRACING
3089     int rank = smpi_process_index();
3090     TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
3091 #endif
3092     retval = smpi_mpi_win_wait(win);
3093 #ifdef HAVE_TRACING
3094     TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
3095 #endif
3096   }
3097   smpi_bench_begin();
3098   return retval;
3099 }
3100
3101 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
3102   void *ptr = xbt_malloc(size);
3103   if(!ptr)
3104     return MPI_ERR_NO_MEM;
3105   else {
3106     *(void **)baseptr = ptr;
3107     return MPI_SUCCESS;
3108   }
3109 }
3110
3111 int PMPI_Free_mem(void *baseptr){
3112   xbt_free(baseptr);
3113   return MPI_SUCCESS;
3114 }
3115
3116 int PMPI_Type_set_name(MPI_Datatype  datatype, char * name)
3117 {
3118   int retval = 0;
3119   if (datatype == MPI_DATATYPE_NULL)  {
3120     retval = MPI_ERR_TYPE;
3121   } else if (name == NULL)  {
3122     retval = MPI_ERR_ARG;
3123   } else {
3124     smpi_datatype_set_name(datatype, name);
3125     retval = MPI_SUCCESS;
3126   }
3127   return retval;
3128 }
3129
3130 int PMPI_Type_get_name(MPI_Datatype  datatype, char * name, int* len)
3131 {
3132   int retval = 0;
3133
3134   if (datatype == MPI_DATATYPE_NULL)  {
3135     retval = MPI_ERR_TYPE;
3136   } else if (name == NULL)  {
3137     retval = MPI_ERR_ARG;
3138   } else {
3139     smpi_datatype_get_name(datatype, name, len);
3140     retval = MPI_SUCCESS;
3141   }
3142   return retval;
3143 }
3144
3145
3146 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
3147   return smpi_type_f2c(datatype);
3148 }
3149
3150 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
3151   return smpi_type_c2f( datatype);
3152 }
3153
3154 MPI_Group PMPI_Group_f2c(MPI_Fint group){
3155   return smpi_group_f2c( group);
3156 }
3157
3158 MPI_Fint PMPI_Group_c2f(MPI_Group group){
3159   return smpi_group_c2f(group);
3160 }
3161
3162 MPI_Request PMPI_Request_f2c(MPI_Fint request){
3163   return smpi_request_f2c(request);
3164 }
3165
3166 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
3167   return smpi_request_c2f(request);
3168 }
3169
3170 MPI_Win PMPI_Win_f2c(MPI_Fint win){
3171   return smpi_win_f2c(win);
3172 }
3173
3174 MPI_Fint PMPI_Win_c2f(MPI_Win win){
3175   return smpi_win_c2f(win);
3176 }
3177
3178 MPI_Op PMPI_Op_f2c(MPI_Fint op){
3179   return smpi_op_f2c(op);
3180 }
3181
3182 MPI_Fint PMPI_Op_c2f(MPI_Op op){
3183   return smpi_op_c2f(op);
3184 }
3185
3186 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
3187   return smpi_comm_f2c(comm);
3188 }
3189
3190 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
3191   return smpi_comm_c2f(comm);
3192 }
3193
3194 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3195   return smpi_info_f2c(info);
3196 }
3197
3198 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3199   return smpi_info_c2f(info);
3200 }
3201
3202 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3203   return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3204 }
3205
3206 int PMPI_Keyval_free(int* keyval) {
3207   return smpi_comm_keyval_free(keyval);
3208 }
3209
3210 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3211   if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3212        ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3213        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3214     return MPI_ERR_ARG;
3215   else if (comm==MPI_COMM_NULL)
3216     return MPI_ERR_COMM;
3217   else
3218     return smpi_comm_attr_delete(comm, keyval);
3219 }
3220
3221 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3222   if (comm==MPI_COMM_NULL){
3223     *flag=0;
3224     return MPI_ERR_COMM;
3225   } else if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3226        ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3227        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE){
3228     *flag=1;
3229     //FIXME : not ideal and leaky, but should not be called too much
3230     int* res = xbt_new(int, 1);
3231     *res=keyval;
3232     *(int**)attr_value=res;
3233     return MPI_SUCCESS;
3234   } else
3235   return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3236 }
3237
3238 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3239   if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3240        ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3241        ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3242     return MPI_ERR_ARG;
3243   else if (comm==MPI_COMM_NULL)
3244     return MPI_ERR_COMM;
3245   else
3246   return smpi_comm_attr_put(comm, keyval, attr_value);
3247 }
3248
3249 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3250 {
3251   return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3252 }
3253
3254 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3255 {
3256   return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3257 }
3258
3259 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3260 {
3261   return PMPI_Attr_delete(comm, comm_keyval);
3262 }
3263
3264 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3265 {
3266   return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3267 }
3268
3269 int PMPI_Comm_free_keyval(int* keyval) {
3270   return PMPI_Keyval_free(keyval);
3271 }
3272
3273
3274 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3275 {
3276   if (type==MPI_DATATYPE_NULL)
3277     return MPI_ERR_TYPE;
3278   else
3279     return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3280 }
3281
3282 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3283 {
3284   if (type==MPI_DATATYPE_NULL)
3285     return MPI_ERR_TYPE;
3286   else
3287     return smpi_type_attr_put(type, type_keyval, attribute_val);
3288 }
3289
3290 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3291 {
3292   if (type==MPI_DATATYPE_NULL)
3293     return MPI_ERR_TYPE;
3294   else
3295     return smpi_type_attr_delete(type, type_keyval);
3296 }
3297
3298 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3299 {
3300   return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3301 }
3302
3303 int PMPI_Type_free_keyval(int* keyval) {
3304   return smpi_type_keyval_free(keyval);
3305 }
3306
3307 int PMPI_Info_create( MPI_Info *info){
3308   if (info == NULL)
3309     return MPI_ERR_ARG;
3310   *info = xbt_new(s_smpi_mpi_info_t, 1);
3311   (*info)->info_dict= xbt_dict_new_homogeneous(NULL);
3312   (*info)->refcount=1;
3313   return MPI_SUCCESS;
3314 }
3315
3316 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3317   if (info == NULL || key == NULL || value == NULL)
3318     return MPI_ERR_ARG;
3319
3320   xbt_dict_set(info->info_dict, key, (void*)value, NULL);
3321   return MPI_SUCCESS;
3322 }
3323
3324 int PMPI_Info_free( MPI_Info *info){
3325   if (info == NULL || *info==NULL)
3326     return MPI_ERR_ARG;
3327   (*info)->refcount--;
3328   if((*info)->refcount==0){
3329     xbt_dict_free(&((*info)->info_dict));
3330     xbt_free(*info);
3331   }
3332   *info=MPI_INFO_NULL;
3333   return MPI_SUCCESS;
3334 }
3335
3336 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3337   if (info == NULL || key == NULL || valuelen <0)
3338     return MPI_ERR_ARG;
3339   if (value == NULL)
3340     return MPI_ERR_INFO_VALUE;
3341   *flag=FALSE;
3342   char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3343   if(tmpvalue){
3344     memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < valuelen) ?
3345                          strlen(tmpvalue) + 1 : valuelen);
3346     *flag=TRUE;
3347   }
3348   return MPI_SUCCESS;
3349 }
3350
3351 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3352   if (info == NULL || newinfo==NULL)
3353     return MPI_ERR_ARG;
3354   *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3355   (*newinfo)->info_dict= xbt_dict_new_homogeneous(NULL);
3356   xbt_dict_cursor_t cursor = NULL;
3357   int *key;
3358   void* data;
3359   xbt_dict_foreach(info->info_dict,cursor,key,data){
3360     xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
3361   }
3362   return MPI_SUCCESS;
3363 }
3364
3365 int PMPI_Info_delete(MPI_Info info, char *key){
3366   xbt_ex_t e;
3367   if (info == NULL || key==NULL)
3368     return MPI_ERR_ARG;
3369   TRY {
3370   xbt_dict_remove(info->info_dict, key);
3371   }CATCH(e){
3372     xbt_ex_free(e);
3373     return MPI_ERR_INFO_NOKEY;
3374   }
3375   return MPI_SUCCESS;
3376 }
3377
3378 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3379   if (info == NULL || nkeys==NULL)
3380     return MPI_ERR_ARG;
3381   *nkeys=xbt_dict_size(info->info_dict);
3382   return MPI_SUCCESS;
3383 }
3384
3385 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3386   if (info == NULL || key==NULL || n<0 || n> MPI_MAX_INFO_KEY)
3387     return MPI_ERR_ARG;
3388
3389   xbt_dict_cursor_t cursor = NULL;
3390   char *keyn;
3391   void* data;
3392   int num=0;
3393   xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3394     if(num==n){
3395      strcpy(key,keyn);
3396       return MPI_SUCCESS;
3397     }
3398     num++;
3399   }
3400   return MPI_ERR_ARG;
3401 }
3402
3403 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3404   if (info == NULL || key == NULL || valuelen <0)
3405     return MPI_ERR_ARG;
3406   *flag=FALSE;
3407   char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3408   if(tmpvalue){
3409     *valuelen=strlen(tmpvalue);
3410     *flag=TRUE;
3411   }
3412   return MPI_SUCCESS;
3413 }
3414
3415 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3416   if(incount<0 || outcount < 0 || inbuf==NULL || outbuf==NULL)
3417     return MPI_ERR_ARG;
3418   if(!is_datatype_valid(type))
3419     return MPI_ERR_TYPE;
3420   if(comm==MPI_COMM_NULL)
3421     return MPI_ERR_COMM;
3422   return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3423 }
3424
3425 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3426   if(incount<0 || outcount < 0|| inbuf==NULL || outbuf==NULL)
3427     return MPI_ERR_ARG;
3428   if(!is_datatype_valid(type))
3429     return MPI_ERR_TYPE;
3430   if(comm==MPI_COMM_NULL)
3431     return MPI_ERR_COMM;
3432   return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3433 }
3434
3435 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3436   if(incount<0)
3437     return MPI_ERR_ARG;
3438   if(!is_datatype_valid(datatype))
3439     return MPI_ERR_TYPE;
3440   if(comm==MPI_COMM_NULL)
3441     return MPI_ERR_COMM;
3442
3443   *size=incount*smpi_datatype_size(datatype);
3444
3445   return MPI_SUCCESS;
3446 }
3447
3448
3449 /* The following calls are not yet implemented and will fail at runtime. */
3450 /* Once implemented, please move them above this notice. */
3451
3452 #define NOT_YET_IMPLEMENTED {                                           \
3453     XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
3454     return MPI_SUCCESS;                                                 \
3455   }
3456
3457 MPI_Errhandler PMPI_Errhandler_f2c(MPI_Fint errhandler){
3458   NOT_YET_IMPLEMENTED
3459 }
3460
3461 MPI_Fint PMPI_Errhandler_c2f(MPI_Errhandler errhandler){
3462   NOT_YET_IMPLEMENTED
3463 }
3464
3465 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
3466   NOT_YET_IMPLEMENTED
3467 }
3468
3469 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
3470   NOT_YET_IMPLEMENTED
3471 }
3472
3473 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
3474   NOT_YET_IMPLEMENTED
3475 }
3476
3477 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
3478   NOT_YET_IMPLEMENTED
3479 }
3480
3481 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
3482   NOT_YET_IMPLEMENTED
3483 }
3484
3485 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
3486   NOT_YET_IMPLEMENTED
3487 }
3488
3489 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
3490   NOT_YET_IMPLEMENTED
3491 }
3492
3493 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
3494   NOT_YET_IMPLEMENTED
3495 }
3496
3497 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
3498   NOT_YET_IMPLEMENTED
3499 }
3500
3501 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
3502   NOT_YET_IMPLEMENTED
3503 }
3504
3505 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
3506   NOT_YET_IMPLEMENTED
3507 }
3508
3509 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
3510   NOT_YET_IMPLEMENTED
3511 }
3512
3513 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
3514   NOT_YET_IMPLEMENTED
3515 }
3516
3517 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
3518   NOT_YET_IMPLEMENTED
3519 }
3520
3521 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
3522   NOT_YET_IMPLEMENTED
3523 }
3524
3525 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
3526   NOT_YET_IMPLEMENTED
3527 }
3528
3529 int PMPI_Cancel(MPI_Request* request) {
3530   NOT_YET_IMPLEMENTED
3531 }
3532
3533 int PMPI_Buffer_attach(void* buffer, int size) {
3534   NOT_YET_IMPLEMENTED
3535 }
3536
3537 int PMPI_Buffer_detach(void* buffer, int* size) {
3538   NOT_YET_IMPLEMENTED
3539 }
3540
3541 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
3542   NOT_YET_IMPLEMENTED
3543 }
3544
3545 int PMPI_Pcontrol(const int level )
3546 {
3547   NOT_YET_IMPLEMENTED
3548 }
3549
3550
3551 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
3552   NOT_YET_IMPLEMENTED
3553 }
3554
3555 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3556   NOT_YET_IMPLEMENTED
3557 }
3558
3559 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3560   NOT_YET_IMPLEMENTED
3561 }
3562
3563 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3564   NOT_YET_IMPLEMENTED
3565 }
3566
3567 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3568   NOT_YET_IMPLEMENTED
3569 }
3570
3571 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3572   NOT_YET_IMPLEMENTED
3573 }
3574
3575 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3576   NOT_YET_IMPLEMENTED
3577 }
3578
3579 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3580   NOT_YET_IMPLEMENTED
3581 }
3582
3583 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3584   NOT_YET_IMPLEMENTED
3585 }
3586
3587 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3588   NOT_YET_IMPLEMENTED
3589 }
3590
3591 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3592   NOT_YET_IMPLEMENTED
3593 }
3594
3595
3596
3597 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3598   NOT_YET_IMPLEMENTED
3599 }
3600
3601 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
3602   NOT_YET_IMPLEMENTED
3603 }
3604
3605 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
3606   NOT_YET_IMPLEMENTED
3607 }
3608
3609 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3610   NOT_YET_IMPLEMENTED
3611 }
3612
3613
3614
3615 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
3616                             int *num_addresses, int *num_datatypes, int *combiner){
3617   NOT_YET_IMPLEMENTED
3618 }
3619
3620 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
3621                            int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
3622                            MPI_Datatype* array_of_datatypes){
3623   NOT_YET_IMPLEMENTED
3624 }
3625
3626 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
3627                             int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
3628                             int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
3629   NOT_YET_IMPLEMENTED
3630 }
3631
3632 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){
3633   NOT_YET_IMPLEMENTED
3634 }
3635
3636 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3637   NOT_YET_IMPLEMENTED
3638 }
3639
3640 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3641                     void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
3642                     MPI_Comm comm){
3643   NOT_YET_IMPLEMENTED
3644 }
3645
3646 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3647   NOT_YET_IMPLEMENTED
3648 }
3649
3650 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3651   NOT_YET_IMPLEMENTED
3652 }
3653
3654 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3655   NOT_YET_IMPLEMENTED
3656 }
3657
3658 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3659   NOT_YET_IMPLEMENTED
3660 }
3661
3662 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3663   NOT_YET_IMPLEMENTED
3664 }
3665
3666 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3667   NOT_YET_IMPLEMENTED
3668 }
3669
3670 int PMPI_Add_error_class( int *errorclass){
3671   NOT_YET_IMPLEMENTED
3672 }
3673
3674 int PMPI_Add_error_code(  int errorclass, int *errorcode){
3675   NOT_YET_IMPLEMENTED
3676 }
3677
3678 int PMPI_Add_error_string( int errorcode, char *string){
3679   NOT_YET_IMPLEMENTED
3680 }
3681
3682 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3683   NOT_YET_IMPLEMENTED
3684 }
3685
3686 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3687   NOT_YET_IMPLEMENTED
3688 }
3689
3690 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){
3691   NOT_YET_IMPLEMENTED
3692 }
3693
3694 int PMPI_Grequest_complete( MPI_Request request){
3695   NOT_YET_IMPLEMENTED
3696 }
3697
3698 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3699   NOT_YET_IMPLEMENTED
3700 }
3701
3702 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3703   NOT_YET_IMPLEMENTED
3704 }
3705
3706 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3707   NOT_YET_IMPLEMENTED
3708 }
3709
3710 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3711   NOT_YET_IMPLEMENTED
3712 }
3713
3714 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3715   NOT_YET_IMPLEMENTED
3716 }
3717
3718 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3719   NOT_YET_IMPLEMENTED
3720 }
3721
3722 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3723   NOT_YET_IMPLEMENTED
3724 }
3725
3726 int PMPI_Open_port( MPI_Info info, char *port_name){
3727   NOT_YET_IMPLEMENTED
3728 }
3729
3730 int PMPI_Close_port(char *port_name){
3731   NOT_YET_IMPLEMENTED
3732 }
3733
3734 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3735   NOT_YET_IMPLEMENTED
3736 }
3737
3738 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){
3739   NOT_YET_IMPLEMENTED
3740 }
3741
3742 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3743                               int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3744                               MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3745   NOT_YET_IMPLEMENTED
3746 }
3747
3748 int PMPI_Comm_get_parent( MPI_Comm *parent){
3749   NOT_YET_IMPLEMENTED
3750 }
3751
3752 int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win) {
3753   NOT_YET_IMPLEMENTED
3754 }
3755
3756 int PMPI_Win_test(MPI_Win win, int *flag){
3757   NOT_YET_IMPLEMENTED
3758 }
3759
3760 int PMPI_Win_unlock(int rank, MPI_Win win){
3761   NOT_YET_IMPLEMENTED
3762 }
3763