1 /* Copyright (c) 2007-2016. 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 */
26 int PMPI_Init(int *argc, char ***argv)
28 // PMPI_Init is call only one time by only by SMPI process
30 MPI_Initialized(&already_init);
31 if(already_init == 0){
32 smpi_process_init(argc, argv);
33 smpi_process_mark_as_initialized();
34 int rank = smpi_process_index();
35 TRACE_smpi_init(rank);
36 TRACE_smpi_computing_init(rank);
37 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
38 extra->type = TRACING_INIT;
39 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
40 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
52 int rank = smpi_process_index();
53 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
54 extra->type = TRACING_FINALIZE;
55 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
57 smpi_process_finalize();
59 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
60 TRACE_smpi_finalize(smpi_process_index());
61 smpi_process_destroy();
65 int PMPI_Finalized(int* flag)
67 *flag=smpi_process_finalized();
71 int PMPI_Get_version (int *version,int *subversion){
72 *version = MPI_VERSION;
73 *subversion= MPI_SUBVERSION;
77 int PMPI_Get_library_version (char *version,int *len){
78 int retval = MPI_SUCCESS;
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)
99 if (provided == nullptr) {
100 retval = MPI_ERR_ARG;
102 *provided = MPI_THREAD_SINGLE;
103 retval = MPI_SUCCESS;
108 int PMPI_Is_thread_main(int *flag)
112 if (flag == nullptr) {
113 retval = MPI_ERR_ARG;
115 *flag = smpi_process_index() == 0;
116 retval = MPI_SUCCESS;
121 int PMPI_Abort(MPI_Comm comm, int errorcode)
124 smpi_process_destroy();
125 // FIXME: should kill all processes in comm instead
126 simcall_process_kill(SIMIX_process_self());
132 return smpi_mpi_wtime();
135 extern double sg_maxmin_precision;
138 return sg_maxmin_precision;
141 int PMPI_Address(void *location, MPI_Aint * address)
145 if (address==nullptr) {
146 retval = MPI_ERR_ARG;
148 *address = reinterpret_cast<MPI_Aint>(location);
149 retval = MPI_SUCCESS;
154 int PMPI_Get_address(void *location, MPI_Aint * address)
156 return PMPI_Address(location, address);
159 int PMPI_Type_free(MPI_Datatype * datatype)
162 /* Free a predefined datatype is an error according to the standard, and should be checked for */
163 if (*datatype == MPI_DATATYPE_NULL) {
164 retval = MPI_ERR_ARG;
166 smpi_datatype_unuse(*datatype);
167 retval = MPI_SUCCESS;
172 int PMPI_Type_size(MPI_Datatype datatype, int *size)
176 if (datatype == MPI_DATATYPE_NULL) {
177 retval = MPI_ERR_TYPE;
178 } else if (size == nullptr) {
179 retval = MPI_ERR_ARG;
181 *size = static_cast<int>(smpi_datatype_size(datatype));
182 retval = MPI_SUCCESS;
187 int PMPI_Type_size_x(MPI_Datatype datatype, MPI_Count *size)
191 if (datatype == MPI_DATATYPE_NULL) {
192 retval = MPI_ERR_TYPE;
193 } else if (size == nullptr) {
194 retval = MPI_ERR_ARG;
196 *size = static_cast<MPI_Count>(smpi_datatype_size(datatype));
197 retval = MPI_SUCCESS;
202 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
206 if (datatype == MPI_DATATYPE_NULL) {
207 retval = MPI_ERR_TYPE;
208 } else if (lb == nullptr || extent == nullptr) {
209 retval = MPI_ERR_ARG;
211 retval = smpi_datatype_extent(datatype, lb, extent);
216 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
218 return PMPI_Type_get_extent(datatype, lb, extent);
221 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
225 if (datatype == MPI_DATATYPE_NULL) {
226 retval = MPI_ERR_TYPE;
227 } else if (extent == nullptr) {
228 retval = MPI_ERR_ARG;
230 *extent = smpi_datatype_get_extent(datatype);
231 retval = MPI_SUCCESS;
236 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
240 if (datatype == MPI_DATATYPE_NULL) {
241 retval = MPI_ERR_TYPE;
242 } else if (disp == nullptr) {
243 retval = MPI_ERR_ARG;
245 *disp = smpi_datatype_lb(datatype);
246 retval = MPI_SUCCESS;
251 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
255 if (datatype == MPI_DATATYPE_NULL) {
256 retval = MPI_ERR_TYPE;
257 } else if (disp == nullptr) {
258 retval = MPI_ERR_ARG;
260 *disp = smpi_datatype_ub(datatype);
261 retval = MPI_SUCCESS;
266 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
269 if (datatype == MPI_DATATYPE_NULL) {
270 retval = MPI_ERR_TYPE;
272 retval = smpi_datatype_dup(datatype, newtype);
277 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
281 if (function == nullptr || op == nullptr) {
282 retval = MPI_ERR_ARG;
284 *op = smpi_op_new(function, (commute!=0));
285 retval = MPI_SUCCESS;
290 int PMPI_Op_free(MPI_Op * op)
295 retval = MPI_ERR_ARG;
296 } else if (*op == MPI_OP_NULL) {
299 smpi_op_destroy(*op);
301 retval = MPI_SUCCESS;
306 int PMPI_Group_free(MPI_Group * group)
310 if (group == nullptr) {
311 retval = MPI_ERR_ARG;
313 smpi_group_destroy(*group);
314 *group = MPI_GROUP_NULL;
315 retval = MPI_SUCCESS;
320 int PMPI_Group_size(MPI_Group group, int *size)
324 if (group == MPI_GROUP_NULL) {
325 retval = MPI_ERR_GROUP;
326 } else if (size == nullptr) {
327 retval = MPI_ERR_ARG;
329 *size = smpi_group_size(group);
330 retval = MPI_SUCCESS;
335 int PMPI_Group_rank(MPI_Group group, int *rank)
339 if (group == MPI_GROUP_NULL) {
340 retval = MPI_ERR_GROUP;
341 } else if (rank == nullptr) {
342 retval = MPI_ERR_ARG;
344 *rank = smpi_group_rank(group, smpi_process_index());
345 retval = MPI_SUCCESS;
350 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
352 int retval, i, index;
353 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
354 retval = MPI_ERR_GROUP;
356 for (i = 0; i < n; i++) {
357 if(ranks1[i]==MPI_PROC_NULL){
358 ranks2[i]=MPI_PROC_NULL;
360 index = smpi_group_index(group1, ranks1[i]);
361 ranks2[i] = smpi_group_rank(group2, index);
364 retval = MPI_SUCCESS;
369 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
373 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
374 retval = MPI_ERR_GROUP;
375 } else if (result == nullptr) {
376 retval = MPI_ERR_ARG;
378 *result = smpi_group_compare(group1, group2);
379 retval = MPI_SUCCESS;
384 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
386 int retval, i, proc1, proc2, size, size2;
388 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
389 retval = MPI_ERR_GROUP;
390 } else if (newgroup == nullptr) {
391 retval = MPI_ERR_ARG;
393 size = smpi_group_size(group1);
394 size2 = smpi_group_size(group2);
395 for (i = 0; i < size2; i++) {
396 proc2 = smpi_group_index(group2, i);
397 proc1 = smpi_group_rank(group1, proc2);
398 if (proc1 == MPI_UNDEFINED) {
403 *newgroup = MPI_GROUP_EMPTY;
405 *newgroup = smpi_group_new(size);
406 size2 = smpi_group_size(group1);
407 for (i = 0; i < size2; i++) {
408 proc1 = smpi_group_index(group1, i);
409 smpi_group_set_mapping(*newgroup, proc1, i);
411 for (i = size2; i < size; i++) {
412 proc2 = smpi_group_index(group2, i - size2);
413 smpi_group_set_mapping(*newgroup, proc2, i);
416 retval = MPI_SUCCESS;
421 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
423 int retval, i, proc1, proc2, size;
425 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
426 retval = MPI_ERR_GROUP;
427 } else if (newgroup == nullptr) {
428 retval = MPI_ERR_ARG;
430 size = smpi_group_size(group2);
431 for (i = 0; i < size; i++) {
432 proc2 = smpi_group_index(group2, i);
433 proc1 = smpi_group_rank(group1, proc2);
434 if (proc1 == MPI_UNDEFINED) {
439 *newgroup = MPI_GROUP_EMPTY;
441 *newgroup = smpi_group_new(size);
443 for (i = 0; i < smpi_group_size(group2); i++) {
444 proc2 = smpi_group_index(group2, i);
445 proc1 = smpi_group_rank(group1, proc2);
446 if (proc1 != MPI_UNDEFINED) {
447 smpi_group_set_mapping(*newgroup, proc2, j);
452 retval = MPI_SUCCESS;
457 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
459 int retval, i, proc1, proc2, size, size2;
461 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
462 retval = MPI_ERR_GROUP;
463 } else if (newgroup == nullptr) {
464 retval = MPI_ERR_ARG;
466 size = smpi_group_size(group1);
468 for (i = 0; i < size2; i++) {
469 proc1 = smpi_group_index(group1, i);
470 proc2 = smpi_group_rank(group2, proc1);
471 if (proc2 != MPI_UNDEFINED) {
476 *newgroup = MPI_GROUP_EMPTY;
478 *newgroup = smpi_group_new(size);
479 for (i = 0; i < size2; i++) {
480 proc1 = smpi_group_index(group1, i);
481 proc2 = smpi_group_rank(group2, proc1);
482 if (proc2 == MPI_UNDEFINED) {
483 smpi_group_set_mapping(*newgroup, proc1, i);
487 retval = MPI_SUCCESS;
492 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
496 if (group == MPI_GROUP_NULL) {
497 retval = MPI_ERR_GROUP;
498 } else if (newgroup == nullptr) {
499 retval = MPI_ERR_ARG;
501 retval = smpi_group_incl(group, n, ranks, newgroup);
506 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
508 int retval, i, j, newsize, oldsize, index;
510 if (group == MPI_GROUP_NULL) {
511 retval = MPI_ERR_GROUP;
512 } else if (newgroup == nullptr) {
513 retval = MPI_ERR_ARG;
517 if (group != smpi_comm_group(MPI_COMM_WORLD)
518 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
519 smpi_group_use(group);
520 } else if (n == smpi_group_size(group)) {
521 *newgroup = MPI_GROUP_EMPTY;
523 oldsize=smpi_group_size(group);
524 newsize = oldsize - n;
525 *newgroup = smpi_group_new(newsize);
527 int* to_exclude=xbt_new0(int, smpi_group_size(group));
528 for(i=0; i<oldsize; i++)
531 to_exclude[ranks[i]]=1;
534 for(i=0; i<oldsize; i++){
535 if(to_exclude[i]==0){
536 index = smpi_group_index(group, i);
537 smpi_group_set_mapping(*newgroup, index, j);
542 xbt_free(to_exclude);
544 retval = MPI_SUCCESS;
549 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
551 int retval, i, j, rank, size, index;
553 if (group == MPI_GROUP_NULL) {
554 retval = MPI_ERR_GROUP;
555 } else if (newgroup == nullptr) {
556 retval = MPI_ERR_ARG;
559 *newgroup = MPI_GROUP_EMPTY;
562 for (i = 0; i < n; i++) {
563 for (rank = ranges[i][0]; /* First */
564 rank >= 0 && rank < smpi_group_size(group); /* Last */
567 if(rank == ranges[i][1]){/*already last ?*/
570 rank += ranges[i][2]; /* Stride */
571 if (ranges[i][0]<ranges[i][1]){
572 if(rank > ranges[i][1])
575 if(rank < ranges[i][1])
581 *newgroup = smpi_group_new(size);
583 for (i = 0; i < n; i++) {
584 for (rank = ranges[i][0]; /* First */
585 rank >= 0 && rank < smpi_group_size(group); /* Last */
587 index = smpi_group_index(group, rank);
588 smpi_group_set_mapping(*newgroup, index, j);
590 if(rank == ranges[i][1]){/*already last ?*/
593 rank += ranges[i][2]; /* Stride */
594 if (ranges[i][0]<ranges[i][1]){
595 if(rank > ranges[i][1])
598 if(rank < ranges[i][1])
604 retval = MPI_SUCCESS;
609 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
611 int retval, i, rank, newrank,oldrank, size, index, add;
613 if (group == MPI_GROUP_NULL) {
614 retval = MPI_ERR_GROUP;
615 } else if (newgroup == nullptr) {
616 retval = MPI_ERR_ARG;
620 if (group!= smpi_comm_group(MPI_COMM_WORLD)
621 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
622 smpi_group_use(group);
624 size = smpi_group_size(group);
625 for (i = 0; i < n; i++) {
626 for (rank = ranges[i][0]; /* First */
627 rank >= 0 && rank < smpi_group_size(group); /* Last */
630 if(rank == ranges[i][1]){/*already last ?*/
633 rank += ranges[i][2]; /* Stride */
634 if (ranges[i][0]<ranges[i][1]){
635 if(rank > ranges[i][1])
638 if(rank < ranges[i][1])
644 *newgroup = MPI_GROUP_EMPTY;
646 *newgroup = smpi_group_new(size);
649 while (newrank < size) {
651 for (i = 0; i < n; i++) {
652 for (rank = ranges[i][0];
653 rank >= 0 && rank < smpi_group_size(group);
659 if(rank == ranges[i][1]){/*already last ?*/
662 rank += ranges[i][2]; /* Stride */
663 if (ranges[i][0]<ranges[i][1]){
664 if(rank > ranges[i][1])
667 if(rank < ranges[i][1])
673 index = smpi_group_index(group, oldrank);
674 smpi_group_set_mapping(*newgroup, index, newrank);
682 retval = MPI_SUCCESS;
687 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
690 if (comm == MPI_COMM_NULL) {
691 retval = MPI_ERR_COMM;
692 } else if (rank == nullptr) {
693 retval = MPI_ERR_ARG;
695 *rank = smpi_comm_rank(comm);
696 retval = MPI_SUCCESS;
701 int PMPI_Comm_size(MPI_Comm comm, int *size)
704 if (comm == MPI_COMM_NULL) {
705 retval = MPI_ERR_COMM;
706 } else if (size == nullptr) {
707 retval = MPI_ERR_ARG;
709 *size = smpi_comm_size(comm);
710 retval = MPI_SUCCESS;
715 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
719 if (comm == MPI_COMM_NULL) {
720 retval = MPI_ERR_COMM;
721 } else if (name == nullptr || len == nullptr) {
722 retval = MPI_ERR_ARG;
724 smpi_comm_get_name(comm, name, len);
725 retval = MPI_SUCCESS;
730 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
734 if (comm == MPI_COMM_NULL) {
735 retval = MPI_ERR_COMM;
736 } else if (group == nullptr) {
737 retval = MPI_ERR_ARG;
739 *group = smpi_comm_group(comm);
740 if(*group!= smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL
741 && *group != MPI_GROUP_EMPTY)
742 smpi_group_use(*group);
743 retval = MPI_SUCCESS;
748 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
752 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
753 retval = MPI_ERR_COMM;
754 } else if (result == nullptr) {
755 retval = MPI_ERR_ARG;
757 if (comm1 == comm2) { /* Same communicators means same groups */
760 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
761 if (*result == MPI_IDENT) {
762 *result = MPI_CONGRUENT;
765 retval = MPI_SUCCESS;
770 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
774 if (comm == MPI_COMM_NULL) {
775 retval = MPI_ERR_COMM;
776 } else if (newcomm == nullptr) {
777 retval = MPI_ERR_ARG;
779 retval = smpi_comm_dup(comm, newcomm);
784 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
788 if (comm == MPI_COMM_NULL) {
789 retval = MPI_ERR_COMM;
790 } else if (group == MPI_GROUP_NULL) {
791 retval = MPI_ERR_GROUP;
792 } else if (newcomm == nullptr) {
793 retval = MPI_ERR_ARG;
794 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
795 *newcomm= MPI_COMM_NULL;
796 retval = MPI_SUCCESS;
798 smpi_group_use(group);
799 *newcomm = smpi_comm_new(group, nullptr);
800 retval = MPI_SUCCESS;
805 int PMPI_Comm_free(MPI_Comm * comm)
809 if (comm == nullptr) {
810 retval = MPI_ERR_ARG;
811 } else if (*comm == MPI_COMM_NULL) {
812 retval = MPI_ERR_COMM;
814 smpi_comm_destroy(*comm);
815 *comm = MPI_COMM_NULL;
816 retval = MPI_SUCCESS;
821 int PMPI_Comm_disconnect(MPI_Comm * comm)
823 /* TODO: wait until all communication in comm are done */
826 if (comm == nullptr) {
827 retval = MPI_ERR_ARG;
828 } else if (*comm == MPI_COMM_NULL) {
829 retval = MPI_ERR_COMM;
831 smpi_comm_destroy(*comm);
832 *comm = MPI_COMM_NULL;
833 retval = MPI_SUCCESS;
838 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
843 if (comm_out == nullptr) {
844 retval = MPI_ERR_ARG;
845 } else if (comm == MPI_COMM_NULL) {
846 retval = MPI_ERR_COMM;
848 *comm_out = smpi_comm_split(comm, color, key);
849 retval = MPI_SUCCESS;
856 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
861 if (request == nullptr) {
862 retval = MPI_ERR_ARG;
863 } else if (comm == MPI_COMM_NULL) {
864 retval = MPI_ERR_COMM;
865 } else if (!is_datatype_valid(datatype)) {
866 retval = MPI_ERR_TYPE;
867 } else if (dst == MPI_PROC_NULL) {
868 retval = MPI_SUCCESS;
870 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
871 retval = MPI_SUCCESS;
874 if (retval != MPI_SUCCESS && request != nullptr)
875 *request = MPI_REQUEST_NULL;
879 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
884 if (request == nullptr) {
885 retval = MPI_ERR_ARG;
886 } else if (comm == MPI_COMM_NULL) {
887 retval = MPI_ERR_COMM;
888 } else if (!is_datatype_valid(datatype)) {
889 retval = MPI_ERR_TYPE;
890 } else if (src == MPI_PROC_NULL) {
891 retval = MPI_SUCCESS;
893 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
894 retval = MPI_SUCCESS;
897 if (retval != MPI_SUCCESS && request != nullptr)
898 *request = MPI_REQUEST_NULL;
902 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
907 if (request == nullptr) {
908 retval = MPI_ERR_ARG;
909 } else if (comm == MPI_COMM_NULL) {
910 retval = MPI_ERR_COMM;
911 } else if (!is_datatype_valid(datatype)) {
912 retval = MPI_ERR_TYPE;
913 } else if (dst == MPI_PROC_NULL) {
914 retval = MPI_SUCCESS;
916 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
917 retval = MPI_SUCCESS;
920 if (retval != MPI_SUCCESS && request != nullptr)
921 *request = MPI_REQUEST_NULL;
925 int PMPI_Start(MPI_Request * request)
930 if (request == nullptr || *request == MPI_REQUEST_NULL) {
931 retval = MPI_ERR_REQUEST;
933 smpi_mpi_start(*request);
934 retval = MPI_SUCCESS;
940 int PMPI_Startall(int count, MPI_Request * requests)
945 if (requests == nullptr) {
946 retval = MPI_ERR_ARG;
948 retval = MPI_SUCCESS;
949 for (i = 0 ; i < count ; i++) {
950 if(requests[i] == MPI_REQUEST_NULL) {
951 retval = MPI_ERR_REQUEST;
954 if(retval != MPI_ERR_REQUEST) {
955 smpi_mpi_startall(count, requests);
962 int PMPI_Request_free(MPI_Request * request)
967 if (*request == MPI_REQUEST_NULL) {
968 retval = MPI_ERR_ARG;
970 smpi_mpi_request_free(request);
971 retval = MPI_SUCCESS;
977 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
983 if (request == nullptr) {
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) || (buf==nullptr && count > 0)) {
993 retval = MPI_ERR_COUNT;
994 } else if (!is_datatype_valid(datatype)) {
995 retval = MPI_ERR_TYPE;
996 } else if(tag<0 && tag != MPI_ANY_TAG){
997 retval = MPI_ERR_TAG;
1000 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1001 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1003 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1004 extra->type = TRACING_IRECV;
1005 extra->src = src_traced;
1008 extra->datatype1 = encode_datatype(datatype, &known);
1009 int dt_size_send = 1;
1011 dt_size_send = smpi_datatype_size(datatype);
1012 extra->send_size = count*dt_size_send;
1013 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;
1018 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1019 (*request)->recv = 1;
1023 if (retval != MPI_SUCCESS && request != nullptr)
1024 *request = MPI_REQUEST_NULL;
1029 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1034 if (request == nullptr) {
1035 retval = MPI_ERR_ARG;
1036 } else if (comm == MPI_COMM_NULL) {
1037 retval = MPI_ERR_COMM;
1038 } else if (dst == MPI_PROC_NULL) {
1039 *request = MPI_REQUEST_NULL;
1040 retval = MPI_SUCCESS;
1041 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1042 retval = MPI_ERR_RANK;
1043 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1044 retval = MPI_ERR_COUNT;
1045 } else if (!is_datatype_valid(datatype)) {
1046 retval = MPI_ERR_TYPE;
1047 } else if(tag<0 && tag != MPI_ANY_TAG){
1048 retval = MPI_ERR_TAG;
1051 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1052 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1053 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1054 extra->type = TRACING_ISEND;
1056 extra->dst = dst_traced;
1058 extra->datatype1 = encode_datatype(datatype, &known);
1059 int dt_size_send = 1;
1061 dt_size_send = smpi_datatype_size(datatype);
1062 extra->send_size = count*dt_size_send;
1063 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1064 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1066 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1067 retval = MPI_SUCCESS;
1069 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1070 (*request)->send = 1;
1074 if (retval != MPI_SUCCESS && request!=nullptr)
1075 *request = MPI_REQUEST_NULL;
1079 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
1084 if (request == nullptr) {
1085 retval = MPI_ERR_ARG;
1086 } else if (comm == MPI_COMM_NULL) {
1087 retval = MPI_ERR_COMM;
1088 } else if (dst == MPI_PROC_NULL) {
1089 *request = MPI_REQUEST_NULL;
1090 retval = MPI_SUCCESS;
1091 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1092 retval = MPI_ERR_RANK;
1093 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
1094 retval = MPI_ERR_COUNT;
1095 } else if (!is_datatype_valid(datatype)) {
1096 retval = MPI_ERR_TYPE;
1097 } else if(tag<0 && tag != MPI_ANY_TAG){
1098 retval = MPI_ERR_TAG;
1101 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1102 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1103 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1104 extra->type = TRACING_ISSEND;
1106 extra->dst = dst_traced;
1108 extra->datatype1 = encode_datatype(datatype, &known);
1109 int dt_size_send = 1;
1111 dt_size_send = smpi_datatype_size(datatype);
1112 extra->send_size = count*dt_size_send;
1113 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1114 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1116 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1117 retval = MPI_SUCCESS;
1119 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1120 (*request)->send = 1;
1124 if (retval != MPI_SUCCESS && request!=nullptr)
1125 *request = MPI_REQUEST_NULL;
1129 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1134 if (comm == MPI_COMM_NULL) {
1135 retval = MPI_ERR_COMM;
1136 } else if (src == MPI_PROC_NULL) {
1137 smpi_empty_status(status);
1138 status->MPI_SOURCE = MPI_PROC_NULL;
1139 retval = MPI_SUCCESS;
1140 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1141 retval = MPI_ERR_RANK;
1142 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1143 retval = MPI_ERR_COUNT;
1144 } else if (!is_datatype_valid(datatype)) {
1145 retval = MPI_ERR_TYPE;
1146 } else if(tag<0 && tag != MPI_ANY_TAG){
1147 retval = MPI_ERR_TAG;
1149 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1150 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1151 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1152 extra->type = TRACING_RECV;
1153 extra->src = src_traced;
1156 extra->datatype1 = encode_datatype(datatype, &known);
1157 int dt_size_send = 1;
1159 dt_size_send = smpi_datatype_size(datatype);
1160 extra->send_size = count*dt_size_send;
1161 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1163 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1164 retval = MPI_SUCCESS;
1166 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1167 if(status!=MPI_STATUS_IGNORE){
1168 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1169 if (!TRACE_smpi_view_internals()) {
1170 TRACE_smpi_recv(rank, src_traced, rank, tag);
1173 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1180 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1186 if (comm == MPI_COMM_NULL) {
1187 retval = MPI_ERR_COMM;
1188 } else if (dst == MPI_PROC_NULL) {
1189 retval = MPI_SUCCESS;
1190 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1191 retval = MPI_ERR_RANK;
1192 } else if ((count < 0) || (buf == nullptr && count > 0)) {
1193 retval = MPI_ERR_COUNT;
1194 } else if (!is_datatype_valid(datatype)) {
1195 retval = MPI_ERR_TYPE;
1196 } else if(tag < 0 && tag != MPI_ANY_TAG){
1197 retval = MPI_ERR_TAG;
1199 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1200 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1201 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1202 extra->type = TRACING_SEND;
1204 extra->dst = dst_traced;
1206 extra->datatype1 = encode_datatype(datatype, &known);
1207 int dt_size_send = 1;
1209 dt_size_send = smpi_datatype_size(datatype);
1211 extra->send_size = count*dt_size_send;
1212 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1213 if (!TRACE_smpi_view_internals()) {
1214 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1217 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1218 retval = MPI_SUCCESS;
1220 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1227 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1232 if (comm == MPI_COMM_NULL) {
1233 retval = MPI_ERR_COMM;
1234 } else if (dst == MPI_PROC_NULL) {
1235 retval = MPI_SUCCESS;
1236 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1237 retval = MPI_ERR_RANK;
1238 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1239 retval = MPI_ERR_COUNT;
1240 } else if (!is_datatype_valid(datatype)){
1241 retval = MPI_ERR_TYPE;
1242 } else if(tag<0 && tag != MPI_ANY_TAG){
1243 retval = MPI_ERR_TAG;
1245 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1246 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1247 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1248 extra->type = TRACING_SSEND;
1250 extra->dst = dst_traced;
1252 extra->datatype1 = encode_datatype(datatype, &known);
1253 int dt_size_send = 1;
1255 dt_size_send = smpi_datatype_size(datatype);
1257 extra->send_size = count*dt_size_send;
1258 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1259 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1261 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1262 retval = MPI_SUCCESS;
1264 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1271 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1272 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1278 if (comm == MPI_COMM_NULL) {
1279 retval = MPI_ERR_COMM;
1280 } else if (!is_datatype_valid(sendtype)
1281 || !is_datatype_valid(recvtype)) {
1282 retval = MPI_ERR_TYPE;
1283 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1284 smpi_empty_status(status);
1285 status->MPI_SOURCE = MPI_PROC_NULL;
1286 retval = MPI_SUCCESS;
1287 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1288 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1289 retval = MPI_ERR_RANK;
1290 } else if ((sendcount < 0 || recvcount<0) ||
1291 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1292 retval = MPI_ERR_COUNT;
1293 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1294 retval = MPI_ERR_TAG;
1297 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1298 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1299 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1300 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1301 extra->type = TRACING_SENDRECV;
1302 extra->src = src_traced;
1303 extra->dst = dst_traced;
1305 extra->datatype1 = encode_datatype(sendtype, &known);
1306 int dt_size_send = 1;
1308 dt_size_send = smpi_datatype_size(sendtype);
1309 extra->send_size = sendcount*dt_size_send;
1310 extra->datatype2 = encode_datatype(recvtype, &known);
1311 int dt_size_recv = 1;
1313 dt_size_recv = smpi_datatype_size(recvtype);
1314 extra->recv_size = recvcount*dt_size_recv;
1316 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1317 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1319 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1320 recvcount, recvtype, src, recvtag, comm, status);
1321 retval = MPI_SUCCESS;
1323 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1324 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1331 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1332 MPI_Comm comm, MPI_Status * status)
1336 if (!is_datatype_valid(datatype)) {
1337 retval = MPI_ERR_TYPE;
1338 } else if (count < 0) {
1339 retval = MPI_ERR_COUNT;
1341 int size = smpi_datatype_get_extent(datatype) * count;
1342 recvbuf = xbt_new0(char, size);
1343 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1344 if(retval==MPI_SUCCESS){
1345 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1353 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1357 if (request == nullptr || flag == nullptr) {
1358 retval = MPI_ERR_ARG;
1359 } else if (*request == MPI_REQUEST_NULL) {
1361 smpi_empty_status(status);
1362 retval = MPI_SUCCESS;
1364 int rank = ((*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1366 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1367 extra->type = TRACING_TEST;
1368 TRACE_smpi_testing_in(rank, extra);
1370 *flag = smpi_mpi_test(request, status);
1372 TRACE_smpi_testing_out(rank);
1373 retval = MPI_SUCCESS;
1379 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1384 if (index == nullptr || flag == nullptr) {
1385 retval = MPI_ERR_ARG;
1387 *flag = smpi_mpi_testany(count, requests, index, status);
1388 retval = MPI_SUCCESS;
1394 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1399 if (flag == nullptr) {
1400 retval = MPI_ERR_ARG;
1402 *flag = smpi_mpi_testall(count, requests, statuses);
1403 retval = MPI_SUCCESS;
1409 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1413 if (status == nullptr) {
1414 retval = MPI_ERR_ARG;
1415 } else if (comm == MPI_COMM_NULL) {
1416 retval = MPI_ERR_COMM;
1417 } else if (source == MPI_PROC_NULL) {
1418 smpi_empty_status(status);
1419 status->MPI_SOURCE = MPI_PROC_NULL;
1420 retval = MPI_SUCCESS;
1422 smpi_mpi_probe(source, tag, comm, status);
1423 retval = MPI_SUCCESS;
1429 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1433 if ((flag == nullptr) || (status == nullptr)) {
1434 retval = MPI_ERR_ARG;
1435 } else if (comm == MPI_COMM_NULL) {
1436 retval = MPI_ERR_COMM;
1437 } else if (source == MPI_PROC_NULL) {
1439 smpi_empty_status(status);
1440 status->MPI_SOURCE = MPI_PROC_NULL;
1441 retval = MPI_SUCCESS;
1443 smpi_mpi_iprobe(source, tag, comm, flag, status);
1444 retval = MPI_SUCCESS;
1450 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1456 smpi_empty_status(status);
1458 if (request == nullptr) {
1459 retval = MPI_ERR_ARG;
1460 } else if (*request == MPI_REQUEST_NULL) {
1461 retval = MPI_SUCCESS;
1464 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1466 int src_traced = (*request)->src;
1467 int dst_traced = (*request)->dst;
1468 int tag_traced= (*request)->tag;
1469 MPI_Comm comm = (*request)->comm;
1470 int is_wait_for_receive = (*request)->recv;
1471 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1472 extra->type = TRACING_WAIT;
1473 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1475 smpi_mpi_wait(request, status);
1476 retval = MPI_SUCCESS;
1478 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1479 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1480 if (is_wait_for_receive) {
1481 if(src_traced==MPI_ANY_SOURCE)
1482 src_traced = (status!=MPI_STATUS_IGNORE) ?
1483 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1485 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1493 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1495 if (index == nullptr)
1499 //save requests information for tracing
1508 savedvalstype* savedvals=nullptr;
1510 savedvals = xbt_new0(savedvalstype, count);
1512 for (i = 0; i < count; i++) {
1513 MPI_Request req = requests[i]; //already received requests are no longer valid
1515 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1518 int rank_traced = smpi_process_index();
1519 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1520 extra->type = TRACING_WAITANY;
1521 extra->send_size=count;
1522 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1524 *index = smpi_mpi_waitany(count, requests, status);
1526 if(*index!=MPI_UNDEFINED){
1527 int src_traced = savedvals[*index].src;
1528 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1529 int dst_traced = savedvals[*index].dst;
1530 int is_wait_for_receive = savedvals[*index].recv;
1531 if (is_wait_for_receive) {
1532 if(savedvals[*index].src==MPI_ANY_SOURCE)
1533 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1534 smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE) : savedvals[*index].src;
1535 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1537 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1539 xbt_free(savedvals);
1545 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1548 //save information from requests
1558 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1560 for (i = 0; i < count; i++) {
1561 MPI_Request req = requests[i];
1562 if(req!=MPI_REQUEST_NULL){
1563 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1565 savedvals[i].valid=0;
1568 int rank_traced = smpi_process_index();
1569 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1570 extra->type = TRACING_WAITALL;
1571 extra->send_size=count;
1572 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1574 int retval = smpi_mpi_waitall(count, requests, status);
1576 for (i = 0; i < count; i++) {
1577 if(savedvals[i].valid){
1578 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1579 int src_traced = savedvals[i].src;
1580 int dst_traced = savedvals[i].dst;
1581 int is_wait_for_receive = savedvals[i].recv;
1582 if (is_wait_for_receive) {
1583 if(src_traced==MPI_ANY_SOURCE)
1584 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1585 smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
1586 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1590 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1591 xbt_free(savedvals);
1597 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1602 if (outcount == nullptr) {
1603 retval = MPI_ERR_ARG;
1605 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1606 retval = MPI_SUCCESS;
1612 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1617 if (outcount == nullptr) {
1618 retval = MPI_ERR_ARG;
1620 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1621 retval = MPI_SUCCESS;
1628 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1634 if (comm == MPI_COMM_NULL) {
1635 retval = MPI_ERR_COMM;
1636 } else if (!is_datatype_valid(datatype)) {
1637 retval = MPI_ERR_ARG;
1639 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1640 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1642 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1643 extra->type = TRACING_BCAST;
1644 extra->root = root_traced;
1646 extra->datatype1 = encode_datatype(datatype, &known);
1647 int dt_size_send = 1;
1649 dt_size_send = smpi_datatype_size(datatype);
1650 extra->send_size = count*dt_size_send;
1651 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1652 if(smpi_comm_size(comm)>1)
1653 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1654 retval = MPI_SUCCESS;
1656 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1663 int PMPI_Barrier(MPI_Comm comm)
1669 if (comm == MPI_COMM_NULL) {
1670 retval = MPI_ERR_COMM;
1672 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1673 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1674 extra->type = TRACING_BARRIER;
1675 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1677 mpi_coll_barrier_fun(comm);
1678 retval = MPI_SUCCESS;
1680 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1687 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1688 int root, MPI_Comm comm)
1694 if (comm == MPI_COMM_NULL) {
1695 retval = MPI_ERR_COMM;
1696 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1697 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1698 retval = MPI_ERR_TYPE;
1699 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1700 retval = MPI_ERR_COUNT;
1703 char* sendtmpbuf = static_cast<char*>(sendbuf);
1704 int sendtmpcount = sendcount;
1705 MPI_Datatype sendtmptype = sendtype;
1706 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1708 sendtmptype=recvtype;
1710 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1711 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1712 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1713 extra->type = TRACING_GATHER;
1714 extra->root = root_traced;
1716 extra->datatype1 = encode_datatype(sendtmptype, &known);
1717 int dt_size_send = 1;
1719 dt_size_send = smpi_datatype_size(sendtmptype);
1720 extra->send_size = sendtmpcount*dt_size_send;
1721 extra->datatype2 = encode_datatype(recvtype, &known);
1722 int dt_size_recv = 1;
1723 if((smpi_comm_rank(comm)==root) && known==0)
1724 dt_size_recv = smpi_datatype_size(recvtype);
1725 extra->recv_size = recvcount*dt_size_recv;
1727 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1729 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1731 retval = MPI_SUCCESS;
1732 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1739 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1740 MPI_Datatype recvtype, 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 retval = MPI_ERR_COUNT;
1753 } else if (recvcounts == nullptr || displs == nullptr) {
1754 retval = MPI_ERR_ARG;
1756 char* sendtmpbuf = static_cast<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);
1767 int size = smpi_comm_size(comm);
1768 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1769 extra->type = TRACING_GATHERV;
1770 extra->num_processes = size;
1771 extra->root = root_traced;
1773 extra->datatype1 = encode_datatype(sendtmptype, &known);
1774 int dt_size_send = 1;
1776 dt_size_send = smpi_datatype_size(sendtype);
1777 extra->send_size = sendtmpcount*dt_size_send;
1778 extra->datatype2 = encode_datatype(recvtype, &known);
1779 int dt_size_recv = 1;
1781 dt_size_recv = smpi_datatype_size(recvtype);
1782 if((smpi_comm_rank(comm)==root)){
1783 extra->recvcounts= xbt_new(int,size);
1784 for(i=0; i< size; i++)//copy data to avoid bad free
1785 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1787 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1789 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1790 retval = MPI_SUCCESS;
1791 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1798 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1799 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1805 if (comm == MPI_COMM_NULL) {
1806 retval = MPI_ERR_COMM;
1807 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1808 (recvtype == MPI_DATATYPE_NULL)){
1809 retval = MPI_ERR_TYPE;
1810 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1812 retval = MPI_ERR_COUNT;
1814 if(sendbuf == MPI_IN_PLACE) {
1815 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1816 sendcount=recvcount;
1819 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1820 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1821 extra->type = TRACING_ALLGATHER;
1823 extra->datatype1 = encode_datatype(sendtype, &known);
1824 int dt_size_send = 1;
1826 dt_size_send = smpi_datatype_size(sendtype);
1827 extra->send_size = sendcount*dt_size_send;
1828 extra->datatype2 = encode_datatype(recvtype, &known);
1829 int dt_size_recv = 1;
1831 dt_size_recv = smpi_datatype_size(recvtype);
1832 extra->recv_size = recvcount*dt_size_recv;
1834 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1836 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1837 retval = MPI_SUCCESS;
1838 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1844 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1845 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1851 if (comm == MPI_COMM_NULL) {
1852 retval = MPI_ERR_COMM;
1853 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1854 (recvtype == MPI_DATATYPE_NULL)){
1855 retval = MPI_ERR_TYPE;
1856 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1857 retval = MPI_ERR_COUNT;
1858 } else if (recvcounts == nullptr || displs == nullptr) {
1859 retval = MPI_ERR_ARG;
1862 if(sendbuf == MPI_IN_PLACE) {
1863 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1864 sendcount=recvcounts[smpi_comm_rank(comm)];
1867 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1869 int size = smpi_comm_size(comm);
1870 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1871 extra->type = TRACING_ALLGATHERV;
1872 extra->num_processes = size;
1874 extra->datatype1 = encode_datatype(sendtype, &known);
1875 int dt_size_send = 1;
1877 dt_size_send = smpi_datatype_size(sendtype);
1878 extra->send_size = sendcount*dt_size_send;
1879 extra->datatype2 = encode_datatype(recvtype, &known);
1880 int dt_size_recv = 1;
1882 dt_size_recv = smpi_datatype_size(recvtype);
1883 extra->recvcounts= xbt_new(int, size);
1884 for(i=0; i< size; i++)//copy data to avoid bad free
1885 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1887 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1889 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1890 retval = MPI_SUCCESS;
1891 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1898 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1899 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1905 if (comm == MPI_COMM_NULL) {
1906 retval = MPI_ERR_COMM;
1907 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1908 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1909 retval = MPI_ERR_TYPE;
1910 } else if ((sendbuf == recvbuf) ||
1911 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1912 retval = MPI_ERR_BUFFER;
1915 if (recvbuf == MPI_IN_PLACE) {
1917 recvcount=sendcount;
1919 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1920 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1921 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1922 extra->type = TRACING_SCATTER;
1923 extra->root = root_traced;
1925 extra->datatype1 = encode_datatype(sendtype, &known);
1926 int dt_size_send = 1;
1927 if((smpi_comm_rank(comm)==root) && known==0)
1928 dt_size_send = smpi_datatype_size(sendtype);
1929 extra->send_size = sendcount*dt_size_send;
1930 extra->datatype2 = encode_datatype(recvtype, &known);
1931 int dt_size_recv = 1;
1933 dt_size_recv = smpi_datatype_size(recvtype);
1934 extra->recv_size = recvcount*dt_size_recv;
1935 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1937 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1938 retval = MPI_SUCCESS;
1939 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1946 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1947 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1953 if (comm == MPI_COMM_NULL) {
1954 retval = MPI_ERR_COMM;
1955 } else if (sendcounts == nullptr || displs == nullptr) {
1956 retval = MPI_ERR_ARG;
1957 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1958 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1959 retval = MPI_ERR_TYPE;
1961 if (recvbuf == MPI_IN_PLACE) {
1963 recvcount=sendcounts[smpi_comm_rank(comm)];
1965 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1966 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1968 int size = smpi_comm_size(comm);
1969 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1970 extra->type = TRACING_SCATTERV;
1971 extra->num_processes = size;
1972 extra->root = root_traced;
1974 extra->datatype1 = encode_datatype(sendtype, &known);
1975 int dt_size_send = 1;
1977 dt_size_send = smpi_datatype_size(sendtype);
1978 if((smpi_comm_rank(comm)==root)){
1979 extra->sendcounts= xbt_new(int, size);
1980 for(i=0; i< size; i++)//copy data to avoid bad free
1981 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
1983 extra->datatype2 = encode_datatype(recvtype, &known);
1984 int dt_size_recv = 1;
1986 dt_size_recv = smpi_datatype_size(recvtype);
1987 extra->recv_size = recvcount*dt_size_recv;
1988 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1990 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1992 retval = MPI_SUCCESS;
1993 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2000 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2006 if (comm == MPI_COMM_NULL) {
2007 retval = MPI_ERR_COMM;
2008 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2009 retval = MPI_ERR_ARG;
2011 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2012 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2013 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2014 extra->type = TRACING_REDUCE;
2016 extra->datatype1 = encode_datatype(datatype, &known);
2017 int dt_size_send = 1;
2019 dt_size_send = smpi_datatype_size(datatype);
2020 extra->send_size = count*dt_size_send;
2021 extra->root = root_traced;
2023 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2025 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2027 retval = MPI_SUCCESS;
2028 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2035 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2039 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2040 retval = MPI_ERR_ARG;
2042 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2049 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2055 if (comm == MPI_COMM_NULL) {
2056 retval = MPI_ERR_COMM;
2057 } else if (!is_datatype_valid(datatype)) {
2058 retval = MPI_ERR_TYPE;
2059 } else if (op == MPI_OP_NULL) {
2060 retval = MPI_ERR_OP;
2063 char* sendtmpbuf = static_cast<char*>(sendbuf);
2064 if( sendbuf == MPI_IN_PLACE ) {
2065 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
2066 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2068 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2069 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2070 extra->type = TRACING_ALLREDUCE;
2072 extra->datatype1 = encode_datatype(datatype, &known);
2073 int dt_size_send = 1;
2075 dt_size_send = smpi_datatype_size(datatype);
2076 extra->send_size = count*dt_size_send;
2078 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2080 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2082 if( sendbuf == MPI_IN_PLACE )
2083 xbt_free(sendtmpbuf);
2085 retval = MPI_SUCCESS;
2086 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2093 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2099 if (comm == MPI_COMM_NULL) {
2100 retval = MPI_ERR_COMM;
2101 } else if (!is_datatype_valid(datatype)) {
2102 retval = MPI_ERR_TYPE;
2103 } else if (op == MPI_OP_NULL) {
2104 retval = MPI_ERR_OP;
2106 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2107 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2108 extra->type = TRACING_SCAN;
2110 extra->datatype1 = encode_datatype(datatype, &known);
2111 int dt_size_send = 1;
2113 dt_size_send = smpi_datatype_size(datatype);
2114 extra->send_size = count*dt_size_send;
2116 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2118 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2120 retval = MPI_SUCCESS;
2121 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2128 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2133 if (comm == MPI_COMM_NULL) {
2134 retval = MPI_ERR_COMM;
2135 } else if (!is_datatype_valid(datatype)) {
2136 retval = MPI_ERR_TYPE;
2137 } else if (op == MPI_OP_NULL) {
2138 retval = MPI_ERR_OP;
2140 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2141 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2142 extra->type = TRACING_EXSCAN;
2144 extra->datatype1 = encode_datatype(datatype, &known);
2145 int dt_size_send = 1;
2147 dt_size_send = smpi_datatype_size(datatype);
2148 extra->send_size = count*dt_size_send;
2149 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2151 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2152 retval = MPI_SUCCESS;
2153 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2160 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2165 if (comm == MPI_COMM_NULL) {
2166 retval = MPI_ERR_COMM;
2167 } else if (!is_datatype_valid(datatype)) {
2168 retval = MPI_ERR_TYPE;
2169 } else if (op == MPI_OP_NULL) {
2170 retval = MPI_ERR_OP;
2171 } else if (recvcounts == nullptr) {
2172 retval = MPI_ERR_ARG;
2174 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2176 int size = smpi_comm_size(comm);
2177 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2178 extra->type = TRACING_REDUCE_SCATTER;
2179 extra->num_processes = size;
2181 extra->datatype1 = encode_datatype(datatype, &known);
2182 int dt_size_send = 1;
2184 dt_size_send = smpi_datatype_size(datatype);
2185 extra->send_size = 0;
2186 extra->recvcounts= xbt_new(int, size);
2187 for(i=0; i< size; i++)//copy data to avoid bad free
2188 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2189 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2191 void* sendtmpbuf=sendbuf;
2192 if(sendbuf==MPI_IN_PLACE)
2195 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2196 retval = MPI_SUCCESS;
2197 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2204 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2205 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2210 if (comm == MPI_COMM_NULL) {
2211 retval = MPI_ERR_COMM;
2212 } else if (!is_datatype_valid(datatype)) {
2213 retval = MPI_ERR_TYPE;
2214 } else if (op == MPI_OP_NULL) {
2215 retval = MPI_ERR_OP;
2216 } else if (recvcount < 0) {
2217 retval = MPI_ERR_ARG;
2219 int count=smpi_comm_size(comm);
2221 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2222 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2223 extra->type = TRACING_REDUCE_SCATTER;
2224 extra->num_processes = count;
2226 extra->datatype1 = encode_datatype(datatype, &known);
2227 int dt_size_send = 1;
2229 dt_size_send = smpi_datatype_size(datatype);
2230 extra->send_size = 0;
2231 extra->recvcounts= xbt_new(int, count);
2232 for(i=0; i< count; i++)//copy data to avoid bad free
2233 extra->recvcounts[i] = recvcount*dt_size_send;
2235 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2237 int* recvcounts=static_cast<int*>(xbt_malloc(count));
2238 for (i=0; i<count;i++)
2239 recvcounts[i]=recvcount;
2240 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts, datatype, op, comm);
2241 xbt_free(recvcounts);
2242 retval = MPI_SUCCESS;
2244 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2251 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2252 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2258 if (comm == MPI_COMM_NULL) {
2259 retval = MPI_ERR_COMM;
2260 } else if (sendtype == MPI_DATATYPE_NULL
2261 || recvtype == MPI_DATATYPE_NULL) {
2262 retval = MPI_ERR_TYPE;
2264 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2265 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2266 extra->type = TRACING_ALLTOALL;
2268 extra->datatype1 = encode_datatype(sendtype, &known);
2270 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2272 extra->send_size = sendcount;
2273 extra->datatype2 = encode_datatype(recvtype, &known);
2275 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2277 extra->recv_size = recvcount;
2278 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2280 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2282 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2289 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2290 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2296 if (comm == MPI_COMM_NULL) {
2297 retval = MPI_ERR_COMM;
2298 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2299 retval = MPI_ERR_TYPE;
2300 } else if (sendcounts == nullptr || senddisps == nullptr || recvcounts == nullptr || recvdisps == nullptr) {
2301 retval = MPI_ERR_ARG;
2303 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2305 int size = smpi_comm_size(comm);
2306 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2307 extra->type = TRACING_ALLTOALLV;
2308 extra->send_size = 0;
2309 extra->recv_size = 0;
2310 extra->recvcounts= xbt_new(int, size);
2311 extra->sendcounts= xbt_new(int, size);
2313 extra->datatype1 = encode_datatype(sendtype, &known);
2314 int dt_size_send = 1;
2316 dt_size_send = smpi_datatype_size(sendtype);
2317 int dt_size_recv = 1;
2318 extra->datatype2 = encode_datatype(recvtype, &known);
2320 dt_size_recv = smpi_datatype_size(recvtype);
2321 for(i=0; i< size; i++){//copy data to avoid bad free
2322 extra->send_size += sendcounts[i]*dt_size_send;
2323 extra->recv_size += recvcounts[i]*dt_size_recv;
2325 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2326 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2328 extra->num_processes = size;
2329 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2331 retval = mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype,
2333 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2341 int PMPI_Get_processor_name(char *name, int *resultlen)
2343 int retval = MPI_SUCCESS;
2345 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2346 ? strlen(SIMIX_host_self()->cname()) + 1
2347 : MPI_MAX_PROCESSOR_NAME - 1);
2348 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2353 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2355 int retval = MPI_SUCCESS;
2358 if (status == nullptr || count == nullptr) {
2359 retval = MPI_ERR_ARG;
2360 } else if (!is_datatype_valid(datatype)) {
2361 retval = MPI_ERR_TYPE;
2363 size = smpi_datatype_size(datatype);
2366 } else if (status->count % size != 0) {
2367 retval = MPI_UNDEFINED;
2369 *count = smpi_mpi_get_count(status, datatype);
2375 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2378 if (old_type == MPI_DATATYPE_NULL) {
2379 retval = MPI_ERR_TYPE;
2380 } else if (count<0){
2381 retval = MPI_ERR_COUNT;
2383 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2388 int PMPI_Type_commit(MPI_Datatype* datatype) {
2391 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2392 retval = MPI_ERR_TYPE;
2394 smpi_datatype_commit(datatype);
2395 retval = MPI_SUCCESS;
2400 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2403 if (old_type == MPI_DATATYPE_NULL) {
2404 retval = MPI_ERR_TYPE;
2405 } else if (count<0 || blocklen<0){
2406 retval = MPI_ERR_COUNT;
2408 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2413 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2416 if (old_type == MPI_DATATYPE_NULL) {
2417 retval = MPI_ERR_TYPE;
2418 } else if (count<0 || blocklen<0){
2419 retval = MPI_ERR_COUNT;
2421 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2426 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2427 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2430 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2433 if (old_type == MPI_DATATYPE_NULL) {
2434 retval = MPI_ERR_TYPE;
2435 } else if (count<0){
2436 retval = MPI_ERR_COUNT;
2438 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2443 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2446 if (old_type == MPI_DATATYPE_NULL) {
2447 retval = MPI_ERR_TYPE;
2448 } else if (count<0){
2449 retval = MPI_ERR_COUNT;
2451 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2456 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2457 MPI_Datatype* new_type) {
2460 if (old_type == MPI_DATATYPE_NULL) {
2461 retval = MPI_ERR_TYPE;
2462 } else if (count<0){
2463 retval = MPI_ERR_COUNT;
2465 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count));
2466 for (i=0; i<count;i++)
2467 blocklens[i]=blocklength;
2468 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2469 xbt_free(blocklens);
2474 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2477 if (old_type == MPI_DATATYPE_NULL) {
2478 retval = MPI_ERR_TYPE;
2479 } else if (count<0){
2480 retval = MPI_ERR_COUNT;
2482 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2487 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2488 MPI_Datatype* new_type) {
2489 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2492 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2493 MPI_Datatype* new_type) {
2496 if (old_type == MPI_DATATYPE_NULL) {
2497 retval = MPI_ERR_TYPE;
2498 } else if (count<0){
2499 retval = MPI_ERR_COUNT;
2501 int* blocklens=(int*)xbt_malloc(blocklength*count);
2502 for (i=0; i<count;i++)blocklens[i]=blocklength;
2503 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2504 xbt_free(blocklens);
2509 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2513 retval = MPI_ERR_COUNT;
2515 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2520 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2521 MPI_Datatype* new_type) {
2522 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2525 int PMPI_Error_class(int errorcode, int* errorclass) {
2526 // assume smpi uses only standard mpi error codes
2527 *errorclass=errorcode;
2531 int PMPI_Initialized(int* flag) {
2532 *flag=smpi_process_initialized();
2536 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2537 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2538 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2540 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2542 if (comm_old == MPI_COMM_NULL){
2543 retval = MPI_ERR_COMM;
2544 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2545 retval = MPI_ERR_ARG;
2547 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2552 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2553 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2554 return MPI_ERR_TOPOLOGY;
2556 if (coords == nullptr) {
2559 return smpi_mpi_cart_rank(comm, coords, rank);
2562 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2563 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2564 return MPI_ERR_TOPOLOGY;
2566 if (source == nullptr || dest == nullptr || direction < 0 ) {
2569 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2572 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2573 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2574 return MPI_ERR_TOPOLOGY;
2576 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2577 return MPI_ERR_RANK;
2582 if(coords == nullptr) {
2585 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2588 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2589 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2590 return MPI_ERR_TOPOLOGY;
2592 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2595 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2598 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2599 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2600 return MPI_ERR_TOPOLOGY;
2602 if (ndims == nullptr) {
2605 return smpi_mpi_cartdim_get(comm, ndims);
2608 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2609 if(dims == nullptr) {
2612 if (ndims < 1 || nnodes < 1) {
2613 return MPI_ERR_DIMS;
2616 return smpi_mpi_dims_create(nnodes, ndims, dims);
2619 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2620 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2621 return MPI_ERR_TOPOLOGY;
2623 if (comm_new == nullptr) {
2626 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2629 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2630 if(oldtype == MPI_DATATYPE_NULL) {
2631 return MPI_ERR_TYPE;
2633 int blocks[3] = { 1, 1, 1 };
2634 MPI_Aint disps[3] = { lb, 0, lb+extent };
2635 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2637 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2638 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t) , subtype, DT_FLAG_VECTOR);
2640 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2644 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2647 if (comm == MPI_COMM_NULL) {
2648 retval= MPI_ERR_COMM;
2649 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2650 retval= MPI_ERR_OTHER;
2652 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2653 retval = MPI_SUCCESS;
2659 int PMPI_Win_free( MPI_Win* win){
2662 if (win == nullptr || *win == MPI_WIN_NULL) {
2663 retval = MPI_ERR_WIN;
2665 retval=smpi_mpi_win_free(win);
2671 int PMPI_Win_set_name(MPI_Win win, char * name)
2674 if (win == MPI_WIN_NULL) {
2675 retval = MPI_ERR_TYPE;
2676 } else if (name == nullptr) {
2677 retval = MPI_ERR_ARG;
2679 smpi_mpi_win_set_name(win, name);
2680 retval = MPI_SUCCESS;
2685 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2687 int retval = MPI_SUCCESS;
2689 if (win == MPI_WIN_NULL) {
2690 retval = MPI_ERR_WIN;
2691 } else if (name == nullptr) {
2692 retval = MPI_ERR_ARG;
2694 smpi_mpi_win_get_name(win, name, len);
2699 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2700 int retval = MPI_SUCCESS;
2701 if (win == MPI_WIN_NULL) {
2702 retval = MPI_ERR_WIN;
2704 smpi_mpi_win_get_group(win, group);
2705 smpi_group_use(*group);
2711 int PMPI_Win_fence( int assert, MPI_Win win){
2714 if (win == MPI_WIN_NULL) {
2715 retval = MPI_ERR_WIN;
2717 int rank = smpi_process_index();
2718 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2719 retval = smpi_mpi_win_fence(assert, win);
2720 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2726 int PMPI_Get( 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_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)) || (!is_datatype_valid(target_datatype))) {
2742 retval = MPI_ERR_TYPE;
2744 int rank = smpi_process_index();
2746 smpi_mpi_win_get_group(win, &group);
2747 int src_traced = smpi_group_index(group, target_rank);
2748 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2750 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2751 target_datatype, win);
2753 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2759 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2760 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2763 if (win == MPI_WIN_NULL) {
2764 retval = MPI_ERR_WIN;
2765 } else if (target_rank == MPI_PROC_NULL) {
2766 retval = MPI_SUCCESS;
2767 } else if (target_rank <0){
2768 retval = MPI_ERR_RANK;
2769 } else if (target_disp <0){
2770 retval = MPI_ERR_ARG;
2771 } else if ((origin_count < 0 || target_count < 0) ||
2772 (origin_addr==nullptr && origin_count > 0)){
2773 retval = MPI_ERR_COUNT;
2774 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2775 retval = MPI_ERR_TYPE;
2777 int rank = smpi_process_index();
2779 smpi_mpi_win_get_group(win, &group);
2780 int dst_traced = smpi_group_index(group, target_rank);
2781 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2782 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2784 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2785 target_datatype, win);
2787 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2793 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2794 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2797 if (win == MPI_WIN_NULL) {
2798 retval = MPI_ERR_WIN;
2799 } else if (target_rank == MPI_PROC_NULL) {
2800 retval = MPI_SUCCESS;
2801 } else if (target_rank <0){
2802 retval = MPI_ERR_RANK;
2803 } else if (target_disp <0){
2804 retval = MPI_ERR_ARG;
2805 } else if ((origin_count < 0 || target_count < 0) ||
2806 (origin_addr==nullptr && origin_count > 0)){
2807 retval = MPI_ERR_COUNT;
2808 } else if ((!is_datatype_valid(origin_datatype)) ||
2809 (!is_datatype_valid(target_datatype))) {
2810 retval = MPI_ERR_TYPE;
2811 } else if (op == MPI_OP_NULL) {
2812 retval = MPI_ERR_OP;
2814 int rank = smpi_process_index();
2816 smpi_mpi_win_get_group(win, &group);
2817 int src_traced = smpi_group_index(group, target_rank);
2818 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2820 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2821 target_datatype, op, win);
2823 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2829 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2832 if (win == MPI_WIN_NULL) {
2833 retval = MPI_ERR_WIN;
2834 } else if (group==MPI_GROUP_NULL){
2835 retval = MPI_ERR_GROUP;
2838 int rank = smpi_process_index();
2839 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2840 retval = smpi_mpi_win_post(group,assert,win);
2841 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2847 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2850 if (win == MPI_WIN_NULL) {
2851 retval = MPI_ERR_WIN;
2852 } else if (group==MPI_GROUP_NULL){
2853 retval = MPI_ERR_GROUP;
2856 int rank = smpi_process_index();
2857 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2858 retval = smpi_mpi_win_start(group,assert,win);
2859 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2865 int PMPI_Win_complete(MPI_Win win){
2868 if (win == MPI_WIN_NULL) {
2869 retval = MPI_ERR_WIN;
2872 int rank = smpi_process_index();
2873 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2875 retval = smpi_mpi_win_complete(win);
2877 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2883 int PMPI_Win_wait(MPI_Win win){
2886 if (win == MPI_WIN_NULL) {
2887 retval = MPI_ERR_WIN;
2890 int rank = smpi_process_index();
2891 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2893 retval = smpi_mpi_win_wait(win);
2895 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2901 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2902 void *ptr = xbt_malloc(size);
2904 return MPI_ERR_NO_MEM;
2906 *static_cast<void**>(baseptr) = ptr;
2911 int PMPI_Free_mem(void *baseptr){
2916 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2919 if (datatype == MPI_DATATYPE_NULL) {
2920 retval = MPI_ERR_TYPE;
2921 } else if (name == nullptr) {
2922 retval = MPI_ERR_ARG;
2924 smpi_datatype_set_name(datatype, name);
2925 retval = MPI_SUCCESS;
2930 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2934 if (datatype == MPI_DATATYPE_NULL) {
2935 retval = MPI_ERR_TYPE;
2936 } else if (name == nullptr) {
2937 retval = MPI_ERR_ARG;
2939 smpi_datatype_get_name(datatype, name, len);
2940 retval = MPI_SUCCESS;
2945 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2946 return smpi_type_f2c(datatype);
2949 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2950 return smpi_type_c2f( datatype);
2953 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2954 return smpi_group_f2c( group);
2957 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2958 return smpi_group_c2f(group);
2961 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2962 return smpi_request_f2c(request);
2965 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2966 return smpi_request_c2f(request);
2969 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2970 return smpi_win_f2c(win);
2973 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2974 return smpi_win_c2f(win);
2977 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2978 return smpi_op_f2c(op);
2981 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2982 return smpi_op_c2f(op);
2985 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2986 return smpi_comm_f2c(comm);
2989 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2990 return smpi_comm_c2f(comm);
2993 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2994 return smpi_info_f2c(info);
2997 MPI_Fint PMPI_Info_c2f(MPI_Info info){
2998 return smpi_info_c2f(info);
3001 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3002 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3005 int PMPI_Keyval_free(int* keyval) {
3006 return smpi_comm_keyval_free(keyval);
3009 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3010 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3011 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3013 else if (comm==MPI_COMM_NULL)
3014 return MPI_ERR_COMM;
3016 return smpi_comm_attr_delete(comm, keyval);
3019 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3021 static int zero = 0;
3022 static int tag_ub = 1000000;
3023 static int last_used_code = MPI_ERR_LASTCODE;
3025 if (comm==MPI_COMM_NULL){
3027 return MPI_ERR_COMM;
3035 *static_cast<int**>(attr_value) = &zero;
3037 case MPI_UNIVERSE_SIZE:
3039 *static_cast<int**>(attr_value) = &smpi_universe_size;
3041 case MPI_LASTUSEDCODE:
3043 *static_cast<int**>(attr_value) = &last_used_code;
3047 *static_cast<int**>(attr_value) = &tag_ub;
3049 case MPI_WTIME_IS_GLOBAL:
3051 *static_cast<int**>(attr_value) = &one;
3054 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3058 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3059 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3060 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3062 else if (comm==MPI_COMM_NULL)
3063 return MPI_ERR_COMM;
3065 return smpi_comm_attr_put(comm, keyval, attr_value);
3068 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3070 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3073 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3075 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3078 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3080 return PMPI_Attr_delete(comm, comm_keyval);
3083 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3086 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3089 int PMPI_Comm_free_keyval(int* keyval) {
3090 return PMPI_Keyval_free(keyval);
3093 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3095 if (type==MPI_DATATYPE_NULL)
3096 return MPI_ERR_TYPE;
3098 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3101 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3103 if (type==MPI_DATATYPE_NULL)
3104 return MPI_ERR_TYPE;
3106 return smpi_type_attr_put(type, type_keyval, attribute_val);
3109 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3111 if (type==MPI_DATATYPE_NULL)
3112 return MPI_ERR_TYPE;
3114 return smpi_type_attr_delete(type, type_keyval);
3117 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3120 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3123 int PMPI_Type_free_keyval(int* keyval) {
3124 return smpi_type_keyval_free(keyval);
3127 int PMPI_Info_create( MPI_Info *info){
3128 if (info == nullptr)
3130 *info = xbt_new(s_smpi_mpi_info_t, 1);
3131 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3132 (*info)->refcount=1;
3136 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3137 if (info == nullptr || key == nullptr || value == nullptr)
3140 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
3144 int PMPI_Info_free( MPI_Info *info){
3145 if (info == nullptr || *info==nullptr)
3147 (*info)->refcount--;
3148 if((*info)->refcount==0){
3149 xbt_dict_free(&((*info)->info_dict));
3152 *info=MPI_INFO_NULL;
3156 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3158 if (info == nullptr || key == nullptr || valuelen <0)
3160 if (value == nullptr)
3161 return MPI_ERR_INFO_VALUE;
3162 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
3164 memset(value, 0, valuelen);
3165 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3171 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3172 if (info == nullptr || newinfo==nullptr)
3174 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3175 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3176 (*newinfo)->refcount=1;
3177 xbt_dict_cursor_t cursor = nullptr;
3180 xbt_dict_foreach(info->info_dict,cursor,key,data){
3181 xbt_dict_set((*newinfo)->info_dict, reinterpret_cast<char*>(key), xbt_strdup(reinterpret_cast<char*>(data)), nullptr);
3186 int PMPI_Info_delete(MPI_Info info, char *key){
3187 if (info == nullptr || key==nullptr)
3190 xbt_dict_remove(info->info_dict, key);
3193 return MPI_ERR_INFO_NOKEY;
3198 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3199 if (info == nullptr || nkeys==nullptr)
3201 *nkeys=xbt_dict_size(info->info_dict);
3205 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3206 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
3209 xbt_dict_cursor_t cursor = nullptr;
3213 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3215 strncpy(key,keyn,strlen(keyn)+1);
3216 xbt_dict_cursor_free(&cursor);
3224 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3226 if (info == nullptr || key == nullptr || valuelen==nullptr)
3228 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3230 *valuelen=strlen(tmpvalue);
3236 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3237 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3239 if(!is_datatype_valid(type))
3240 return MPI_ERR_TYPE;
3241 if(comm==MPI_COMM_NULL)
3242 return MPI_ERR_COMM;
3243 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3246 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3247 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3249 if(!is_datatype_valid(type))
3250 return MPI_ERR_TYPE;
3251 if(comm==MPI_COMM_NULL)
3252 return MPI_ERR_COMM;
3253 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3256 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3259 if(!is_datatype_valid(datatype))
3260 return MPI_ERR_TYPE;
3261 if(comm==MPI_COMM_NULL)
3262 return MPI_ERR_COMM;
3264 *size=incount*smpi_datatype_size(datatype);