2 /* Copyright (c) 2007-2014. The SimGrid Team.
3 * All rights reserved. */
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. */
9 #include "smpi_mpi_dt_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
12 "Logging specific to SMPI (pmpi)");
15 //this function need to be here because of the calls to smpi_bench
16 void TRACE_smpi_set_category(const char *category)
18 //need to end bench otherwise categories for execution tasks are wrong
20 TRACE_internal_smpi_set_category (category);
21 //begin bench after changing process's category
26 /* PMPI User level calls */
28 int PMPI_Init(int *argc, char ***argv)
30 smpi_process_init(argc, argv);
31 smpi_process_mark_as_initialized();
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__);
45 int PMPI_Finalize(void)
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);
54 smpi_process_finalize();
56 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
57 TRACE_smpi_finalize(smpi_process_index());
59 smpi_process_destroy();
63 int PMPI_Finalized(int* flag)
65 *flag=smpi_process_finalized();
69 int PMPI_Get_version (int *version,int *subversion){
70 *version = MPI_VERSION;
71 *subversion= MPI_SUBVERSION;
75 int PMPI_Get_library_version (char *version,int *len){
76 int retval = MPI_SUCCESS;
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);
85 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
87 if (provided != NULL) {
88 *provided = MPI_THREAD_MULTIPLE;
90 return MPI_Init(argc, argv);
93 int PMPI_Query_thread(int *provided)
97 if (provided == NULL) {
100 *provided = MPI_THREAD_MULTIPLE;
101 retval = MPI_SUCCESS;
106 int PMPI_Is_thread_main(int *flag)
111 retval = MPI_ERR_ARG;
113 *flag = smpi_process_index() == 0;
114 retval = MPI_SUCCESS;
119 int PMPI_Abort(MPI_Comm comm, int errorcode)
122 smpi_process_destroy();
123 // FIXME: should kill all processes in comm instead
124 simcall_process_kill(SIMIX_process_self());
128 double PMPI_Wtime(void)
130 return smpi_mpi_wtime();
133 extern double sg_maxmin_precision;
134 double PMPI_Wtick(void)
136 return sg_maxmin_precision;
139 int PMPI_Address(void *location, MPI_Aint * address)
144 retval = MPI_ERR_ARG;
146 *address = (MPI_Aint) location;
147 retval = MPI_SUCCESS;
152 int PMPI_Get_address(void *location, MPI_Aint * address)
154 return PMPI_Address(location, address);
157 int PMPI_Type_free(MPI_Datatype * datatype)
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;
165 smpi_datatype_free(datatype);
166 retval = MPI_SUCCESS;
171 int PMPI_Type_size(MPI_Datatype datatype, int *size)
175 if (datatype == MPI_DATATYPE_NULL) {
176 retval = MPI_ERR_TYPE;
177 } else if (size == NULL) {
178 retval = MPI_ERR_ARG;
180 *size = (int) smpi_datatype_size(datatype);
181 retval = MPI_SUCCESS;
186 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
190 if (datatype == MPI_DATATYPE_NULL) {
191 retval = MPI_ERR_TYPE;
192 } else if (lb == NULL || extent == NULL) {
193 retval = MPI_ERR_ARG;
195 retval = smpi_datatype_extent(datatype, lb, extent);
200 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
202 return PMPI_Type_get_extent(datatype, lb, extent);
205 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
209 if (datatype == MPI_DATATYPE_NULL) {
210 retval = MPI_ERR_TYPE;
211 } else if (extent == NULL) {
212 retval = MPI_ERR_ARG;
214 *extent = smpi_datatype_get_extent(datatype);
215 retval = MPI_SUCCESS;
220 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
224 if (datatype == MPI_DATATYPE_NULL) {
225 retval = MPI_ERR_TYPE;
226 } else if (disp == NULL) {
227 retval = MPI_ERR_ARG;
229 *disp = smpi_datatype_lb(datatype);
230 retval = MPI_SUCCESS;
235 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
239 if (datatype == MPI_DATATYPE_NULL) {
240 retval = MPI_ERR_TYPE;
241 } else if (disp == NULL) {
242 retval = MPI_ERR_ARG;
244 *disp = smpi_datatype_ub(datatype);
245 retval = MPI_SUCCESS;
250 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
253 if (datatype == MPI_DATATYPE_NULL) {
254 retval = MPI_ERR_TYPE;
256 retval = smpi_datatype_dup(datatype, newtype);
261 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
265 if (function == NULL || op == NULL) {
266 retval = MPI_ERR_ARG;
268 *op = smpi_op_new(function, commute);
269 retval = MPI_SUCCESS;
274 int PMPI_Op_free(MPI_Op * op)
279 retval = MPI_ERR_ARG;
280 } else if (*op == MPI_OP_NULL) {
283 smpi_op_destroy(*op);
285 retval = MPI_SUCCESS;
290 int PMPI_Group_free(MPI_Group * group)
295 retval = MPI_ERR_ARG;
297 smpi_group_destroy(*group);
298 *group = MPI_GROUP_NULL;
299 retval = MPI_SUCCESS;
304 int PMPI_Group_size(MPI_Group group, int *size)
308 if (group == MPI_GROUP_NULL) {
309 retval = MPI_ERR_GROUP;
310 } else if (size == NULL) {
311 retval = MPI_ERR_ARG;
313 *size = smpi_group_size(group);
314 retval = MPI_SUCCESS;
319 int PMPI_Group_rank(MPI_Group group, int *rank)
323 if (group == MPI_GROUP_NULL) {
324 retval = MPI_ERR_GROUP;
325 } else if (rank == NULL) {
326 retval = MPI_ERR_ARG;
328 *rank = smpi_group_rank(group, smpi_process_index());
329 retval = MPI_SUCCESS;
334 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
335 MPI_Group group2, int *ranks2)
337 int retval, i, index;
338 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
339 retval = MPI_ERR_GROUP;
341 for (i = 0; i < n; i++) {
342 if(ranks1[i]==MPI_PROC_NULL){
343 ranks2[i]=MPI_PROC_NULL;
345 index = smpi_group_index(group1, ranks1[i]);
346 ranks2[i] = smpi_group_rank(group2, index);
349 retval = MPI_SUCCESS;
354 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
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;
363 *result = smpi_group_compare(group1, group2);
364 retval = MPI_SUCCESS;
369 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
370 MPI_Group * newgroup)
372 int retval, i, proc1, proc2, size, size2;
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;
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) {
389 *newgroup = MPI_GROUP_EMPTY;
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);
397 for (i = size2; i < size; i++) {
398 proc2 = smpi_group_index(group2, i - size2);
399 smpi_group_set_mapping(*newgroup, proc2, i);
402 retval = MPI_SUCCESS;
407 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
408 MPI_Group * newgroup)
410 int retval, i, proc1, proc2, size;
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;
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) {
426 *newgroup = MPI_GROUP_EMPTY;
428 *newgroup = smpi_group_new(size);
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);
439 retval = MPI_SUCCESS;
444 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
446 int retval, i, proc1, proc2, size, size2;
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;
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) {
462 *newgroup = MPI_GROUP_EMPTY;
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);
473 retval = MPI_SUCCESS;
478 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
482 if (group == MPI_GROUP_NULL) {
483 retval = MPI_ERR_GROUP;
484 } else if (newgroup == NULL) {
485 retval = MPI_ERR_ARG;
487 retval = smpi_group_incl(group, n, ranks, newgroup);
492 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
494 int retval, i, j, newsize, oldsize, index;
496 if (group == MPI_GROUP_NULL) {
497 retval = MPI_ERR_GROUP;
498 } else if (newgroup == NULL) {
499 retval = MPI_ERR_ARG;
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;
511 oldsize=smpi_group_size(group);
512 newsize = oldsize - n;
513 *newgroup = smpi_group_new(newsize);
515 int* to_exclude=xbt_new0(int, smpi_group_size(group));
516 for(i=0; i<oldsize; i++)
519 to_exclude[ranks[i]]=1;
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);
530 xbt_free(to_exclude);
532 retval = MPI_SUCCESS;
537 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
538 MPI_Group * newgroup)
540 int retval, i, j, rank, size, index;
542 if (group == MPI_GROUP_NULL) {
543 retval = MPI_ERR_GROUP;
544 } else if (newgroup == NULL) {
545 retval = MPI_ERR_ARG;
548 *newgroup = MPI_GROUP_EMPTY;
551 for (i = 0; i < n; i++) {
552 for (rank = ranges[i][0]; /* First */
553 rank >= 0 && rank < smpi_group_size(group); /* Last */
556 if(rank == ranges[i][1]){/*already last ?*/
559 rank += ranges[i][2]; /* Stride */
560 if (ranges[i][0]<ranges[i][1]){
561 if(rank > ranges[i][1])
564 if(rank < ranges[i][1])
570 *newgroup = smpi_group_new(size);
572 for (i = 0; i < n; i++) {
573 for (rank = ranges[i][0]; /* First */
574 rank >= 0 && rank < smpi_group_size(group); /* Last */
576 index = smpi_group_index(group, rank);
577 smpi_group_set_mapping(*newgroup, index, j);
579 if(rank == ranges[i][1]){/*already last ?*/
582 rank += ranges[i][2]; /* Stride */
583 if (ranges[i][0]<ranges[i][1]){
584 if(rank > ranges[i][1])
587 if(rank < ranges[i][1])
593 retval = MPI_SUCCESS;
598 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
599 MPI_Group * newgroup)
601 int retval, i, rank, newrank,oldrank, size, index, add;
603 if (group == MPI_GROUP_NULL) {
604 retval = MPI_ERR_GROUP;
605 } else if (newgroup == NULL) {
606 retval = MPI_ERR_ARG;
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);
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 */
622 if(rank == ranges[i][1]){/*already last ?*/
625 rank += ranges[i][2]; /* Stride */
626 if (ranges[i][0]<ranges[i][1]){
627 if(rank > ranges[i][1])
630 if(rank < ranges[i][1])
636 *newgroup = MPI_GROUP_EMPTY;
638 *newgroup = smpi_group_new(size);
641 while (newrank < size) {
643 for (i = 0; i < n; i++) {
644 for (rank = ranges[i][0];
645 rank >= 0 && rank < smpi_group_size(group);
651 if(rank == ranges[i][1]){/*already last ?*/
654 rank += ranges[i][2]; /* Stride */
655 if (ranges[i][0]<ranges[i][1]){
656 if(rank > ranges[i][1])
659 if(rank < ranges[i][1])
665 index = smpi_group_index(group, oldrank);
666 smpi_group_set_mapping(*newgroup, index, newrank);
674 retval = MPI_SUCCESS;
679 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
682 if (comm == MPI_COMM_NULL) {
683 retval = MPI_ERR_COMM;
684 } else if (rank == NULL) {
685 retval = MPI_ERR_ARG;
687 *rank = smpi_comm_rank(comm);
688 retval = MPI_SUCCESS;
693 int PMPI_Comm_size(MPI_Comm comm, int *size)
696 if (comm == MPI_COMM_NULL) {
697 retval = MPI_ERR_COMM;
698 } else if (size == NULL) {
699 retval = MPI_ERR_ARG;
701 *size = smpi_comm_size(comm);
702 retval = MPI_SUCCESS;
707 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
711 if (comm == MPI_COMM_NULL) {
712 retval = MPI_ERR_COMM;
713 } else if (name == NULL || len == NULL) {
714 retval = MPI_ERR_ARG;
716 smpi_comm_get_name(comm, name, len);
717 retval = MPI_SUCCESS;
722 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
726 if (comm == MPI_COMM_NULL) {
727 retval = MPI_ERR_COMM;
728 } else if (group == NULL) {
729 retval = MPI_ERR_ARG;
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;
742 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
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;
751 if (comm1 == comm2) { /* Same communicators means same groups */
755 smpi_group_compare(smpi_comm_group(comm1),
756 smpi_comm_group(comm2));
757 if (*result == MPI_IDENT) {
758 *result = MPI_CONGRUENT;
761 retval = MPI_SUCCESS;
766 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
770 if (comm == MPI_COMM_NULL) {
771 retval = MPI_ERR_COMM;
772 } else if (newcomm == NULL) {
773 retval = MPI_ERR_ARG;
775 retval = smpi_comm_dup(comm, newcomm);
780 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
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;
795 *newcomm = smpi_comm_new(group, NULL);
796 retval = MPI_SUCCESS;
801 int PMPI_Comm_free(MPI_Comm * comm)
806 retval = MPI_ERR_ARG;
807 } else if (*comm == MPI_COMM_NULL) {
808 retval = MPI_ERR_COMM;
810 smpi_comm_destroy(*comm);
811 *comm = MPI_COMM_NULL;
812 retval = MPI_SUCCESS;
817 int PMPI_Comm_disconnect(MPI_Comm * comm)
819 /* TODO: wait until all communication in comm are done */
823 retval = MPI_ERR_ARG;
824 } else if (*comm == MPI_COMM_NULL) {
825 retval = MPI_ERR_COMM;
827 smpi_comm_destroy(*comm);
828 *comm = MPI_COMM_NULL;
829 retval = MPI_SUCCESS;
834 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
839 if (comm_out == NULL) {
840 retval = MPI_ERR_ARG;
841 } else if (comm == MPI_COMM_NULL) {
842 retval = MPI_ERR_COMM;
844 *comm_out = smpi_comm_split(comm, color, key);
845 retval = MPI_SUCCESS;
852 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
853 int tag, MPI_Comm comm, MPI_Request * request)
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;
867 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
868 retval = MPI_SUCCESS;
871 if (retval != MPI_SUCCESS && request)
872 *request = MPI_REQUEST_NULL;
876 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
877 int tag, MPI_Comm comm, MPI_Request * request)
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;
891 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
892 retval = MPI_SUCCESS;
895 if (retval != MPI_SUCCESS && request)
896 *request = MPI_REQUEST_NULL;
900 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
901 int dst, int tag, MPI_Comm comm, MPI_Request* request)
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;
915 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
916 retval = MPI_SUCCESS;
919 if (retval != MPI_SUCCESS && request)
920 *request = MPI_REQUEST_NULL;
924 int PMPI_Start(MPI_Request * request)
929 if (request == NULL || *request == MPI_REQUEST_NULL) {
930 retval = MPI_ERR_REQUEST;
932 smpi_mpi_start(*request);
933 retval = MPI_SUCCESS;
939 int PMPI_Startall(int count, MPI_Request * requests)
944 if (requests == NULL) {
945 retval = MPI_ERR_ARG;
947 retval = MPI_SUCCESS;
948 for (i = 0 ; i < count ; i++) {
949 if(requests[i] == MPI_REQUEST_NULL) {
950 retval = MPI_ERR_REQUEST;
953 if(retval != MPI_ERR_REQUEST) {
954 smpi_mpi_startall(count, requests);
961 int PMPI_Request_free(MPI_Request * request)
966 if (*request == MPI_REQUEST_NULL) {
967 retval = MPI_ERR_ARG;
969 smpi_mpi_request_free(request);
970 retval = MPI_SUCCESS;
976 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
977 int tag, MPI_Comm comm, MPI_Request * request)
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;
1003 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1004 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1006 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1007 extra->type = TRACING_IRECV;
1008 extra->send_size = count;
1009 extra->src = src_traced;
1011 extra->datatype1 = encode_datatype(datatype);
1012 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1015 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1016 retval = MPI_SUCCESS;
1019 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1020 (*request)->recv = 1;
1025 if (retval != MPI_SUCCESS && request)
1026 *request = MPI_REQUEST_NULL;
1031 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1032 int tag, MPI_Comm comm, MPI_Request * request)
1037 if (request == NULL) {
1038 retval = MPI_ERR_ARG;
1039 } else if (comm == MPI_COMM_NULL) {
1040 retval = MPI_ERR_COMM;
1041 } else if (dst == MPI_PROC_NULL) {
1042 *request = MPI_REQUEST_NULL;
1043 retval = MPI_SUCCESS;
1044 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1045 retval = MPI_ERR_RANK;
1046 } else if (count < 0) {
1047 retval = MPI_ERR_COUNT;
1048 } else if (buf==NULL && count > 0) {
1049 retval = MPI_ERR_COUNT;
1050 } else if (!is_datatype_valid(datatype)) {
1051 retval = MPI_ERR_TYPE;
1052 } else if(tag<0 && tag != MPI_ANY_TAG){
1053 retval = MPI_ERR_TAG;
1057 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1058 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1060 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1061 extra->type = TRACING_ISEND;
1062 extra->send_size = count;
1064 extra->dst = dst_traced;
1065 extra->datatype1 = encode_datatype(datatype);
1066 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1067 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1070 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1071 retval = MPI_SUCCESS;
1074 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1075 (*request)->send = 1;
1080 if (retval != MPI_SUCCESS && request)
1081 *request = MPI_REQUEST_NULL;
1085 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1086 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1091 if (request == NULL) {
1092 retval = MPI_ERR_ARG;
1093 } else if (comm == MPI_COMM_NULL) {
1094 retval = MPI_ERR_COMM;
1095 } else if (dst == MPI_PROC_NULL) {
1096 *request = MPI_REQUEST_NULL;
1097 retval = MPI_SUCCESS;
1098 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1099 retval = MPI_ERR_RANK;
1100 } else if (count < 0) {
1101 retval = MPI_ERR_COUNT;
1102 } else if (buf==NULL && count > 0) {
1103 retval = MPI_ERR_COUNT;
1104 } else if (!is_datatype_valid(datatype)) {
1105 retval = MPI_ERR_TYPE;
1106 } else if(tag<0 && tag != MPI_ANY_TAG){
1107 retval = MPI_ERR_TAG;
1111 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1112 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1113 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1114 extra->type = TRACING_ISSEND;
1115 extra->send_size = count;
1117 extra->dst = dst_traced;
1118 extra->datatype1 = encode_datatype(datatype);
1119 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1120 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1123 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1124 retval = MPI_SUCCESS;
1127 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1128 (*request)->send = 1;
1133 if (retval != MPI_SUCCESS && request)
1134 *request = MPI_REQUEST_NULL;
1138 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1139 MPI_Comm comm, MPI_Status * status)
1144 if (comm == MPI_COMM_NULL) {
1145 retval = MPI_ERR_COMM;
1146 } else if (src == MPI_PROC_NULL) {
1147 smpi_empty_status(status);
1148 status->MPI_SOURCE = MPI_PROC_NULL;
1149 retval = MPI_SUCCESS;
1150 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1151 retval = MPI_ERR_RANK;
1152 } else if (count < 0) {
1153 retval = MPI_ERR_COUNT;
1154 } else if (buf==NULL && count > 0) {
1155 retval = MPI_ERR_COUNT;
1156 } else if (!is_datatype_valid(datatype)) {
1157 retval = MPI_ERR_TYPE;
1158 } else if(tag<0 && tag != MPI_ANY_TAG){
1159 retval = MPI_ERR_TAG;
1162 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1163 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1164 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1165 extra->type = TRACING_RECV;
1166 extra->send_size = count;
1167 extra->src = src_traced;
1169 extra->datatype1 = encode_datatype(datatype);
1170 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1173 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1174 retval = MPI_SUCCESS;
1177 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1178 if(status!=MPI_STATUS_IGNORE){
1179 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1180 TRACE_smpi_recv(rank, src_traced, rank);
1182 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1190 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1197 if (comm == MPI_COMM_NULL) {
1198 retval = MPI_ERR_COMM;
1199 } else if (dst == MPI_PROC_NULL) {
1200 retval = MPI_SUCCESS;
1201 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1202 retval = MPI_ERR_RANK;
1203 } else if (count < 0) {
1204 retval = MPI_ERR_COUNT;
1205 } else if (buf==NULL && count > 0) {
1206 retval = MPI_ERR_COUNT;
1207 } else if (!is_datatype_valid(datatype)) {
1208 retval = MPI_ERR_TYPE;
1209 } else if(tag<0 && tag != MPI_ANY_TAG){
1210 retval = MPI_ERR_TAG;
1214 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1215 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1216 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1217 extra->type = TRACING_SEND;
1218 extra->send_size = count;
1220 extra->dst = dst_traced;
1221 extra->datatype1 = encode_datatype(datatype);
1222 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1223 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1226 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1227 retval = MPI_SUCCESS;
1230 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1240 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1245 if (comm == MPI_COMM_NULL) {
1246 retval = MPI_ERR_COMM;
1247 } else if (dst == MPI_PROC_NULL) {
1248 retval = MPI_SUCCESS;
1249 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1250 retval = MPI_ERR_RANK;
1251 } else if (count < 0) {
1252 retval = MPI_ERR_COUNT;
1253 } else if (buf==NULL && count > 0) {
1254 retval = MPI_ERR_COUNT;
1255 } else if (!is_datatype_valid(datatype)){
1256 retval = MPI_ERR_TYPE;
1257 } else if(tag<0 && tag != MPI_ANY_TAG){
1258 retval = MPI_ERR_TAG;
1262 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1263 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1264 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1265 extra->type = TRACING_SSEND;
1266 extra->send_size = count;
1268 extra->dst = dst_traced;
1269 extra->datatype1 = encode_datatype(datatype);
1270 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra); TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1273 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1274 retval = MPI_SUCCESS;
1277 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1285 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1286 int dst, int sendtag, void *recvbuf, int recvcount,
1287 MPI_Datatype recvtype, int src, int recvtag,
1288 MPI_Comm comm, MPI_Status * status)
1294 if (comm == MPI_COMM_NULL) {
1295 retval = MPI_ERR_COMM;
1296 } else if (!is_datatype_valid(sendtype)
1297 || !is_datatype_valid(recvtype)) {
1298 retval = MPI_ERR_TYPE;
1299 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1300 smpi_empty_status(status);
1301 status->MPI_SOURCE = MPI_PROC_NULL;
1302 retval = MPI_SUCCESS;
1303 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1304 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1305 retval = MPI_ERR_RANK;
1306 } else if (sendcount < 0 || recvcount<0) {
1307 retval = MPI_ERR_COUNT;
1308 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1309 retval = MPI_ERR_COUNT;
1310 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1311 retval = MPI_ERR_TAG;
1315 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1316 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1317 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1318 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1319 extra->type = TRACING_SENDRECV;
1320 extra->send_size = sendcount;
1321 extra->recv_size = recvcount;
1322 extra->src = src_traced;
1323 extra->dst = dst_traced;
1324 extra->datatype1 = encode_datatype(sendtype);
1325 extra->datatype2 = encode_datatype(recvtype);
1327 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1328 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1332 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1333 recvcount, recvtype, src, recvtag, comm, status);
1334 retval = MPI_SUCCESS;
1337 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1338 TRACE_smpi_recv(rank, src_traced, rank);
1347 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1348 int dst, int sendtag, int src, int recvtag,
1349 MPI_Comm comm, MPI_Status * status)
1351 //TODO: suboptimal implementation
1354 if (!is_datatype_valid(datatype)) {
1355 retval = MPI_ERR_TYPE;
1356 } else if (count < 0) {
1357 retval = MPI_ERR_COUNT;
1359 int size = smpi_datatype_get_extent(datatype) * count;
1360 recvbuf = xbt_new0(char, size);
1362 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1363 datatype, src, recvtag, comm, status);
1364 if(retval==MPI_SUCCESS){
1365 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1373 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1377 if (request == NULL || flag == NULL) {
1378 retval = MPI_ERR_ARG;
1379 } else if (*request == MPI_REQUEST_NULL) {
1381 smpi_empty_status(status);
1382 retval = MPI_SUCCESS;
1385 int rank = request && (*request)->comm != MPI_COMM_NULL
1386 ? smpi_process_index()
1389 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1390 extra->type = TRACING_TEST;
1391 TRACE_smpi_testing_in(rank, extra);
1393 *flag = smpi_mpi_test(request, status);
1395 TRACE_smpi_testing_out(rank);
1397 retval = MPI_SUCCESS;
1403 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1404 MPI_Status * status)
1409 if (index == NULL || flag == NULL) {
1410 retval = MPI_ERR_ARG;
1412 *flag = smpi_mpi_testany(count, requests, index, status);
1413 retval = MPI_SUCCESS;
1419 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1425 retval = MPI_ERR_ARG;
1427 *flag = smpi_mpi_testall(count, requests, statuses);
1428 retval = MPI_SUCCESS;
1434 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1438 if (status == NULL) {
1439 retval = MPI_ERR_ARG;
1440 } else if (comm == MPI_COMM_NULL) {
1441 retval = MPI_ERR_COMM;
1442 } else if (source == MPI_PROC_NULL) {
1443 smpi_empty_status(status);
1444 status->MPI_SOURCE = MPI_PROC_NULL;
1445 retval = MPI_SUCCESS;
1447 smpi_mpi_probe(source, tag, comm, status);
1448 retval = MPI_SUCCESS;
1455 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1460 retval = MPI_ERR_ARG;
1461 } else if (status == NULL) {
1462 retval = MPI_ERR_ARG;
1463 } else if (comm == MPI_COMM_NULL) {
1464 retval = MPI_ERR_COMM;
1465 } else if (source == MPI_PROC_NULL) {
1467 smpi_empty_status(status);
1468 status->MPI_SOURCE = MPI_PROC_NULL;
1469 retval = MPI_SUCCESS;
1471 smpi_mpi_iprobe(source, tag, comm, flag, status);
1472 retval = MPI_SUCCESS;
1478 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1484 smpi_empty_status(status);
1486 if (request == NULL) {
1487 retval = MPI_ERR_ARG;
1488 } else if (*request == MPI_REQUEST_NULL) {
1489 retval = MPI_SUCCESS;
1493 int rank = request && (*request)->comm != MPI_COMM_NULL
1494 ? smpi_process_index()
1497 int src_traced = (*request)->src;
1498 int dst_traced = (*request)->dst;
1499 MPI_Comm comm = (*request)->comm;
1500 int is_wait_for_receive = (*request)->recv;
1501 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1502 extra->type = TRACING_WAIT;
1503 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1506 smpi_mpi_wait(request, status);
1507 retval = MPI_SUCCESS;
1510 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1511 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1512 if (is_wait_for_receive) {
1513 if(src_traced==MPI_ANY_SOURCE)
1514 src_traced = (status!=MPI_STATUS_IGNORE) ?
1515 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1517 TRACE_smpi_recv(rank, src_traced, dst_traced);
1527 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1534 //save requests information for tracing
1536 int *srcs = xbt_new0(int, count);
1537 int *dsts = xbt_new0(int, count);
1538 int *recvs = xbt_new0(int, count);
1539 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1541 for (i = 0; i < count; i++) {
1542 MPI_Request req = requests[i]; //already received requests are no longer valid
1546 recvs[i] = req->recv;
1547 comms[i] = req->comm;
1550 int rank_traced = smpi_process_index();
1551 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1552 extra->type = TRACING_WAITANY;
1553 extra->send_size=count;
1554 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1557 *index = smpi_mpi_waitany(count, requests, status);
1559 if(*index!=MPI_UNDEFINED){
1560 int src_traced = srcs[*index];
1561 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1562 int dst_traced = dsts[*index];
1563 int is_wait_for_receive = recvs[*index];
1564 if (is_wait_for_receive) {
1565 if(srcs[*index]==MPI_ANY_SOURCE)
1566 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1567 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1569 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1571 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1583 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1588 //save information from requests
1590 int *srcs = xbt_new0(int, count);
1591 int *dsts = xbt_new0(int, count);
1592 int *recvs = xbt_new0(int, count);
1593 int *valid = xbt_new0(int, count);
1594 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1596 //int valid_count = 0;
1597 for (i = 0; i < count; i++) {
1598 MPI_Request req = requests[i];
1599 if(req!=MPI_REQUEST_NULL){
1602 recvs[i] = req->recv;
1603 comms[i] = req->comm;
1609 int rank_traced = smpi_process_index();
1610 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1611 extra->type = TRACING_WAITALL;
1612 extra->send_size=count;
1613 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1615 int retval = smpi_mpi_waitall(count, requests, status);
1617 for (i = 0; i < count; i++) {
1619 //int src_traced = srcs[*index];
1620 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1621 int src_traced = srcs[i];
1622 int dst_traced = dsts[i];
1623 int is_wait_for_receive = recvs[i];
1624 if (is_wait_for_receive) {
1625 if(src_traced==MPI_ANY_SOURCE)
1626 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1627 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1629 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1633 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1645 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1646 int *indices, MPI_Status status[])
1651 if (outcount == NULL) {
1652 retval = MPI_ERR_ARG;
1654 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1655 retval = MPI_SUCCESS;
1661 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1662 int* indices, MPI_Status status[])
1667 if (outcount == NULL) {
1668 retval = MPI_ERR_ARG;
1670 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1671 retval = MPI_SUCCESS;
1678 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1684 if (comm == MPI_COMM_NULL) {
1685 retval = MPI_ERR_COMM;
1686 } else if (!is_datatype_valid(datatype)) {
1687 retval = MPI_ERR_ARG;
1690 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1691 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1693 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1694 extra->type = TRACING_BCAST;
1695 extra->send_size = count;
1696 extra->root = root_traced;
1697 extra->datatype1 = encode_datatype(datatype);
1698 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1701 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1702 retval = MPI_SUCCESS;
1704 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1712 int PMPI_Barrier(MPI_Comm comm)
1718 if (comm == MPI_COMM_NULL) {
1719 retval = MPI_ERR_COMM;
1722 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1723 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1724 extra->type = TRACING_BARRIER;
1725 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1727 mpi_coll_barrier_fun(comm);
1728 retval = MPI_SUCCESS;
1730 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1738 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1739 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1740 int root, MPI_Comm comm)
1746 if (comm == MPI_COMM_NULL) {
1747 retval = MPI_ERR_COMM;
1748 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1749 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1750 retval = MPI_ERR_TYPE;
1751 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1752 ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1753 retval = MPI_ERR_COUNT;
1756 char* sendtmpbuf = (char*) sendbuf;
1757 int sendtmpcount = sendcount;
1758 MPI_Datatype sendtmptype = sendtype;
1759 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1761 sendtmptype=recvtype;
1764 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1765 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1766 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1767 extra->type = TRACING_GATHER;
1768 extra->send_size = sendtmpcount;
1769 extra->recv_size = recvcount;
1770 extra->root = root_traced;
1771 extra->datatype1 = encode_datatype(sendtmptype);
1772 extra->datatype2 = encode_datatype(recvtype);
1774 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1776 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1777 recvtype, root, comm);
1780 retval = MPI_SUCCESS;
1782 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1790 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1791 void *recvbuf, int *recvcounts, int *displs,
1792 MPI_Datatype recvtype, int root, MPI_Comm comm)
1798 if (comm == MPI_COMM_NULL) {
1799 retval = MPI_ERR_COMM;
1800 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1801 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1802 retval = MPI_ERR_TYPE;
1803 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1804 retval = MPI_ERR_COUNT;
1805 } else if (recvcounts == NULL || displs == NULL) {
1806 retval = MPI_ERR_ARG;
1808 char* sendtmpbuf = (char*) sendbuf;
1809 int sendtmpcount = sendcount;
1810 MPI_Datatype sendtmptype = sendtype;
1811 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1813 sendtmptype=recvtype;
1817 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1818 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1820 int size = smpi_comm_size(comm);
1821 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1822 extra->type = TRACING_GATHERV;
1823 extra->send_size = sendtmpcount;
1824 extra->recvcounts= xbt_malloc(size*sizeof(int));
1825 for(i=0; i< size; i++)//copy data to avoid bad free
1826 extra->recvcounts[i] = recvcounts[i];
1827 extra->num_processes = size;
1828 extra->root = root_traced;
1829 extra->datatype1 = encode_datatype(sendtmptype);
1830 extra->datatype2 = encode_datatype(recvtype);
1832 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1834 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1835 displs, recvtype, root, comm);
1836 retval = MPI_SUCCESS;
1838 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1846 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1847 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1854 if (comm == MPI_COMM_NULL) {
1855 retval = MPI_ERR_COMM;
1856 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1857 (recvtype == MPI_DATATYPE_NULL)){
1858 retval = MPI_ERR_TYPE;
1859 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1861 retval = MPI_ERR_COUNT;
1863 if(sendbuf == MPI_IN_PLACE) {
1864 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1865 sendcount=recvcount;
1869 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1870 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1871 extra->type = TRACING_ALLGATHER;
1872 extra->send_size = sendcount;
1873 extra->recv_size = recvcount;
1874 extra->datatype1 = encode_datatype(sendtype);
1875 extra->datatype2 = encode_datatype(recvtype);
1877 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1879 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1881 retval = MPI_SUCCESS;
1884 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1891 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1892 void *recvbuf, int *recvcounts, int *displs,
1893 MPI_Datatype recvtype, MPI_Comm comm)
1899 if (comm == MPI_COMM_NULL) {
1900 retval = MPI_ERR_COMM;
1901 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1902 (recvtype == MPI_DATATYPE_NULL)){
1903 retval = MPI_ERR_TYPE;
1904 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1905 retval = MPI_ERR_COUNT;
1906 } else if (recvcounts == NULL || displs == NULL) {
1907 retval = MPI_ERR_ARG;
1910 if(sendbuf == MPI_IN_PLACE) {
1911 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1912 sendcount=recvcounts[smpi_comm_rank(comm)];
1916 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1918 int size = smpi_comm_size(comm);
1919 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1920 extra->type = TRACING_ALLGATHERV;
1921 extra->send_size = sendcount;
1922 extra->recvcounts= xbt_malloc(size*sizeof(int));
1923 for(i=0; i< size; i++)//copy data to avoid bad free
1924 extra->recvcounts[i] = recvcounts[i];
1925 extra->num_processes = size;
1926 extra->datatype1 = encode_datatype(sendtype);
1927 extra->datatype2 = encode_datatype(recvtype);
1929 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1931 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1932 displs, recvtype, comm);
1933 retval = MPI_SUCCESS;
1935 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1943 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1944 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1945 int root, MPI_Comm comm)
1951 if (comm == MPI_COMM_NULL) {
1952 retval = MPI_ERR_COMM;
1953 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1954 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1955 retval = MPI_ERR_TYPE;
1956 } else if ((sendbuf == recvbuf) ||
1957 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
1958 retval = MPI_ERR_BUFFER;
1961 if (recvbuf == MPI_IN_PLACE) {
1963 recvcount=sendcount;
1966 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1967 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1968 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1969 extra->type = TRACING_SCATTER;
1970 extra->send_size = sendcount;
1971 extra->recv_size= recvcount;
1972 extra->root = root_traced;
1973 extra->datatype1 = encode_datatype(sendtype);
1974 extra->datatype2 = encode_datatype(recvtype);
1976 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1978 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1979 recvtype, root, comm);
1980 retval = MPI_SUCCESS;
1982 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1990 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1991 MPI_Datatype sendtype, void *recvbuf, int recvcount,
1992 MPI_Datatype recvtype, int root, MPI_Comm comm)
1998 if (comm == MPI_COMM_NULL) {
1999 retval = MPI_ERR_COMM;
2000 } else if (sendcounts == NULL || displs == NULL) {
2001 retval = MPI_ERR_ARG;
2002 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2003 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2004 retval = MPI_ERR_TYPE;
2006 if (recvbuf == MPI_IN_PLACE) {
2008 recvcount=sendcounts[smpi_comm_rank(comm)];
2011 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2012 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2014 int size = smpi_comm_size(comm);
2015 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2016 extra->type = TRACING_SCATTERV;
2017 extra->recv_size = recvcount;
2018 extra->sendcounts= xbt_malloc(size*sizeof(int));
2019 for(i=0; i< size; i++)//copy data to avoid bad free
2020 extra->sendcounts[i] = sendcounts[i];
2021 extra->num_processes = size;
2022 extra->root = root_traced;
2023 extra->datatype1 = encode_datatype(sendtype);
2024 extra->datatype2 = encode_datatype(recvtype);
2026 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2029 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2030 recvcount, recvtype, root, comm);
2031 retval = MPI_SUCCESS;
2033 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2041 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2042 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2048 if (comm == MPI_COMM_NULL) {
2049 retval = MPI_ERR_COMM;
2050 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2051 retval = MPI_ERR_ARG;
2054 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2055 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2056 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2057 extra->type = TRACING_REDUCE;
2058 extra->send_size = count;
2059 extra->datatype1 = encode_datatype(datatype);
2060 extra->root = root_traced;
2062 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2064 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2066 retval = MPI_SUCCESS;
2068 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2076 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2077 MPI_Datatype datatype, MPI_Op op){
2081 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2082 retval = MPI_ERR_ARG;
2084 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2091 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2092 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2098 if (comm == MPI_COMM_NULL) {
2099 retval = MPI_ERR_COMM;
2100 } else if (!is_datatype_valid(datatype)) {
2101 retval = MPI_ERR_TYPE;
2102 } else if (op == MPI_OP_NULL) {
2103 retval = MPI_ERR_OP;
2106 char* sendtmpbuf = (char*) sendbuf;
2107 if( sendbuf == MPI_IN_PLACE ) {
2108 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2109 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2112 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2113 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2114 extra->type = TRACING_ALLREDUCE;
2115 extra->send_size = count;
2116 extra->datatype1 = encode_datatype(datatype);
2118 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2120 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2122 if( sendbuf == MPI_IN_PLACE ) {
2123 xbt_free(sendtmpbuf);
2126 retval = MPI_SUCCESS;
2128 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2136 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2137 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2143 if (comm == MPI_COMM_NULL) {
2144 retval = MPI_ERR_COMM;
2145 } else if (!is_datatype_valid(datatype)) {
2146 retval = MPI_ERR_TYPE;
2147 } else if (op == MPI_OP_NULL) {
2148 retval = MPI_ERR_OP;
2151 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2152 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2153 extra->type = TRACING_SCAN;
2154 extra->send_size = count;
2155 extra->datatype1 = encode_datatype(datatype);
2157 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2159 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2160 retval = MPI_SUCCESS;
2162 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2170 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2171 MPI_Op op, MPI_Comm comm){
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;
2184 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2185 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2186 extra->type = TRACING_EXSCAN;
2187 extra->send_size = count;
2188 extra->datatype1 = encode_datatype(datatype);
2190 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2192 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2193 retval = MPI_SUCCESS;
2195 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2203 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2204 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2209 if (comm == MPI_COMM_NULL) {
2210 retval = MPI_ERR_COMM;
2211 } else if (!is_datatype_valid(datatype)) {
2212 retval = MPI_ERR_TYPE;
2213 } else if (op == MPI_OP_NULL) {
2214 retval = MPI_ERR_OP;
2215 } else if (recvcounts == NULL) {
2216 retval = MPI_ERR_ARG;
2219 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2221 int size = smpi_comm_size(comm);
2222 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2223 extra->type = TRACING_REDUCE_SCATTER;
2224 extra->send_size = 0;
2225 extra->recvcounts= xbt_malloc(size*sizeof(int));
2226 for(i=0; i< size; i++)//copy data to avoid bad free
2227 extra->recvcounts[i] = recvcounts[i];
2228 extra->num_processes = size;
2229 extra->datatype1 = encode_datatype(datatype);
2231 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2233 void* sendtmpbuf=sendbuf;
2234 if(sendbuf==MPI_IN_PLACE){
2238 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2239 datatype, op, comm);
2240 retval = MPI_SUCCESS;
2242 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2250 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2251 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2256 if (comm == MPI_COMM_NULL) {
2257 retval = MPI_ERR_COMM;
2258 } else if (!is_datatype_valid(datatype)) {
2259 retval = MPI_ERR_TYPE;
2260 } else if (op == MPI_OP_NULL) {
2261 retval = MPI_ERR_OP;
2262 } else if (recvcount < 0) {
2263 retval = MPI_ERR_ARG;
2265 int count=smpi_comm_size(comm);
2268 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2269 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2270 extra->type = TRACING_REDUCE_SCATTER;
2271 extra->send_size = 0;
2272 extra->recvcounts= xbt_malloc(count*sizeof(int));
2273 for(i=0; i< count; i++)//copy data to avoid bad free
2274 extra->recvcounts[i] = recvcount;
2275 extra->num_processes = count;
2276 extra->datatype1 = encode_datatype(datatype);
2278 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2280 int* recvcounts=(int*)xbt_malloc(count);
2281 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2282 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2283 datatype, op, comm);
2284 xbt_free(recvcounts);
2285 retval = MPI_SUCCESS;
2287 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2295 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2296 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2303 if (comm == MPI_COMM_NULL) {
2304 retval = MPI_ERR_COMM;
2305 } else if (sendtype == MPI_DATATYPE_NULL
2306 || recvtype == MPI_DATATYPE_NULL) {
2307 retval = MPI_ERR_TYPE;
2310 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2311 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2312 extra->type = TRACING_ALLTOALL;
2313 extra->send_size = sendcount;
2314 extra->recv_size = recvcount;
2315 extra->datatype1 = encode_datatype(sendtype);
2316 extra->datatype2 = encode_datatype(recvtype);
2318 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2320 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2322 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2330 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2331 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2332 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2338 if (comm == MPI_COMM_NULL) {
2339 retval = MPI_ERR_COMM;
2340 } else if (sendtype == MPI_DATATYPE_NULL
2341 || recvtype == MPI_DATATYPE_NULL) {
2342 retval = MPI_ERR_TYPE;
2343 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2344 || recvdisps == NULL) {
2345 retval = MPI_ERR_ARG;
2348 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2350 int size = smpi_comm_size(comm);
2351 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2352 extra->type = TRACING_ALLTOALLV;
2353 extra->send_size = 0;
2354 extra->recv_size = 0;
2355 extra->recvcounts= xbt_malloc(size*sizeof(int));
2356 extra->sendcounts= xbt_malloc(size*sizeof(int));
2358 for(i=0; i< size; i++){//copy data to avoid bad free
2359 extra->send_size += sendcounts[i];
2360 extra->recv_size += recvcounts[i];
2362 extra->sendcounts[i] = sendcounts[i];
2363 extra->recvcounts[i] = recvcounts[i];
2365 extra->num_processes = size;
2367 extra->datatype1 = encode_datatype(sendtype);
2368 extra->datatype2 = encode_datatype(recvtype);
2370 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2373 mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2374 recvbuf, recvcounts, recvdisps, recvtype,
2377 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2386 int PMPI_Get_processor_name(char *name, int *resultlen)
2388 int retval = MPI_SUCCESS;
2390 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2391 strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2392 strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2393 MPI_MAX_PROCESSOR_NAME - 1 );
2396 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2401 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2403 int retval = MPI_SUCCESS;
2406 if (status == NULL || count == NULL) {
2407 retval = MPI_ERR_ARG;
2408 } else if (!is_datatype_valid(datatype)) {
2409 retval = MPI_ERR_TYPE;
2411 size = smpi_datatype_size(datatype);
2414 } else if (status->count % size != 0) {
2415 retval = MPI_UNDEFINED;
2417 *count = smpi_mpi_get_count(status, datatype);
2423 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2426 if (old_type == MPI_DATATYPE_NULL) {
2427 retval = MPI_ERR_TYPE;
2428 } else if (count<0){
2429 retval = MPI_ERR_COUNT;
2431 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2436 int PMPI_Type_commit(MPI_Datatype* datatype) {
2439 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2440 retval = MPI_ERR_TYPE;
2442 smpi_datatype_commit(datatype);
2443 retval = MPI_SUCCESS;
2449 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2452 if (old_type == MPI_DATATYPE_NULL) {
2453 retval = MPI_ERR_TYPE;
2454 } else if (count<0 || blocklen<0){
2455 retval = MPI_ERR_COUNT;
2457 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2462 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2465 if (old_type == MPI_DATATYPE_NULL) {
2466 retval = MPI_ERR_TYPE;
2467 } else if (count<0 || blocklen<0){
2468 retval = MPI_ERR_COUNT;
2470 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2475 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2476 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2479 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2482 if (old_type == MPI_DATATYPE_NULL) {
2483 retval = MPI_ERR_TYPE;
2484 } else if (count<0){
2485 retval = MPI_ERR_COUNT;
2487 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2492 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2495 if (old_type == MPI_DATATYPE_NULL) {
2496 retval = MPI_ERR_TYPE;
2497 } else if (count<0){
2498 retval = MPI_ERR_COUNT;
2500 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2505 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2508 if (old_type == MPI_DATATYPE_NULL) {
2509 retval = MPI_ERR_TYPE;
2510 } else if (count<0){
2511 retval = MPI_ERR_COUNT;
2513 int* blocklens=(int*)xbt_malloc(blocklength*count);
2514 for (i=0; i<count;i++)blocklens[i]=blocklength;
2515 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2516 xbt_free(blocklens);
2522 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2525 if (old_type == MPI_DATATYPE_NULL) {
2526 retval = MPI_ERR_TYPE;
2527 } else if (count<0){
2528 retval = MPI_ERR_COUNT;
2530 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2535 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2536 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2539 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2542 if (old_type == MPI_DATATYPE_NULL) {
2543 retval = MPI_ERR_TYPE;
2544 } else if (count<0){
2545 retval = MPI_ERR_COUNT;
2547 int* blocklens=(int*)xbt_malloc(blocklength*count);
2548 for (i=0; i<count;i++)blocklens[i]=blocklength;
2549 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2550 xbt_free(blocklens);
2556 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2560 retval = MPI_ERR_COUNT;
2562 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2567 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2568 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2572 int PMPI_Error_class(int errorcode, int* errorclass) {
2573 // assume smpi uses only standard mpi error codes
2574 *errorclass=errorcode;
2579 int PMPI_Initialized(int* flag) {
2580 *flag=smpi_process_initialized();
2584 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2585 * will be implemented, not only should we check if the topology is NULL, but
2586 * we should check if it is the good topology type (so we have to add a
2587 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2589 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2591 if (comm_old == MPI_COMM_NULL){
2592 retval = MPI_ERR_COMM;
2593 } else if (ndims < 0 ||
2594 (ndims > 0 && (dims == NULL ||
2595 periodic == NULL)) ||
2596 comm_cart == NULL) {
2597 retval = MPI_ERR_ARG;
2599 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2604 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2605 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2606 return MPI_ERR_TOPOLOGY;
2608 if (coords == NULL) {
2611 return smpi_mpi_cart_rank(comm, coords, rank);
2614 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2615 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2616 return MPI_ERR_TOPOLOGY;
2618 if (source == NULL || dest == NULL || direction < 0 ) {
2621 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2624 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2625 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2626 return MPI_ERR_TOPOLOGY;
2628 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2629 return MPI_ERR_RANK;
2634 if(coords == NULL) {
2637 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2640 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2641 if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2642 return MPI_ERR_TOPOLOGY;
2644 if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2647 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2650 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2651 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2652 return MPI_ERR_TOPOLOGY;
2654 if (ndims == NULL) {
2657 return smpi_mpi_cartdim_get(comm, ndims);
2660 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2664 if (ndims < 1 || nnodes < 1) {
2665 return MPI_ERR_DIMS;
2668 return smpi_mpi_dims_create(nnodes, ndims, dims);
2671 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2672 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2673 return MPI_ERR_TOPOLOGY;
2675 if (comm_new == NULL) {
2678 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2681 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2682 if(oldtype == MPI_DATATYPE_NULL) {
2683 return MPI_ERR_TYPE;
2685 int blocks[3] = { 1, 1, 1 };
2686 MPI_Aint disps[3] = { lb, 0, lb+extent };
2687 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2689 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks,
2694 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2696 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2702 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2705 if (comm == MPI_COMM_NULL) {
2706 retval= MPI_ERR_COMM;
2707 }else if ((base == NULL && size != 0)
2708 || disp_unit <= 0 || size < 0 ){
2709 retval= MPI_ERR_OTHER;
2711 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2712 retval = MPI_SUCCESS;
2718 int PMPI_Win_free( MPI_Win* win){
2721 if (win == NULL || *win == MPI_WIN_NULL) {
2722 retval = MPI_ERR_WIN;
2724 retval=smpi_mpi_win_free(win);
2730 int PMPI_Win_set_name(MPI_Win win, char * name)
2733 if (win == MPI_WIN_NULL) {
2734 retval = MPI_ERR_TYPE;
2735 } else if (name == NULL) {
2736 retval = MPI_ERR_ARG;
2738 smpi_mpi_win_set_name(win, name);
2739 retval = MPI_SUCCESS;
2744 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2746 int retval = MPI_SUCCESS;
2748 if (win == MPI_WIN_NULL) {
2749 retval = MPI_ERR_WIN;
2750 } else if (name == NULL) {
2751 retval = MPI_ERR_ARG;
2753 smpi_mpi_win_get_name(win, name, len);
2758 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2759 int retval = MPI_SUCCESS;
2760 if (win == MPI_WIN_NULL) {
2761 retval = MPI_ERR_WIN;
2763 smpi_mpi_win_get_group(win, group);
2769 int PMPI_Win_fence( int assert, MPI_Win win){
2772 if (win == MPI_WIN_NULL) {
2773 retval = MPI_ERR_WIN;
2776 int rank = smpi_process_index();
2777 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2779 retval = smpi_mpi_win_fence(assert, win);
2781 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2789 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2790 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2793 if (win == MPI_WIN_NULL) {
2794 retval = MPI_ERR_WIN;
2795 } else if (target_rank == MPI_PROC_NULL) {
2796 retval = MPI_SUCCESS;
2797 } else if (target_rank <0){
2798 retval = MPI_ERR_RANK;
2799 } else if (target_disp <0){
2800 retval = MPI_ERR_ARG;
2801 } else if (origin_count < 0 || target_count < 0) {
2802 retval = MPI_ERR_COUNT;
2803 } else if (origin_addr==NULL && origin_count > 0){
2804 retval = MPI_ERR_COUNT;
2805 } else if ((!is_datatype_valid(origin_datatype)) ||
2806 (!is_datatype_valid(target_datatype))) {
2807 retval = MPI_ERR_TYPE;
2810 int rank = smpi_process_index();
2812 smpi_mpi_win_get_group(win, &group);
2813 int src_traced = smpi_group_index(group, target_rank);
2814 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2817 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2820 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2827 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2828 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2831 if (win == MPI_WIN_NULL) {
2832 retval = MPI_ERR_WIN;
2833 } else if (target_rank == MPI_PROC_NULL) {
2834 retval = MPI_SUCCESS;
2835 } else if (target_rank <0){
2836 retval = MPI_ERR_RANK;
2837 } else if (target_disp <0){
2838 retval = MPI_ERR_ARG;
2839 } else if (origin_count < 0 || target_count < 0) {
2840 retval = MPI_ERR_COUNT;
2841 } else if (origin_addr==NULL && origin_count > 0){
2842 retval = MPI_ERR_COUNT;
2843 } else if ((!is_datatype_valid(origin_datatype)) ||
2844 (!is_datatype_valid(target_datatype))) {
2845 retval = MPI_ERR_TYPE;
2848 int rank = smpi_process_index();
2850 smpi_mpi_win_get_group(win, &group);
2851 int dst_traced = smpi_group_index(group, target_rank);
2852 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, NULL);
2853 TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2856 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2859 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2868 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2869 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2872 if (win == MPI_WIN_NULL) {
2873 retval = MPI_ERR_WIN;
2874 } else if (target_rank == MPI_PROC_NULL) {
2875 retval = MPI_SUCCESS;
2876 } else if (target_rank <0){
2877 retval = MPI_ERR_RANK;
2878 } else if (target_disp <0){
2879 retval = MPI_ERR_ARG;
2880 } else if (origin_count < 0 || target_count < 0) {
2881 retval = MPI_ERR_COUNT;
2882 } else if (origin_addr==NULL && origin_count > 0){
2883 retval = MPI_ERR_COUNT;
2884 } else if ((!is_datatype_valid(origin_datatype)) ||
2885 (!is_datatype_valid(target_datatype))) {
2886 retval = MPI_ERR_TYPE;
2887 } else if (op == MPI_OP_NULL) {
2888 retval = MPI_ERR_OP;
2891 int rank = smpi_process_index();
2893 smpi_mpi_win_get_group(win, &group);
2894 int src_traced = smpi_group_index(group, target_rank);
2895 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2898 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, op, win);
2901 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2910 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2911 void *ptr = xbt_malloc(size);
2913 return MPI_ERR_NO_MEM;
2915 *(void **)baseptr = ptr;
2920 int PMPI_Free_mem(void *baseptr){
2925 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2928 if (datatype == MPI_DATATYPE_NULL) {
2929 retval = MPI_ERR_TYPE;
2930 } else if (name == NULL) {
2931 retval = MPI_ERR_ARG;
2933 smpi_datatype_set_name(datatype, name);
2934 retval = MPI_SUCCESS;
2939 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2943 if (datatype == MPI_DATATYPE_NULL) {
2944 retval = MPI_ERR_TYPE;
2945 } else if (name == NULL) {
2946 retval = MPI_ERR_ARG;
2948 smpi_datatype_get_name(datatype, name, len);
2949 retval = MPI_SUCCESS;
2955 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2956 return smpi_type_f2c(datatype);
2959 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2960 return smpi_type_c2f( datatype);
2963 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2964 return smpi_group_f2c( group);
2967 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2968 return smpi_group_c2f(group);
2971 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2972 return smpi_request_f2c(request);
2975 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2976 return smpi_request_c2f(request);
2979 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2980 return smpi_win_f2c(win);
2983 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2984 return smpi_win_c2f(win);
2987 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2988 return smpi_op_f2c(op);
2991 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2992 return smpi_op_c2f(op);
2995 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2996 return smpi_comm_f2c(comm);
2999 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
3000 return smpi_comm_c2f(comm);
3003 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3004 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3007 int PMPI_Keyval_free(int* keyval) {
3008 return smpi_comm_keyval_free(keyval);
3011 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3012 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3013 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3014 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3016 else if (comm==MPI_COMM_NULL)
3017 return MPI_ERR_COMM;
3019 return smpi_comm_attr_delete(comm, keyval);
3022 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3023 if (comm==MPI_COMM_NULL){
3025 return MPI_ERR_COMM;
3026 } else if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3027 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3028 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE){
3030 //FIXME : not ideal and leaky, but should not be called too much
3031 int* res = xbt_new(int, 1);
3033 *(int**)attr_value=res;
3036 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3039 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3040 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3041 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3042 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3044 else if (comm==MPI_COMM_NULL)
3045 return MPI_ERR_COMM;
3047 return smpi_comm_attr_put(comm, keyval, attr_value);
3050 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3052 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3055 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3057 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3060 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3062 return PMPI_Attr_delete(comm, comm_keyval);
3065 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3067 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3070 int PMPI_Comm_free_keyval(int* keyval) {
3071 return PMPI_Keyval_free(keyval);
3075 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3077 if (type==MPI_DATATYPE_NULL)
3078 return MPI_ERR_TYPE;
3080 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3083 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3085 if (type==MPI_DATATYPE_NULL)
3086 return MPI_ERR_TYPE;
3088 return smpi_type_attr_put(type, type_keyval, attribute_val);
3091 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3093 if (type==MPI_DATATYPE_NULL)
3094 return MPI_ERR_TYPE;
3096 return smpi_type_attr_delete(type, type_keyval);
3099 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3101 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3104 int PMPI_Type_free_keyval(int* keyval) {
3105 return smpi_type_keyval_free(keyval);
3108 int PMPI_Info_create( MPI_Info *info){
3111 *info = xbt_new(s_smpi_mpi_info_t, 1);
3112 (*info)->info_dict= xbt_dict_new_homogeneous(NULL);
3116 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3117 if (info == NULL || key == NULL || value == NULL)
3120 xbt_dict_set(info->info_dict, key, (void*)value, NULL);
3124 int PMPI_Info_free( MPI_Info *info){
3125 if (info == NULL || *info==NULL)
3127 xbt_dict_free(&((*info)->info_dict));
3129 *info=MPI_INFO_NULL;
3133 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3134 if (info == NULL || key == NULL || valuelen <0)
3137 return MPI_ERR_INFO_VALUE;
3139 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3141 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < valuelen) ?
3142 strlen(tmpvalue) + 1 : valuelen);
3148 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3149 if (info == NULL || newinfo==NULL)
3151 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3152 (*newinfo)->info_dict= xbt_dict_new_homogeneous(NULL);
3153 xbt_dict_cursor_t cursor = NULL;
3156 xbt_dict_foreach(info->info_dict,cursor,key,data){
3157 xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
3162 int PMPI_Info_delete(MPI_Info info, char *key){
3164 if (info == NULL || key==NULL)
3167 xbt_dict_remove(info->info_dict, key);
3170 return MPI_ERR_INFO_NOKEY;
3175 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3176 if (info == NULL || nkeys==NULL)
3178 *nkeys=xbt_dict_size(info->info_dict);
3182 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3183 if (info == NULL || key==NULL || n<0 || n> MPI_MAX_INFO_KEY)
3186 xbt_dict_cursor_t cursor = NULL;
3190 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3192 memcpy(key,keyn, strlen(keyn));
3200 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3201 if (info == NULL || key == NULL || valuelen <0)
3204 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3206 *valuelen=strlen(tmpvalue);
3212 /* The following calls are not yet implemented and will fail at runtime. */
3213 /* Once implemented, please move them above this notice. */
3215 #define NOT_YET_IMPLEMENTED { \
3216 XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
3217 return MPI_SUCCESS; \
3221 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3225 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3229 MPI_Errhandler PMPI_Errhandler_f2c(MPI_Fint errhandler){
3233 MPI_Fint PMPI_Errhandler_c2f(MPI_Errhandler errhandler){
3237 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3242 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
3247 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
3251 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
3255 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
3259 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
3263 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
3267 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
3271 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
3275 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
3279 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
3283 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
3287 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
3291 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
3295 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
3299 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
3303 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
3307 int PMPI_Cancel(MPI_Request* request) {
3311 int PMPI_Buffer_attach(void* buffer, int size) {
3315 int PMPI_Buffer_detach(void* buffer, int* size) {
3319 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
3323 int PMPI_Pcontrol(const int level )
3328 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3332 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
3336 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3340 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3344 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3348 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3352 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3356 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3360 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3364 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3368 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3372 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3376 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3380 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3384 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
3388 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
3392 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3398 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
3399 int *num_addresses, int *num_datatypes, int *combiner){
3403 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
3404 int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
3405 MPI_Datatype* array_of_datatypes){
3409 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
3410 int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
3411 int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
3415 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){
3419 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3423 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3424 void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
3429 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3433 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3437 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3441 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3445 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3449 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3453 int PMPI_Add_error_class( int *errorclass){
3457 int PMPI_Add_error_code( int errorclass, int *errorcode){
3461 int PMPI_Add_error_string( int errorcode, char *string){
3465 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3469 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3473 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){
3477 int PMPI_Grequest_complete( MPI_Request request){
3481 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3485 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3489 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3493 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3497 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3501 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3505 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3509 int PMPI_Open_port( MPI_Info info, char *port_name){
3513 int PMPI_Close_port(char *port_name){
3517 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3521 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){
3525 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3526 int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3527 MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3531 int PMPI_Comm_get_parent( MPI_Comm *parent){
3535 int PMPI_Win_complete(MPI_Win win){
3539 int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win) {
3543 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
3547 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
3551 int PMPI_Win_test(MPI_Win win, int *flag){
3555 int PMPI_Win_unlock(int rank, MPI_Win win){
3559 int PMPI_Win_wait(MPI_Win win){