1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u/host.hpp>
10 #include "smpi_mpi_dt_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi)");
14 //this function need to be here because of the calls to smpi_bench
15 void TRACE_smpi_set_category(const char *category)
17 //need to end bench otherwise categories for execution tasks are wrong
19 TRACE_internal_smpi_set_category (category);
20 //begin bench after changing process's category
24 /* PMPI User level calls */
25 extern "C" { // Obviously, the C MPI interface should use the C linkage
27 int PMPI_Init(int *argc, char ***argv)
29 // PMPI_Init is call only one time by only by SMPI process
31 MPI_Initialized(&already_init);
32 if(already_init == 0){
33 smpi_process_init(argc, argv);
34 smpi_process_mark_as_initialized();
35 int rank = smpi_process_index();
36 TRACE_smpi_init(rank);
37 TRACE_smpi_computing_init(rank);
38 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
39 extra->type = TRACING_INIT;
40 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
41 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
53 int rank = smpi_process_index();
54 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
55 extra->type = TRACING_FINALIZE;
56 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
58 smpi_process_finalize();
60 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
61 TRACE_smpi_finalize(smpi_process_index());
62 smpi_process_destroy();
66 int PMPI_Finalized(int* flag)
68 *flag=smpi_process_finalized();
72 int PMPI_Get_version (int *version,int *subversion){
73 *version = MPI_VERSION;
74 *subversion= MPI_SUBVERSION;
78 int PMPI_Get_library_version (char *version,int *len){
80 snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2015",
81 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR);
82 *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
87 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
89 if (provided != nullptr) {
90 *provided = MPI_THREAD_SINGLE;
92 return MPI_Init(argc, argv);
95 int PMPI_Query_thread(int *provided)
97 if (provided == nullptr) {
100 *provided = MPI_THREAD_SINGLE;
105 int PMPI_Is_thread_main(int *flag)
107 if (flag == nullptr) {
110 *flag = smpi_process_index() == 0;
115 int PMPI_Abort(MPI_Comm comm, int errorcode)
118 smpi_process_destroy();
119 // FIXME: should kill all processes in comm instead
120 simcall_process_kill(SIMIX_process_self());
126 return smpi_mpi_wtime();
129 extern double sg_maxmin_precision;
132 return sg_maxmin_precision;
135 int PMPI_Address(void *location, MPI_Aint * address)
137 if (address==nullptr) {
140 *address = reinterpret_cast<MPI_Aint>(location);
145 int PMPI_Get_address(void *location, MPI_Aint * address)
147 return PMPI_Address(location, address);
150 int PMPI_Type_free(MPI_Datatype * datatype)
152 /* Free a predefined datatype is an error according to the standard, and should be checked for */
153 if (*datatype == MPI_DATATYPE_NULL) {
156 smpi_datatype_unuse(*datatype);
161 int PMPI_Type_size(MPI_Datatype datatype, int *size)
163 if (datatype == MPI_DATATYPE_NULL) {
165 } else if (size == nullptr) {
168 *size = static_cast<int>(smpi_datatype_size(datatype));
173 int PMPI_Type_size_x(MPI_Datatype datatype, MPI_Count *size)
175 if (datatype == MPI_DATATYPE_NULL) {
177 } else if (size == nullptr) {
180 *size = static_cast<MPI_Count>(smpi_datatype_size(datatype));
185 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
187 if (datatype == MPI_DATATYPE_NULL) {
189 } else if (lb == nullptr || extent == nullptr) {
192 return smpi_datatype_extent(datatype, lb, extent);
196 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
198 return PMPI_Type_get_extent(datatype, lb, extent);
201 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
203 if (datatype == MPI_DATATYPE_NULL) {
205 } else if (extent == nullptr) {
208 *extent = smpi_datatype_get_extent(datatype);
213 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
215 if (datatype == MPI_DATATYPE_NULL) {
217 } else if (disp == nullptr) {
220 *disp = smpi_datatype_lb(datatype);
225 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
227 if (datatype == MPI_DATATYPE_NULL) {
229 } else if (disp == nullptr) {
232 *disp = smpi_datatype_ub(datatype);
237 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
238 if (datatype == MPI_DATATYPE_NULL) {
241 return smpi_datatype_dup(datatype, newtype);
245 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
247 if (function == nullptr || op == nullptr) {
250 *op = smpi_op_new(function, (commute!=0));
255 int PMPI_Op_free(MPI_Op * op)
259 } else if (*op == MPI_OP_NULL) {
262 smpi_op_destroy(*op);
268 int PMPI_Group_free(MPI_Group * group)
270 if (group == nullptr) {
273 smpi_group_destroy(*group);
274 *group = MPI_GROUP_NULL;
279 int PMPI_Group_size(MPI_Group group, int *size)
281 if (group == MPI_GROUP_NULL) {
282 return MPI_ERR_GROUP;
283 } else if (size == nullptr) {
286 *size = smpi_group_size(group);
291 int PMPI_Group_rank(MPI_Group group, int *rank)
293 if (group == MPI_GROUP_NULL) {
294 return MPI_ERR_GROUP;
295 } else if (rank == nullptr) {
298 *rank = smpi_group_rank(group, smpi_process_index());
303 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
305 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
306 return MPI_ERR_GROUP;
308 for (int i = 0; i < n; i++) {
309 if(ranks1[i]==MPI_PROC_NULL){
310 ranks2[i]=MPI_PROC_NULL;
312 int index = smpi_group_index(group1, ranks1[i]);
313 ranks2[i] = smpi_group_rank(group2, index);
320 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
322 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
323 return MPI_ERR_GROUP;
324 } else if (result == nullptr) {
327 *result = smpi_group_compare(group1, group2);
332 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
335 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
336 return MPI_ERR_GROUP;
337 } else if (newgroup == nullptr) {
340 int size = smpi_group_size(group1);
341 int size2 = smpi_group_size(group2);
342 for (int i = 0; i < size2; i++) {
343 int proc2 = smpi_group_index(group2, i);
344 int proc1 = smpi_group_rank(group1, proc2);
345 if (proc1 == MPI_UNDEFINED) {
350 *newgroup = MPI_GROUP_EMPTY;
352 *newgroup = smpi_group_new(size);
353 size2 = smpi_group_size(group1);
354 for (int i = 0; i < size2; i++) {
355 int proc1 = smpi_group_index(group1, i);
356 smpi_group_set_mapping(*newgroup, proc1, i);
358 for (int i = size2; i < size; i++) {
359 int proc2 = smpi_group_index(group2, i - size2);
360 smpi_group_set_mapping(*newgroup, proc2, i);
367 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
370 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
371 return MPI_ERR_GROUP;
372 } else if (newgroup == nullptr) {
375 int size = smpi_group_size(group2);
376 for (int i = 0; i < size; i++) {
377 int proc2 = smpi_group_index(group2, i);
378 int proc1 = smpi_group_rank(group1, proc2);
379 if (proc1 == MPI_UNDEFINED) {
384 *newgroup = MPI_GROUP_EMPTY;
386 *newgroup = smpi_group_new(size);
388 for (int i = 0; i < smpi_group_size(group2); i++) {
389 int proc2 = smpi_group_index(group2, i);
390 int proc1 = smpi_group_rank(group1, proc2);
391 if (proc1 != MPI_UNDEFINED) {
392 smpi_group_set_mapping(*newgroup, proc2, j);
401 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
403 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
404 return MPI_ERR_GROUP;
405 } else if (newgroup == nullptr) {
408 int size = smpi_group_size(group1);
410 for (int i = 0; i < size2; i++) {
411 int proc1 = smpi_group_index(group1, i);
412 int proc2 = smpi_group_rank(group2, proc1);
413 if (proc2 != MPI_UNDEFINED) {
418 *newgroup = MPI_GROUP_EMPTY;
420 *newgroup = smpi_group_new(size);
421 for (int i = 0; i < size2; i++) {
422 int proc1 = smpi_group_index(group1, i);
423 int proc2 = smpi_group_rank(group2, proc1);
424 if (proc2 == MPI_UNDEFINED) {
425 smpi_group_set_mapping(*newgroup, proc1, i);
433 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
435 if (group == MPI_GROUP_NULL) {
436 return MPI_ERR_GROUP;
437 } else if (newgroup == nullptr) {
440 return smpi_group_incl(group, n, ranks, newgroup);
444 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
446 if (group == MPI_GROUP_NULL) {
447 return MPI_ERR_GROUP;
448 } else if (newgroup == nullptr) {
453 if (group != smpi_comm_group(MPI_COMM_WORLD)
454 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
455 smpi_group_use(group);
456 } else if (n == smpi_group_size(group)) {
457 *newgroup = MPI_GROUP_EMPTY;
459 int oldsize = smpi_group_size(group);
460 int newsize = oldsize - n;
461 *newgroup = smpi_group_new(newsize);
463 int* to_exclude=xbt_new0(int, smpi_group_size(group));
464 for (int i = 0; i < oldsize; i++)
466 for (int i = 0; i < n; i++)
467 to_exclude[ranks[i]]=1;
470 for (int i = 0; i < oldsize; i++) {
471 if(to_exclude[i]==0){
472 int index = smpi_group_index(group, i);
473 smpi_group_set_mapping(*newgroup, index, j);
478 xbt_free(to_exclude);
484 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
486 if (group == MPI_GROUP_NULL) {
487 return MPI_ERR_GROUP;
488 } else if (newgroup == nullptr) {
492 *newgroup = MPI_GROUP_EMPTY;
495 for (int i = 0; i < n; i++) {
496 for (int rank = ranges[i][0]; /* First */
497 rank >= 0 && rank < smpi_group_size(group); /* Last */
500 if(rank == ranges[i][1]){/*already last ?*/
503 rank += ranges[i][2]; /* Stride */
504 if (ranges[i][0] < ranges[i][1]) {
505 if (rank > ranges[i][1])
508 if (rank < ranges[i][1])
514 *newgroup = smpi_group_new(size);
516 for (int i = 0; i < n; i++) {
517 for (int rank = ranges[i][0]; /* First */
518 rank >= 0 && rank < smpi_group_size(group); /* Last */
520 int index = smpi_group_index(group, rank);
521 smpi_group_set_mapping(*newgroup, index, j);
523 if(rank == ranges[i][1]){/*already last ?*/
526 rank += ranges[i][2]; /* Stride */
527 if (ranges[i][0] < ranges[i][1]) {
528 if (rank > ranges[i][1])
531 if (rank < ranges[i][1])
541 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
543 if (group == MPI_GROUP_NULL) {
544 return MPI_ERR_GROUP;
545 } else if (newgroup == nullptr) {
550 if (group != smpi_comm_group(MPI_COMM_WORLD) && group != smpi_comm_group(MPI_COMM_SELF) &&
551 group != MPI_GROUP_EMPTY)
552 smpi_group_use(group);
554 int size = smpi_group_size(group);
555 for (int i = 0; i < n; i++) {
556 for (int rank = ranges[i][0]; /* First */
557 rank >= 0 && rank < smpi_group_size(group); /* Last */
560 if(rank == ranges[i][1]){/*already last ?*/
563 rank += ranges[i][2]; /* Stride */
564 if (ranges[i][0] < ranges[i][1]) {
565 if (rank > ranges[i][1])
568 if (rank < ranges[i][1])
574 *newgroup = MPI_GROUP_EMPTY;
576 *newgroup = smpi_group_new(size);
579 while (newrank < size) {
581 for (int i = 0; i < n; i++) {
582 for (int rank = ranges[i][0]; rank >= 0 && rank < smpi_group_size(group);) {
587 if(rank == ranges[i][1]){/*already last ?*/
590 rank += ranges[i][2]; /* Stride */
591 if (ranges[i][0]<ranges[i][1]){
592 if (rank > ranges[i][1])
595 if (rank < ranges[i][1])
601 int index = smpi_group_index(group, oldrank);
602 smpi_group_set_mapping(*newgroup, index, newrank);
613 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
615 if (comm == MPI_COMM_NULL) {
617 } else if (rank == nullptr) {
620 *rank = smpi_comm_rank(comm);
625 int PMPI_Comm_size(MPI_Comm comm, int *size)
627 if (comm == MPI_COMM_NULL) {
629 } else if (size == nullptr) {
632 *size = smpi_comm_size(comm);
637 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
639 if (comm == MPI_COMM_NULL) {
641 } else if (name == nullptr || len == nullptr) {
644 smpi_comm_get_name(comm, name, len);
649 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
651 if (comm == MPI_COMM_NULL) {
653 } else if (group == nullptr) {
656 *group = smpi_comm_group(comm);
657 if (*group != smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
658 smpi_group_use(*group);
663 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
665 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
667 } else if (result == nullptr) {
670 if (comm1 == comm2) { /* Same communicators means same groups */
673 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
674 if (*result == MPI_IDENT) {
675 *result = MPI_CONGRUENT;
682 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
684 if (comm == MPI_COMM_NULL) {
686 } else if (newcomm == nullptr) {
689 return smpi_comm_dup(comm, newcomm);
693 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
695 if (comm == MPI_COMM_NULL) {
697 } else if (group == MPI_GROUP_NULL) {
698 return MPI_ERR_GROUP;
699 } else if (newcomm == nullptr) {
701 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
702 *newcomm= MPI_COMM_NULL;
705 smpi_group_use(group);
706 *newcomm = smpi_comm_new(group, nullptr);
711 int PMPI_Comm_free(MPI_Comm * comm)
713 if (comm == nullptr) {
715 } else if (*comm == MPI_COMM_NULL) {
718 smpi_comm_destroy(*comm);
719 *comm = MPI_COMM_NULL;
724 int PMPI_Comm_disconnect(MPI_Comm * comm)
726 /* TODO: wait until all communication in comm are done */
727 if (comm == nullptr) {
729 } else if (*comm == MPI_COMM_NULL) {
732 smpi_comm_destroy(*comm);
733 *comm = MPI_COMM_NULL;
738 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
743 if (comm_out == nullptr) {
744 retval = MPI_ERR_ARG;
745 } else if (comm == MPI_COMM_NULL) {
746 retval = MPI_ERR_COMM;
748 *comm_out = smpi_comm_split(comm, color, key);
749 retval = MPI_SUCCESS;
756 int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out)
761 if (comm_out == nullptr) {
762 retval = MPI_ERR_ARG;
763 } else if (comm == MPI_COMM_NULL) {
764 retval = MPI_ERR_COMM;
766 retval = MPI_Comm_create(comm, group, comm_out);
773 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
778 if (request == nullptr) {
779 retval = MPI_ERR_ARG;
780 } else if (comm == MPI_COMM_NULL) {
781 retval = MPI_ERR_COMM;
782 } else if (!is_datatype_valid(datatype)) {
783 retval = MPI_ERR_TYPE;
784 } else if (dst == MPI_PROC_NULL) {
785 retval = MPI_SUCCESS;
787 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
788 retval = MPI_SUCCESS;
791 if (retval != MPI_SUCCESS && request != nullptr)
792 *request = MPI_REQUEST_NULL;
796 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
801 if (request == nullptr) {
802 retval = MPI_ERR_ARG;
803 } else if (comm == MPI_COMM_NULL) {
804 retval = MPI_ERR_COMM;
805 } else if (!is_datatype_valid(datatype)) {
806 retval = MPI_ERR_TYPE;
807 } else if (src == MPI_PROC_NULL) {
808 retval = MPI_SUCCESS;
810 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
811 retval = MPI_SUCCESS;
814 if (retval != MPI_SUCCESS && request != nullptr)
815 *request = MPI_REQUEST_NULL;
819 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
824 if (request == nullptr) {
825 retval = MPI_ERR_ARG;
826 } else if (comm == MPI_COMM_NULL) {
827 retval = MPI_ERR_COMM;
828 } else if (!is_datatype_valid(datatype)) {
829 retval = MPI_ERR_TYPE;
830 } else if (dst == MPI_PROC_NULL) {
831 retval = MPI_SUCCESS;
833 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
834 retval = MPI_SUCCESS;
837 if (retval != MPI_SUCCESS && request != nullptr)
838 *request = MPI_REQUEST_NULL;
842 int PMPI_Start(MPI_Request * request)
847 if (request == nullptr || *request == MPI_REQUEST_NULL) {
848 retval = MPI_ERR_REQUEST;
850 smpi_mpi_start(*request);
851 retval = MPI_SUCCESS;
857 int PMPI_Startall(int count, MPI_Request * requests)
861 if (requests == nullptr) {
862 retval = MPI_ERR_ARG;
864 retval = MPI_SUCCESS;
865 for (int i = 0; i < count; i++) {
866 if(requests[i] == MPI_REQUEST_NULL) {
867 retval = MPI_ERR_REQUEST;
870 if(retval != MPI_ERR_REQUEST) {
871 smpi_mpi_startall(count, requests);
878 int PMPI_Request_free(MPI_Request * request)
883 if (*request == MPI_REQUEST_NULL) {
884 retval = MPI_ERR_ARG;
886 smpi_mpi_request_free(request);
887 retval = MPI_SUCCESS;
893 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
899 if (request == nullptr) {
900 retval = MPI_ERR_ARG;
901 } else if (comm == MPI_COMM_NULL) {
902 retval = MPI_ERR_COMM;
903 } else if (src == MPI_PROC_NULL) {
904 *request = MPI_REQUEST_NULL;
905 retval = MPI_SUCCESS;
906 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
907 retval = MPI_ERR_RANK;
908 } else if ((count < 0) || (buf==nullptr && count > 0)) {
909 retval = MPI_ERR_COUNT;
910 } else if (!is_datatype_valid(datatype)) {
911 retval = MPI_ERR_TYPE;
912 } else if(tag<0 && tag != MPI_ANY_TAG){
913 retval = MPI_ERR_TAG;
916 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
917 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
919 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
920 extra->type = TRACING_IRECV;
921 extra->src = src_traced;
924 extra->datatype1 = encode_datatype(datatype, &known);
925 int dt_size_send = 1;
927 dt_size_send = smpi_datatype_size(datatype);
928 extra->send_size = count*dt_size_send;
929 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
931 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
932 retval = MPI_SUCCESS;
934 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
935 (*request)->recv = 1;
939 if (retval != MPI_SUCCESS && request != nullptr)
940 *request = MPI_REQUEST_NULL;
945 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
950 if (request == nullptr) {
951 retval = MPI_ERR_ARG;
952 } else if (comm == MPI_COMM_NULL) {
953 retval = MPI_ERR_COMM;
954 } else if (dst == MPI_PROC_NULL) {
955 *request = MPI_REQUEST_NULL;
956 retval = MPI_SUCCESS;
957 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
958 retval = MPI_ERR_RANK;
959 } else if ((count < 0) || (buf==nullptr && count > 0)) {
960 retval = MPI_ERR_COUNT;
961 } else if (!is_datatype_valid(datatype)) {
962 retval = MPI_ERR_TYPE;
963 } else if(tag<0 && tag != MPI_ANY_TAG){
964 retval = MPI_ERR_TAG;
966 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
967 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
968 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
969 extra->type = TRACING_ISEND;
971 extra->dst = dst_traced;
973 extra->datatype1 = encode_datatype(datatype, &known);
974 int dt_size_send = 1;
976 dt_size_send = smpi_datatype_size(datatype);
977 extra->send_size = count*dt_size_send;
978 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
979 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
981 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
982 retval = MPI_SUCCESS;
984 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
985 (*request)->send = 1;
989 if (retval != MPI_SUCCESS && request!=nullptr)
990 *request = MPI_REQUEST_NULL;
994 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
999 if (request == nullptr) {
1000 retval = MPI_ERR_ARG;
1001 } else if (comm == MPI_COMM_NULL) {
1002 retval = MPI_ERR_COMM;
1003 } else if (dst == MPI_PROC_NULL) {
1004 *request = MPI_REQUEST_NULL;
1005 retval = MPI_SUCCESS;
1006 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1007 retval = MPI_ERR_RANK;
1008 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
1009 retval = MPI_ERR_COUNT;
1010 } else if (!is_datatype_valid(datatype)) {
1011 retval = MPI_ERR_TYPE;
1012 } else if(tag<0 && tag != MPI_ANY_TAG){
1013 retval = MPI_ERR_TAG;
1015 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1016 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1017 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1018 extra->type = TRACING_ISSEND;
1020 extra->dst = dst_traced;
1022 extra->datatype1 = encode_datatype(datatype, &known);
1023 int dt_size_send = 1;
1025 dt_size_send = smpi_datatype_size(datatype);
1026 extra->send_size = count*dt_size_send;
1027 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1028 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1030 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1031 retval = MPI_SUCCESS;
1033 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1034 (*request)->send = 1;
1038 if (retval != MPI_SUCCESS && request!=nullptr)
1039 *request = MPI_REQUEST_NULL;
1043 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1048 if (comm == MPI_COMM_NULL) {
1049 retval = MPI_ERR_COMM;
1050 } else if (src == MPI_PROC_NULL) {
1051 smpi_empty_status(status);
1052 status->MPI_SOURCE = MPI_PROC_NULL;
1053 retval = MPI_SUCCESS;
1054 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1055 retval = MPI_ERR_RANK;
1056 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1057 retval = MPI_ERR_COUNT;
1058 } else if (!is_datatype_valid(datatype)) {
1059 retval = MPI_ERR_TYPE;
1060 } else if(tag<0 && tag != MPI_ANY_TAG){
1061 retval = MPI_ERR_TAG;
1063 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1064 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1065 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1066 extra->type = TRACING_RECV;
1067 extra->src = src_traced;
1070 extra->datatype1 = encode_datatype(datatype, &known);
1071 int dt_size_send = 1;
1073 dt_size_send = smpi_datatype_size(datatype);
1074 extra->send_size = count * dt_size_send;
1075 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1077 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1078 retval = MPI_SUCCESS;
1080 // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1081 if (status != MPI_STATUS_IGNORE) {
1082 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1083 if (!TRACE_smpi_view_internals()) {
1084 TRACE_smpi_recv(rank, src_traced, rank, tag);
1087 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1094 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1100 if (comm == MPI_COMM_NULL) {
1101 retval = MPI_ERR_COMM;
1102 } else if (dst == MPI_PROC_NULL) {
1103 retval = MPI_SUCCESS;
1104 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1105 retval = MPI_ERR_RANK;
1106 } else if ((count < 0) || (buf == nullptr && count > 0)) {
1107 retval = MPI_ERR_COUNT;
1108 } else if (!is_datatype_valid(datatype)) {
1109 retval = MPI_ERR_TYPE;
1110 } else if(tag < 0 && tag != MPI_ANY_TAG){
1111 retval = MPI_ERR_TAG;
1113 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1114 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1115 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1116 extra->type = TRACING_SEND;
1118 extra->dst = dst_traced;
1120 extra->datatype1 = encode_datatype(datatype, &known);
1121 int dt_size_send = 1;
1123 dt_size_send = smpi_datatype_size(datatype);
1125 extra->send_size = count*dt_size_send;
1126 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1127 if (!TRACE_smpi_view_internals()) {
1128 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1131 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1132 retval = MPI_SUCCESS;
1134 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1141 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1146 if (comm == MPI_COMM_NULL) {
1147 retval = MPI_ERR_COMM;
1148 } else if (dst == MPI_PROC_NULL) {
1149 retval = MPI_SUCCESS;
1150 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1151 retval = MPI_ERR_RANK;
1152 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1153 retval = MPI_ERR_COUNT;
1154 } else if (!is_datatype_valid(datatype)){
1155 retval = MPI_ERR_TYPE;
1156 } else if(tag<0 && tag != MPI_ANY_TAG){
1157 retval = MPI_ERR_TAG;
1159 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1160 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1161 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1162 extra->type = TRACING_SSEND;
1164 extra->dst = dst_traced;
1166 extra->datatype1 = encode_datatype(datatype, &known);
1167 int dt_size_send = 1;
1169 dt_size_send = smpi_datatype_size(datatype);
1171 extra->send_size = count*dt_size_send;
1172 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1173 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1175 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1176 retval = MPI_SUCCESS;
1178 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1185 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1186 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1192 if (comm == MPI_COMM_NULL) {
1193 retval = MPI_ERR_COMM;
1194 } else if (!is_datatype_valid(sendtype) || !is_datatype_valid(recvtype)) {
1195 retval = MPI_ERR_TYPE;
1196 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1197 smpi_empty_status(status);
1198 status->MPI_SOURCE = MPI_PROC_NULL;
1199 retval = MPI_SUCCESS;
1200 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1201 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1202 retval = MPI_ERR_RANK;
1203 } else if ((sendcount < 0 || recvcount<0) ||
1204 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1205 retval = MPI_ERR_COUNT;
1206 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1207 retval = MPI_ERR_TAG;
1210 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1211 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1212 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1213 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1214 extra->type = TRACING_SENDRECV;
1215 extra->src = src_traced;
1216 extra->dst = dst_traced;
1218 extra->datatype1 = encode_datatype(sendtype, &known);
1219 int dt_size_send = 1;
1221 dt_size_send = smpi_datatype_size(sendtype);
1222 extra->send_size = sendcount*dt_size_send;
1223 extra->datatype2 = encode_datatype(recvtype, &known);
1224 int dt_size_recv = 1;
1226 dt_size_recv = smpi_datatype_size(recvtype);
1227 extra->recv_size = recvcount*dt_size_recv;
1229 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1230 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1232 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm,
1234 retval = MPI_SUCCESS;
1236 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1237 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1244 int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1245 MPI_Comm comm, MPI_Status* status)
1248 if (!is_datatype_valid(datatype)) {
1249 return MPI_ERR_TYPE;
1250 } else if (count < 0) {
1251 return MPI_ERR_COUNT;
1253 int size = smpi_datatype_get_extent(datatype) * count;
1254 void* recvbuf = xbt_new0(char, size);
1255 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1256 if(retval==MPI_SUCCESS){
1257 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1265 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1269 if (request == nullptr || flag == nullptr) {
1270 retval = MPI_ERR_ARG;
1271 } else if (*request == MPI_REQUEST_NULL) {
1273 smpi_empty_status(status);
1274 retval = MPI_SUCCESS;
1276 int rank = ((*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1278 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1279 extra->type = TRACING_TEST;
1280 TRACE_smpi_testing_in(rank, extra);
1282 *flag = smpi_mpi_test(request, status);
1284 TRACE_smpi_testing_out(rank);
1285 retval = MPI_SUCCESS;
1291 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1296 if (index == nullptr || flag == nullptr) {
1297 retval = MPI_ERR_ARG;
1299 *flag = smpi_mpi_testany(count, requests, index, status);
1300 retval = MPI_SUCCESS;
1306 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1311 if (flag == nullptr) {
1312 retval = MPI_ERR_ARG;
1314 *flag = smpi_mpi_testall(count, requests, statuses);
1315 retval = MPI_SUCCESS;
1321 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1325 if (status == nullptr) {
1326 retval = MPI_ERR_ARG;
1327 } else if (comm == MPI_COMM_NULL) {
1328 retval = MPI_ERR_COMM;
1329 } else if (source == MPI_PROC_NULL) {
1330 smpi_empty_status(status);
1331 status->MPI_SOURCE = MPI_PROC_NULL;
1332 retval = MPI_SUCCESS;
1334 smpi_mpi_probe(source, tag, comm, status);
1335 retval = MPI_SUCCESS;
1341 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1345 if ((flag == nullptr) || (status == nullptr)) {
1346 retval = MPI_ERR_ARG;
1347 } else if (comm == MPI_COMM_NULL) {
1348 retval = MPI_ERR_COMM;
1349 } else if (source == MPI_PROC_NULL) {
1351 smpi_empty_status(status);
1352 status->MPI_SOURCE = MPI_PROC_NULL;
1353 retval = MPI_SUCCESS;
1355 smpi_mpi_iprobe(source, tag, comm, flag, status);
1356 retval = MPI_SUCCESS;
1362 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1368 smpi_empty_status(status);
1370 if (request == nullptr) {
1371 retval = MPI_ERR_ARG;
1372 } else if (*request == MPI_REQUEST_NULL) {
1373 retval = MPI_SUCCESS;
1376 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1378 int src_traced = (*request)->src;
1379 int dst_traced = (*request)->dst;
1380 int tag_traced= (*request)->tag;
1381 MPI_Comm comm = (*request)->comm;
1382 int is_wait_for_receive = (*request)->recv;
1383 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1384 extra->type = TRACING_WAIT;
1385 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1387 smpi_mpi_wait(request, status);
1388 retval = MPI_SUCCESS;
1390 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1391 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1392 if (is_wait_for_receive) {
1393 if(src_traced==MPI_ANY_SOURCE)
1394 src_traced = (status!=MPI_STATUS_IGNORE) ?
1395 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1397 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1405 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1407 if (index == nullptr)
1411 //save requests information for tracing
1419 savedvalstype* savedvals=nullptr;
1421 savedvals = xbt_new0(savedvalstype, count);
1423 for (int i = 0; i < count; i++) {
1424 MPI_Request req = requests[i]; //already received requests are no longer valid
1426 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1429 int rank_traced = smpi_process_index();
1430 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1431 extra->type = TRACING_WAITANY;
1432 extra->send_size=count;
1433 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1435 *index = smpi_mpi_waitany(count, requests, status);
1437 if(*index!=MPI_UNDEFINED){
1438 int src_traced = savedvals[*index].src;
1439 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1440 int dst_traced = savedvals[*index].dst;
1441 int is_wait_for_receive = savedvals[*index].recv;
1442 if (is_wait_for_receive) {
1443 if(savedvals[*index].src==MPI_ANY_SOURCE)
1444 src_traced = (status != MPI_STATUSES_IGNORE)
1445 ? smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE)
1446 : savedvals[*index].src;
1447 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1449 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1451 xbt_free(savedvals);
1457 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1460 //save information from requests
1469 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1471 for (int i = 0; i < count; i++) {
1472 MPI_Request req = requests[i];
1473 if(req!=MPI_REQUEST_NULL){
1474 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1476 savedvals[i].valid=0;
1479 int rank_traced = smpi_process_index();
1480 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1481 extra->type = TRACING_WAITALL;
1482 extra->send_size=count;
1483 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1485 int retval = smpi_mpi_waitall(count, requests, status);
1487 for (int i = 0; i < count; i++) {
1488 if(savedvals[i].valid){
1489 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1490 int src_traced = savedvals[i].src;
1491 int dst_traced = savedvals[i].dst;
1492 int is_wait_for_receive = savedvals[i].recv;
1493 if (is_wait_for_receive) {
1494 if(src_traced==MPI_ANY_SOURCE)
1495 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1496 smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
1497 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1501 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1502 xbt_free(savedvals);
1508 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1513 if (outcount == nullptr) {
1514 retval = MPI_ERR_ARG;
1516 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1517 retval = MPI_SUCCESS;
1523 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1528 if (outcount == nullptr) {
1529 retval = MPI_ERR_ARG;
1531 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1532 retval = MPI_SUCCESS;
1539 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1545 if (comm == MPI_COMM_NULL) {
1546 retval = MPI_ERR_COMM;
1547 } else if (!is_datatype_valid(datatype)) {
1548 retval = MPI_ERR_ARG;
1550 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1551 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1553 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1554 extra->type = TRACING_BCAST;
1555 extra->root = root_traced;
1557 extra->datatype1 = encode_datatype(datatype, &known);
1558 int dt_size_send = 1;
1560 dt_size_send = smpi_datatype_size(datatype);
1561 extra->send_size = count * dt_size_send;
1562 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1563 if (smpi_comm_size(comm) > 1)
1564 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1565 retval = MPI_SUCCESS;
1567 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1573 int PMPI_Barrier(MPI_Comm comm)
1579 if (comm == MPI_COMM_NULL) {
1580 retval = MPI_ERR_COMM;
1582 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1583 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1584 extra->type = TRACING_BARRIER;
1585 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1587 mpi_coll_barrier_fun(comm);
1588 retval = MPI_SUCCESS;
1590 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1597 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1598 int root, MPI_Comm comm)
1604 if (comm == MPI_COMM_NULL) {
1605 retval = MPI_ERR_COMM;
1606 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1607 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1608 retval = MPI_ERR_TYPE;
1609 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1610 retval = MPI_ERR_COUNT;
1613 char* sendtmpbuf = static_cast<char*>(sendbuf);
1614 int sendtmpcount = sendcount;
1615 MPI_Datatype sendtmptype = sendtype;
1616 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1618 sendtmptype=recvtype;
1620 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1621 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1622 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1623 extra->type = TRACING_GATHER;
1624 extra->root = root_traced;
1626 extra->datatype1 = encode_datatype(sendtmptype, &known);
1627 int dt_size_send = 1;
1629 dt_size_send = smpi_datatype_size(sendtmptype);
1630 extra->send_size = sendtmpcount * dt_size_send;
1631 extra->datatype2 = encode_datatype(recvtype, &known);
1632 int dt_size_recv = 1;
1633 if ((smpi_comm_rank(comm) == root) && known == 0)
1634 dt_size_recv = smpi_datatype_size(recvtype);
1635 extra->recv_size = recvcount * dt_size_recv;
1637 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1639 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1641 retval = MPI_SUCCESS;
1642 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1649 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1650 MPI_Datatype recvtype, int root, MPI_Comm comm)
1656 if (comm == MPI_COMM_NULL) {
1657 retval = MPI_ERR_COMM;
1658 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1659 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1660 retval = MPI_ERR_TYPE;
1661 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1662 retval = MPI_ERR_COUNT;
1663 } else if (recvcounts == nullptr || displs == nullptr) {
1664 retval = MPI_ERR_ARG;
1666 char* sendtmpbuf = static_cast<char*>(sendbuf);
1667 int sendtmpcount = sendcount;
1668 MPI_Datatype sendtmptype = sendtype;
1669 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1671 sendtmptype=recvtype;
1674 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1675 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1677 int size = smpi_comm_size(comm);
1678 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1679 extra->type = TRACING_GATHERV;
1680 extra->num_processes = size;
1681 extra->root = root_traced;
1683 extra->datatype1 = encode_datatype(sendtmptype, &known);
1684 int dt_size_send = 1;
1686 dt_size_send = smpi_datatype_size(sendtype);
1687 extra->send_size = sendtmpcount * dt_size_send;
1688 extra->datatype2 = encode_datatype(recvtype, &known);
1689 int dt_size_recv = 1;
1691 dt_size_recv = smpi_datatype_size(recvtype);
1692 if ((smpi_comm_rank(comm) == root)) {
1693 extra->recvcounts = xbt_new(int, size);
1694 for (i = 0; i < size; i++) // copy data to avoid bad free
1695 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
1697 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1699 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1700 retval = MPI_SUCCESS;
1701 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1708 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1709 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1715 if (comm == MPI_COMM_NULL) {
1716 retval = MPI_ERR_COMM;
1717 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1718 (recvtype == MPI_DATATYPE_NULL)){
1719 retval = MPI_ERR_TYPE;
1720 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1722 retval = MPI_ERR_COUNT;
1724 if(sendbuf == MPI_IN_PLACE) {
1725 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1726 sendcount=recvcount;
1729 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1730 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1731 extra->type = TRACING_ALLGATHER;
1733 extra->datatype1 = encode_datatype(sendtype, &known);
1734 int dt_size_send = 1;
1736 dt_size_send = smpi_datatype_size(sendtype);
1737 extra->send_size = sendcount * dt_size_send;
1738 extra->datatype2 = encode_datatype(recvtype, &known);
1739 int dt_size_recv = 1;
1741 dt_size_recv = smpi_datatype_size(recvtype);
1742 extra->recv_size = recvcount * dt_size_recv;
1744 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1746 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1747 retval = MPI_SUCCESS;
1748 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1754 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1755 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1761 if (comm == MPI_COMM_NULL) {
1762 retval = MPI_ERR_COMM;
1763 } else if (((sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) || (recvtype == MPI_DATATYPE_NULL)) {
1764 retval = MPI_ERR_TYPE;
1765 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1766 retval = MPI_ERR_COUNT;
1767 } else if (recvcounts == nullptr || displs == nullptr) {
1768 retval = MPI_ERR_ARG;
1771 if(sendbuf == MPI_IN_PLACE) {
1772 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1773 sendcount=recvcounts[smpi_comm_rank(comm)];
1776 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1778 int size = smpi_comm_size(comm);
1779 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1780 extra->type = TRACING_ALLGATHERV;
1781 extra->num_processes = size;
1783 extra->datatype1 = encode_datatype(sendtype, &known);
1784 int dt_size_send = 1;
1786 dt_size_send = smpi_datatype_size(sendtype);
1787 extra->send_size = sendcount * dt_size_send;
1788 extra->datatype2 = encode_datatype(recvtype, &known);
1789 int dt_size_recv = 1;
1791 dt_size_recv = smpi_datatype_size(recvtype);
1792 extra->recvcounts = xbt_new(int, size);
1793 for (i = 0; i < size; i++) // copy data to avoid bad free
1794 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
1796 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1798 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1799 retval = MPI_SUCCESS;
1800 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1807 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1808 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1814 if (comm == MPI_COMM_NULL) {
1815 retval = MPI_ERR_COMM;
1816 } else if (((smpi_comm_rank(comm) == root) && (!is_datatype_valid(sendtype))) ||
1817 ((recvbuf != MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))) {
1818 retval = MPI_ERR_TYPE;
1819 } else if ((sendbuf == recvbuf) ||
1820 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1821 retval = MPI_ERR_BUFFER;
1824 if (recvbuf == MPI_IN_PLACE) {
1825 recvtype = sendtype;
1826 recvcount = sendcount;
1828 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1829 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1830 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1831 extra->type = TRACING_SCATTER;
1832 extra->root = root_traced;
1834 extra->datatype1 = encode_datatype(sendtype, &known);
1835 int dt_size_send = 1;
1836 if ((smpi_comm_rank(comm) == root) && known == 0)
1837 dt_size_send = smpi_datatype_size(sendtype);
1838 extra->send_size = sendcount * dt_size_send;
1839 extra->datatype2 = encode_datatype(recvtype, &known);
1840 int dt_size_recv = 1;
1842 dt_size_recv = smpi_datatype_size(recvtype);
1843 extra->recv_size = recvcount * dt_size_recv;
1844 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1846 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1847 retval = MPI_SUCCESS;
1848 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1855 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1856 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1862 if (comm == MPI_COMM_NULL) {
1863 retval = MPI_ERR_COMM;
1864 } else if (sendcounts == nullptr || displs == nullptr) {
1865 retval = MPI_ERR_ARG;
1866 } else if (((smpi_comm_rank(comm) == root) && (sendtype == MPI_DATATYPE_NULL)) ||
1867 ((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1868 retval = MPI_ERR_TYPE;
1870 if (recvbuf == MPI_IN_PLACE) {
1871 recvtype = sendtype;
1872 recvcount = sendcounts[smpi_comm_rank(comm)];
1874 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1875 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1877 int size = smpi_comm_size(comm);
1878 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1879 extra->type = TRACING_SCATTERV;
1880 extra->num_processes = size;
1881 extra->root = root_traced;
1883 extra->datatype1 = encode_datatype(sendtype, &known);
1884 int dt_size_send = 1;
1886 dt_size_send = smpi_datatype_size(sendtype);
1887 if ((smpi_comm_rank(comm) == root)) {
1888 extra->sendcounts = xbt_new(int, size);
1889 for (i = 0; i < size; i++) // copy data to avoid bad free
1890 extra->sendcounts[i] = sendcounts[i] * dt_size_send;
1892 extra->datatype2 = encode_datatype(recvtype, &known);
1893 int dt_size_recv = 1;
1895 dt_size_recv = smpi_datatype_size(recvtype);
1896 extra->recv_size = recvcount * dt_size_recv;
1897 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1899 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1901 retval = MPI_SUCCESS;
1902 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1909 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1915 if (comm == MPI_COMM_NULL) {
1916 retval = MPI_ERR_COMM;
1917 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1918 retval = MPI_ERR_ARG;
1920 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1921 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1922 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1923 extra->type = TRACING_REDUCE;
1925 extra->datatype1 = encode_datatype(datatype, &known);
1926 int dt_size_send = 1;
1928 dt_size_send = smpi_datatype_size(datatype);
1929 extra->send_size = count * dt_size_send;
1930 extra->root = root_traced;
1932 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1934 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
1936 retval = MPI_SUCCESS;
1937 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1944 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
1948 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1949 retval = MPI_ERR_ARG;
1951 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
1952 retval = MPI_SUCCESS;
1958 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1964 if (comm == MPI_COMM_NULL) {
1965 retval = MPI_ERR_COMM;
1966 } else if (!is_datatype_valid(datatype)) {
1967 retval = MPI_ERR_TYPE;
1968 } else if (op == MPI_OP_NULL) {
1969 retval = MPI_ERR_OP;
1972 char* sendtmpbuf = static_cast<char*>(sendbuf);
1973 if( sendbuf == MPI_IN_PLACE ) {
1974 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
1975 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
1977 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1978 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1979 extra->type = TRACING_ALLREDUCE;
1981 extra->datatype1 = encode_datatype(datatype, &known);
1982 int dt_size_send = 1;
1984 dt_size_send = smpi_datatype_size(datatype);
1985 extra->send_size = count * dt_size_send;
1987 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1989 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
1991 if( sendbuf == MPI_IN_PLACE )
1992 xbt_free(sendtmpbuf);
1994 retval = MPI_SUCCESS;
1995 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2002 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2008 if (comm == MPI_COMM_NULL) {
2009 retval = MPI_ERR_COMM;
2010 } else if (!is_datatype_valid(datatype)) {
2011 retval = MPI_ERR_TYPE;
2012 } else if (op == MPI_OP_NULL) {
2013 retval = MPI_ERR_OP;
2015 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2016 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2017 extra->type = TRACING_SCAN;
2019 extra->datatype1 = encode_datatype(datatype, &known);
2020 int dt_size_send = 1;
2022 dt_size_send = smpi_datatype_size(datatype);
2023 extra->send_size = count * dt_size_send;
2025 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2027 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2029 retval = MPI_SUCCESS;
2030 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2037 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2042 if (comm == MPI_COMM_NULL) {
2043 retval = MPI_ERR_COMM;
2044 } else if (!is_datatype_valid(datatype)) {
2045 retval = MPI_ERR_TYPE;
2046 } else if (op == MPI_OP_NULL) {
2047 retval = MPI_ERR_OP;
2049 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2050 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2051 extra->type = TRACING_EXSCAN;
2053 extra->datatype1 = encode_datatype(datatype, &known);
2054 int dt_size_send = 1;
2056 dt_size_send = smpi_datatype_size(datatype);
2057 extra->send_size = count * dt_size_send;
2058 void* sendtmpbuf = sendbuf;
2059 if (sendbuf == MPI_IN_PLACE) {
2060 sendtmpbuf = static_cast<void*>(xbt_malloc(count * smpi_datatype_size(datatype)));
2061 memcpy(sendtmpbuf, recvbuf, count * smpi_datatype_size(datatype));
2063 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2065 smpi_mpi_exscan(sendtmpbuf, recvbuf, count, datatype, op, comm);
2066 retval = MPI_SUCCESS;
2067 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2068 if (sendbuf == MPI_IN_PLACE)
2069 xbt_free(sendtmpbuf);
2076 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2081 if (comm == MPI_COMM_NULL) {
2082 retval = MPI_ERR_COMM;
2083 } else if (!is_datatype_valid(datatype)) {
2084 retval = MPI_ERR_TYPE;
2085 } else if (op == MPI_OP_NULL) {
2086 retval = MPI_ERR_OP;
2087 } else if (recvcounts == nullptr) {
2088 retval = MPI_ERR_ARG;
2090 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2092 int size = smpi_comm_size(comm);
2093 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2094 extra->type = TRACING_REDUCE_SCATTER;
2095 extra->num_processes = size;
2097 extra->datatype1 = encode_datatype(datatype, &known);
2098 int dt_size_send = 1;
2100 dt_size_send = smpi_datatype_size(datatype);
2101 extra->send_size = 0;
2102 extra->recvcounts = xbt_new(int, size);
2104 for (i = 0; i < size; i++) { // copy data to avoid bad free
2105 extra->recvcounts[i] = recvcounts[i] * dt_size_send;
2106 totalcount += recvcounts[i];
2108 void* sendtmpbuf = sendbuf;
2109 if (sendbuf == MPI_IN_PLACE) {
2110 sendtmpbuf = static_cast<void*>(xbt_malloc(totalcount * smpi_datatype_size(datatype)));
2111 memcpy(sendtmpbuf, recvbuf, totalcount * smpi_datatype_size(datatype));
2114 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2116 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2117 retval = MPI_SUCCESS;
2118 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2120 if (sendbuf == MPI_IN_PLACE)
2121 xbt_free(sendtmpbuf);
2128 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2129 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2134 if (comm == MPI_COMM_NULL) {
2135 retval = MPI_ERR_COMM;
2136 } else if (!is_datatype_valid(datatype)) {
2137 retval = MPI_ERR_TYPE;
2138 } else if (op == MPI_OP_NULL) {
2139 retval = MPI_ERR_OP;
2140 } else if (recvcount < 0) {
2141 retval = MPI_ERR_ARG;
2143 int count = smpi_comm_size(comm);
2145 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2146 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2147 extra->type = TRACING_REDUCE_SCATTER;
2148 extra->num_processes = count;
2150 extra->datatype1 = encode_datatype(datatype, &known);
2151 int dt_size_send = 1;
2153 dt_size_send = smpi_datatype_size(datatype);
2154 extra->send_size = 0;
2155 extra->recvcounts = xbt_new(int, count);
2156 for (int i = 0; i < count; i++) // copy data to avoid bad free
2157 extra->recvcounts[i] = recvcount * dt_size_send;
2158 void* sendtmpbuf = sendbuf;
2159 if (sendbuf == MPI_IN_PLACE) {
2160 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount * count * smpi_datatype_size(datatype)));
2161 memcpy(sendtmpbuf, recvbuf, recvcount * count * smpi_datatype_size(datatype));
2164 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2166 int* recvcounts = static_cast<int*>(xbt_malloc(count * sizeof(int)));
2167 for (int i = 0; i < count; i++)
2168 recvcounts[i] = recvcount;
2169 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2170 xbt_free(recvcounts);
2171 retval = MPI_SUCCESS;
2173 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2175 if (sendbuf == MPI_IN_PLACE)
2176 xbt_free(sendtmpbuf);
2183 int PMPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
2184 MPI_Datatype recvtype, MPI_Comm comm)
2189 if (comm == MPI_COMM_NULL) {
2190 retval = MPI_ERR_COMM;
2191 } else if ((sendbuf != MPI_IN_PLACE && sendtype == MPI_DATATYPE_NULL) || recvtype == MPI_DATATYPE_NULL) {
2192 retval = MPI_ERR_TYPE;
2194 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2195 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2196 extra->type = TRACING_ALLTOALL;
2198 void* sendtmpbuf = static_cast<char*>(sendbuf);
2199 int sendtmpcount = sendcount;
2200 MPI_Datatype sendtmptype = sendtype;
2201 if (sendbuf == MPI_IN_PLACE) {
2202 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount * smpi_comm_size(comm) * smpi_datatype_size(recvtype)));
2203 memcpy(sendtmpbuf, recvbuf, recvcount * smpi_comm_size(comm) * smpi_datatype_size(recvtype));
2204 sendtmpcount = recvcount;
2205 sendtmptype = recvtype;
2209 extra->datatype1 = encode_datatype(sendtmptype, &known);
2211 extra->send_size = sendtmpcount * smpi_datatype_size(sendtmptype);
2213 extra->send_size = sendtmpcount;
2214 extra->datatype2 = encode_datatype(recvtype, &known);
2216 extra->recv_size = recvcount * smpi_datatype_size(recvtype);
2218 extra->recv_size = recvcount;
2220 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2222 retval = mpi_coll_alltoall_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, comm);
2224 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2226 if (sendbuf == MPI_IN_PLACE)
2227 xbt_free(sendtmpbuf);
2234 int PMPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf,
2235 int* recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2241 if (comm == MPI_COMM_NULL) {
2242 retval = MPI_ERR_COMM;
2243 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2244 retval = MPI_ERR_TYPE;
2245 } else if ((sendbuf != MPI_IN_PLACE && (sendcounts == nullptr || senddisps == nullptr)) || recvcounts == nullptr ||
2246 recvdisps == nullptr) {
2247 retval = MPI_ERR_ARG;
2249 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2251 int size = smpi_comm_size(comm);
2252 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2253 extra->type = TRACING_ALLTOALLV;
2254 extra->send_size = 0;
2255 extra->recv_size = 0;
2256 extra->recvcounts = xbt_new(int, size);
2257 extra->sendcounts = xbt_new(int, size);
2259 int dt_size_recv = 1;
2260 extra->datatype2 = encode_datatype(recvtype, &known);
2261 dt_size_recv = smpi_datatype_size(recvtype);
2263 void* sendtmpbuf = static_cast<char*>(sendbuf);
2264 int* sendtmpcounts = sendcounts;
2265 int* sendtmpdisps = senddisps;
2266 MPI_Datatype sendtmptype = sendtype;
2268 for (i = 0; i < size; i++) { // copy data to avoid bad free
2269 extra->recv_size += recvcounts[i] * dt_size_recv;
2270 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
2271 if (((recvdisps[i] + recvcounts[i]) * dt_size_recv) > maxsize)
2272 maxsize = (recvdisps[i] + recvcounts[i]) * dt_size_recv;
2275 if (sendbuf == MPI_IN_PLACE) {
2276 sendtmpbuf = static_cast<void*>(xbt_malloc(maxsize));
2277 memcpy(sendtmpbuf, recvbuf, maxsize);
2278 sendtmpcounts = static_cast<int*>(xbt_malloc(size * sizeof(int)));
2279 memcpy(sendtmpcounts, recvcounts, size * sizeof(int));
2280 sendtmpdisps = static_cast<int*>(xbt_malloc(size * sizeof(int)));
2281 memcpy(sendtmpdisps, recvdisps, size * sizeof(int));
2282 sendtmptype = recvtype;
2285 extra->datatype1 = encode_datatype(sendtmptype, &known);
2286 int dt_size_send = 1;
2287 dt_size_send = smpi_datatype_size(sendtmptype);
2289 for (i = 0; i < size; i++) { // copy data to avoid bad free
2290 extra->send_size += sendtmpcounts[i] * dt_size_send;
2291 extra->sendcounts[i] = sendtmpcounts[i] * dt_size_send;
2293 extra->num_processes = size;
2294 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2295 retval = mpi_coll_alltoallv_fun(sendtmpbuf, sendtmpcounts, sendtmpdisps, sendtmptype, recvbuf, recvcounts,
2296 recvdisps, recvtype, comm);
2297 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2299 if (sendbuf == MPI_IN_PLACE) {
2300 xbt_free(sendtmpbuf);
2301 xbt_free(sendtmpcounts);
2302 xbt_free(sendtmpdisps);
2311 int PMPI_Get_processor_name(char *name, int *resultlen)
2313 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2314 ? strlen(SIMIX_host_self()->cname()) + 1
2315 : MPI_MAX_PROCESSOR_NAME - 1);
2316 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2321 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2323 if (status == nullptr || count == nullptr) {
2325 } else if (!is_datatype_valid(datatype)) {
2326 return MPI_ERR_TYPE;
2328 size_t size = smpi_datatype_size(datatype);
2332 } else if (status->count % size != 0) {
2333 return MPI_UNDEFINED;
2335 *count = smpi_mpi_get_count(status, datatype);
2341 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2342 if (old_type == MPI_DATATYPE_NULL) {
2343 return MPI_ERR_TYPE;
2344 } else if (count<0){
2345 return MPI_ERR_COUNT;
2347 return smpi_datatype_contiguous(count, old_type, new_type, 0);
2351 int PMPI_Type_commit(MPI_Datatype* datatype) {
2352 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2353 return MPI_ERR_TYPE;
2355 smpi_datatype_commit(datatype);
2360 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2361 if (old_type == MPI_DATATYPE_NULL) {
2362 return MPI_ERR_TYPE;
2363 } else if (count<0 || blocklen<0){
2364 return MPI_ERR_COUNT;
2366 return smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2370 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2371 if (old_type == MPI_DATATYPE_NULL) {
2372 return MPI_ERR_TYPE;
2373 } else if (count<0 || blocklen<0){
2374 return MPI_ERR_COUNT;
2376 return smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2380 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2381 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2384 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2385 if (old_type == MPI_DATATYPE_NULL) {
2386 return MPI_ERR_TYPE;
2387 } else if (count<0){
2388 return MPI_ERR_COUNT;
2390 return smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2394 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2395 if (old_type == MPI_DATATYPE_NULL) {
2396 return MPI_ERR_TYPE;
2397 } else if (count<0){
2398 return MPI_ERR_COUNT;
2400 return smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2404 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2405 MPI_Datatype* new_type)
2407 if (old_type == MPI_DATATYPE_NULL) {
2408 return MPI_ERR_TYPE;
2409 } else if (count<0){
2410 return MPI_ERR_COUNT;
2412 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count*sizeof(int)));
2413 for (int i = 0; i < count; i++)
2414 blocklens[i]=blocklength;
2415 int retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2416 xbt_free(blocklens);
2421 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
2423 if (old_type == MPI_DATATYPE_NULL) {
2424 return MPI_ERR_TYPE;
2425 } else if (count<0){
2426 return MPI_ERR_COUNT;
2428 return smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2432 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2433 MPI_Datatype* new_type) {
2434 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2437 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2438 MPI_Datatype* new_type) {
2439 if (old_type == MPI_DATATYPE_NULL) {
2440 return MPI_ERR_TYPE;
2441 } else if (count<0){
2442 return MPI_ERR_COUNT;
2444 int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int));
2445 for (int i = 0; i < count; i++)
2446 blocklens[i] = blocklength;
2447 int retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2448 xbt_free(blocklens);
2453 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2455 return MPI_ERR_COUNT;
2457 return smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2461 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2462 MPI_Datatype* new_type) {
2463 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2466 int PMPI_Error_class(int errorcode, int* errorclass) {
2467 // assume smpi uses only standard mpi error codes
2468 *errorclass=errorcode;
2472 int PMPI_Initialized(int* flag) {
2473 *flag=smpi_process_initialized();
2477 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2478 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2479 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2481 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2482 if (comm_old == MPI_COMM_NULL){
2483 return MPI_ERR_COMM;
2484 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2487 return smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2491 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2492 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2493 return MPI_ERR_TOPOLOGY;
2495 if (coords == nullptr) {
2498 return smpi_mpi_cart_rank(comm, coords, rank);
2501 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2502 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2503 return MPI_ERR_TOPOLOGY;
2505 if (source == nullptr || dest == nullptr || direction < 0 ) {
2508 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2511 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2512 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2513 return MPI_ERR_TOPOLOGY;
2515 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2516 return MPI_ERR_RANK;
2521 if(coords == nullptr) {
2524 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2527 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2528 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2529 return MPI_ERR_TOPOLOGY;
2531 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2534 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2537 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2538 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2539 return MPI_ERR_TOPOLOGY;
2541 if (ndims == nullptr) {
2544 return smpi_mpi_cartdim_get(comm, ndims);
2547 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2548 if(dims == nullptr) {
2551 if (ndims < 1 || nnodes < 1) {
2552 return MPI_ERR_DIMS;
2555 return smpi_mpi_dims_create(nnodes, ndims, dims);
2558 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2559 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2560 return MPI_ERR_TOPOLOGY;
2562 if (comm_new == nullptr) {
2565 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2568 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2569 if (oldtype == MPI_DATATYPE_NULL) {
2570 return MPI_ERR_TYPE;
2572 int blocks[3] = {1, 1, 1};
2573 MPI_Aint disps[3] = {lb, 0, lb + extent};
2574 MPI_Datatype types[3] = {MPI_LB, oldtype, MPI_UB};
2576 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create(blocks, disps, 3, types);
2577 smpi_datatype_create(newtype, oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t), subtype, DT_FLAG_VECTOR);
2579 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2583 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2586 if (comm == MPI_COMM_NULL) {
2587 retval= MPI_ERR_COMM;
2588 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2589 retval= MPI_ERR_OTHER;
2591 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2592 retval = MPI_SUCCESS;
2598 int PMPI_Win_free( MPI_Win* win){
2601 if (win == nullptr || *win == MPI_WIN_NULL) {
2602 retval = MPI_ERR_WIN;
2604 retval=smpi_mpi_win_free(win);
2610 int PMPI_Win_set_name(MPI_Win win, char * name)
2612 if (win == MPI_WIN_NULL) {
2613 return MPI_ERR_TYPE;
2614 } else if (name == nullptr) {
2617 smpi_mpi_win_set_name(win, name);
2622 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2624 if (win == MPI_WIN_NULL) {
2626 } else if (name == nullptr) {
2629 smpi_mpi_win_get_name(win, name, len);
2634 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2635 if (win == MPI_WIN_NULL) {
2638 smpi_mpi_win_get_group(win, group);
2639 smpi_group_use(*group);
2644 int PMPI_Win_fence( int assert, MPI_Win win){
2647 if (win == MPI_WIN_NULL) {
2648 retval = MPI_ERR_WIN;
2650 int rank = smpi_process_index();
2651 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2652 retval = smpi_mpi_win_fence(assert, win);
2653 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2659 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2660 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2663 if (win == MPI_WIN_NULL) {
2664 retval = MPI_ERR_WIN;
2665 } else if (target_rank == MPI_PROC_NULL) {
2666 retval = MPI_SUCCESS;
2667 } else if (target_rank <0){
2668 retval = MPI_ERR_RANK;
2669 } else if (target_disp <0){
2670 retval = MPI_ERR_ARG;
2671 } else if ((origin_count < 0 || target_count < 0) ||
2672 (origin_addr==nullptr && origin_count > 0)){
2673 retval = MPI_ERR_COUNT;
2674 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2675 retval = MPI_ERR_TYPE;
2677 int rank = smpi_process_index();
2679 smpi_mpi_win_get_group(win, &group);
2680 int src_traced = smpi_group_index(group, target_rank);
2681 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2683 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2684 target_datatype, win);
2686 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2692 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2693 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2696 if (win == MPI_WIN_NULL) {
2697 retval = MPI_ERR_WIN;
2698 } else if (target_rank == MPI_PROC_NULL) {
2699 retval = MPI_SUCCESS;
2700 } else if (target_rank <0){
2701 retval = MPI_ERR_RANK;
2702 } else if (target_disp <0){
2703 retval = MPI_ERR_ARG;
2704 } else if ((origin_count < 0 || target_count < 0) ||
2705 (origin_addr==nullptr && origin_count > 0)){
2706 retval = MPI_ERR_COUNT;
2707 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2708 retval = MPI_ERR_TYPE;
2710 int rank = smpi_process_index();
2712 smpi_mpi_win_get_group(win, &group);
2713 int dst_traced = smpi_group_index(group, target_rank);
2714 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2715 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2717 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2718 target_datatype, win);
2720 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2726 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2727 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2730 if (win == MPI_WIN_NULL) {
2731 retval = MPI_ERR_WIN;
2732 } else if (target_rank == MPI_PROC_NULL) {
2733 retval = MPI_SUCCESS;
2734 } else if (target_rank <0){
2735 retval = MPI_ERR_RANK;
2736 } else if (target_disp <0){
2737 retval = MPI_ERR_ARG;
2738 } else if ((origin_count < 0 || target_count < 0) ||
2739 (origin_addr==nullptr && origin_count > 0)){
2740 retval = MPI_ERR_COUNT;
2741 } else if ((!is_datatype_valid(origin_datatype)) ||
2742 (!is_datatype_valid(target_datatype))) {
2743 retval = MPI_ERR_TYPE;
2744 } else if (op == MPI_OP_NULL) {
2745 retval = MPI_ERR_OP;
2747 int rank = smpi_process_index();
2749 smpi_mpi_win_get_group(win, &group);
2750 int src_traced = smpi_group_index(group, target_rank);
2751 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2753 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2754 target_datatype, op, win);
2756 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2762 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2765 if (win == MPI_WIN_NULL) {
2766 retval = MPI_ERR_WIN;
2767 } else if (group==MPI_GROUP_NULL){
2768 retval = MPI_ERR_GROUP;
2770 int rank = smpi_process_index();
2771 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2772 retval = smpi_mpi_win_post(group,assert,win);
2773 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2779 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2782 if (win == MPI_WIN_NULL) {
2783 retval = MPI_ERR_WIN;
2784 } else if (group==MPI_GROUP_NULL){
2785 retval = MPI_ERR_GROUP;
2787 int rank = smpi_process_index();
2788 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2789 retval = smpi_mpi_win_start(group,assert,win);
2790 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2796 int PMPI_Win_complete(MPI_Win win){
2799 if (win == MPI_WIN_NULL) {
2800 retval = MPI_ERR_WIN;
2802 int rank = smpi_process_index();
2803 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2805 retval = smpi_mpi_win_complete(win);
2807 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2813 int PMPI_Win_wait(MPI_Win win){
2816 if (win == MPI_WIN_NULL) {
2817 retval = MPI_ERR_WIN;
2819 int rank = smpi_process_index();
2820 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2822 retval = smpi_mpi_win_wait(win);
2824 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2830 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2831 void *ptr = xbt_malloc(size);
2833 return MPI_ERR_NO_MEM;
2835 *static_cast<void**>(baseptr) = ptr;
2840 int PMPI_Free_mem(void *baseptr){
2845 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2847 if (datatype == MPI_DATATYPE_NULL) {
2848 return MPI_ERR_TYPE;
2849 } else if (name == nullptr) {
2852 smpi_datatype_set_name(datatype, name);
2857 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2859 if (datatype == MPI_DATATYPE_NULL) {
2860 return MPI_ERR_TYPE;
2861 } else if (name == nullptr) {
2864 smpi_datatype_get_name(datatype, name, len);
2869 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2870 return smpi_type_f2c(datatype);
2873 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2874 return smpi_type_c2f( datatype);
2877 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2878 return smpi_group_f2c( group);
2881 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2882 return smpi_group_c2f(group);
2885 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2886 return smpi_request_f2c(request);
2889 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2890 return smpi_request_c2f(request);
2893 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2894 return smpi_win_f2c(win);
2897 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2898 return smpi_win_c2f(win);
2901 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2902 return smpi_op_f2c(op);
2905 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2906 return smpi_op_c2f(op);
2909 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2910 return smpi_comm_f2c(comm);
2913 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2914 return smpi_comm_c2f(comm);
2917 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2918 return smpi_info_f2c(info);
2921 MPI_Fint PMPI_Info_c2f(MPI_Info info){
2922 return smpi_info_c2f(info);
2925 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2926 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2929 int PMPI_Keyval_free(int* keyval) {
2930 return smpi_comm_keyval_free(keyval);
2933 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2934 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2935 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2937 else if (comm==MPI_COMM_NULL)
2938 return MPI_ERR_COMM;
2940 return smpi_comm_attr_delete(comm, keyval);
2943 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2945 static int zero = 0;
2946 static int tag_ub = 1000000;
2947 static int last_used_code = MPI_ERR_LASTCODE;
2949 if (comm==MPI_COMM_NULL){
2951 return MPI_ERR_COMM;
2959 *static_cast<int**>(attr_value) = &zero;
2961 case MPI_UNIVERSE_SIZE:
2963 *static_cast<int**>(attr_value) = &smpi_universe_size;
2965 case MPI_LASTUSEDCODE:
2967 *static_cast<int**>(attr_value) = &last_used_code;
2971 *static_cast<int**>(attr_value) = &tag_ub;
2973 case MPI_WTIME_IS_GLOBAL:
2975 *static_cast<int**>(attr_value) = &one;
2978 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
2982 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2983 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2984 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2986 else if (comm==MPI_COMM_NULL)
2987 return MPI_ERR_COMM;
2989 return smpi_comm_attr_put(comm, keyval, attr_value);
2992 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2994 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
2997 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
2999 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3002 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3004 return PMPI_Attr_delete(comm, comm_keyval);
3007 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3010 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3013 int PMPI_Comm_free_keyval(int* keyval) {
3014 return PMPI_Keyval_free(keyval);
3017 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3019 if (type==MPI_DATATYPE_NULL)
3020 return MPI_ERR_TYPE;
3022 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3025 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3027 if (type==MPI_DATATYPE_NULL)
3028 return MPI_ERR_TYPE;
3030 return smpi_type_attr_put(type, type_keyval, attribute_val);
3033 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3035 if (type==MPI_DATATYPE_NULL)
3036 return MPI_ERR_TYPE;
3038 return smpi_type_attr_delete(type, type_keyval);
3041 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3044 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3047 int PMPI_Type_free_keyval(int* keyval) {
3048 return smpi_type_keyval_free(keyval);
3051 int PMPI_Info_create( MPI_Info *info){
3052 if (info == nullptr)
3054 *info = xbt_new(s_smpi_mpi_info_t, 1);
3055 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3056 (*info)->refcount=1;
3060 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3061 if (info == nullptr || key == nullptr || value == nullptr)
3064 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
3068 int PMPI_Info_free( MPI_Info *info){
3069 if (info == nullptr || *info==nullptr)
3071 (*info)->refcount--;
3072 if((*info)->refcount==0){
3073 xbt_dict_free(&((*info)->info_dict));
3076 *info=MPI_INFO_NULL;
3080 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3082 if (info == nullptr || key == nullptr || valuelen <0)
3084 if (value == nullptr)
3085 return MPI_ERR_INFO_VALUE;
3086 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
3088 memset(value, 0, valuelen);
3089 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3095 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3096 if (info == nullptr || newinfo==nullptr)
3098 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3099 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3100 (*newinfo)->refcount=1;
3101 xbt_dict_cursor_t cursor = nullptr;
3104 xbt_dict_foreach(info->info_dict,cursor,key,data){
3105 xbt_dict_set((*newinfo)->info_dict, key, xbt_strdup(static_cast<char*>(data)), nullptr);
3110 int PMPI_Info_delete(MPI_Info info, char *key){
3111 if (info == nullptr || key==nullptr)
3114 xbt_dict_remove(info->info_dict, key);
3117 return MPI_ERR_INFO_NOKEY;
3122 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3123 if (info == nullptr || nkeys==nullptr)
3125 *nkeys=xbt_dict_size(info->info_dict);
3129 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3130 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
3133 xbt_dict_cursor_t cursor = nullptr;
3137 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3139 strncpy(key,keyn,strlen(keyn)+1);
3140 xbt_dict_cursor_free(&cursor);
3148 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3150 if (info == nullptr || key == nullptr || valuelen==nullptr)
3152 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3154 *valuelen=strlen(tmpvalue);
3160 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3161 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3163 if(!is_datatype_valid(type))
3164 return MPI_ERR_TYPE;
3165 if(comm==MPI_COMM_NULL)
3166 return MPI_ERR_COMM;
3167 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3170 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3171 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3173 if(!is_datatype_valid(type))
3174 return MPI_ERR_TYPE;
3175 if(comm==MPI_COMM_NULL)
3176 return MPI_ERR_COMM;
3177 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3180 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3183 if(!is_datatype_valid(datatype))
3184 return MPI_ERR_TYPE;
3185 if(comm==MPI_COMM_NULL)
3186 return MPI_ERR_COMM;
3188 *size=incount*smpi_datatype_size(datatype);