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_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out)
861 if (comm_out == nullptr) {
862 retval = MPI_ERR_ARG;
863 } else if (comm == MPI_COMM_NULL) {
864 retval = MPI_ERR_COMM;
866 retval = MPI_Comm_create(comm, group, comm_out);
873 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
878 if (request == nullptr) {
879 retval = MPI_ERR_ARG;
880 } else if (comm == MPI_COMM_NULL) {
881 retval = MPI_ERR_COMM;
882 } else if (!is_datatype_valid(datatype)) {
883 retval = MPI_ERR_TYPE;
884 } else if (dst == MPI_PROC_NULL) {
885 retval = MPI_SUCCESS;
887 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
888 retval = MPI_SUCCESS;
891 if (retval != MPI_SUCCESS && request != nullptr)
892 *request = MPI_REQUEST_NULL;
896 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
901 if (request == nullptr) {
902 retval = MPI_ERR_ARG;
903 } else if (comm == MPI_COMM_NULL) {
904 retval = MPI_ERR_COMM;
905 } else if (!is_datatype_valid(datatype)) {
906 retval = MPI_ERR_TYPE;
907 } else if (src == MPI_PROC_NULL) {
908 retval = MPI_SUCCESS;
910 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
911 retval = MPI_SUCCESS;
914 if (retval != MPI_SUCCESS && request != nullptr)
915 *request = MPI_REQUEST_NULL;
919 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
924 if (request == nullptr) {
925 retval = MPI_ERR_ARG;
926 } else if (comm == MPI_COMM_NULL) {
927 retval = MPI_ERR_COMM;
928 } else if (!is_datatype_valid(datatype)) {
929 retval = MPI_ERR_TYPE;
930 } else if (dst == MPI_PROC_NULL) {
931 retval = MPI_SUCCESS;
933 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
934 retval = MPI_SUCCESS;
937 if (retval != MPI_SUCCESS && request != nullptr)
938 *request = MPI_REQUEST_NULL;
942 int PMPI_Start(MPI_Request * request)
947 if (request == nullptr || *request == MPI_REQUEST_NULL) {
948 retval = MPI_ERR_REQUEST;
950 smpi_mpi_start(*request);
951 retval = MPI_SUCCESS;
957 int PMPI_Startall(int count, MPI_Request * requests)
962 if (requests == nullptr) {
963 retval = MPI_ERR_ARG;
965 retval = MPI_SUCCESS;
966 for (i = 0 ; i < count ; i++) {
967 if(requests[i] == MPI_REQUEST_NULL) {
968 retval = MPI_ERR_REQUEST;
971 if(retval != MPI_ERR_REQUEST) {
972 smpi_mpi_startall(count, requests);
979 int PMPI_Request_free(MPI_Request * request)
984 if (*request == MPI_REQUEST_NULL) {
985 retval = MPI_ERR_ARG;
987 smpi_mpi_request_free(request);
988 retval = MPI_SUCCESS;
994 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
1000 if (request == nullptr) {
1001 retval = MPI_ERR_ARG;
1002 } else if (comm == MPI_COMM_NULL) {
1003 retval = MPI_ERR_COMM;
1004 } else if (src == MPI_PROC_NULL) {
1005 *request = MPI_REQUEST_NULL;
1006 retval = MPI_SUCCESS;
1007 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1008 retval = MPI_ERR_RANK;
1009 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1010 retval = MPI_ERR_COUNT;
1011 } else if (!is_datatype_valid(datatype)) {
1012 retval = MPI_ERR_TYPE;
1013 } else if(tag<0 && tag != MPI_ANY_TAG){
1014 retval = MPI_ERR_TAG;
1017 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1018 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1020 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1021 extra->type = TRACING_IRECV;
1022 extra->src = src_traced;
1025 extra->datatype1 = encode_datatype(datatype, &known);
1026 int dt_size_send = 1;
1028 dt_size_send = smpi_datatype_size(datatype);
1029 extra->send_size = count*dt_size_send;
1030 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1032 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1033 retval = MPI_SUCCESS;
1035 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1036 (*request)->recv = 1;
1040 if (retval != MPI_SUCCESS && request != nullptr)
1041 *request = MPI_REQUEST_NULL;
1046 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1051 if (request == nullptr) {
1052 retval = MPI_ERR_ARG;
1053 } else if (comm == MPI_COMM_NULL) {
1054 retval = MPI_ERR_COMM;
1055 } else if (dst == MPI_PROC_NULL) {
1056 *request = MPI_REQUEST_NULL;
1057 retval = MPI_SUCCESS;
1058 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1059 retval = MPI_ERR_RANK;
1060 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1061 retval = MPI_ERR_COUNT;
1062 } else if (!is_datatype_valid(datatype)) {
1063 retval = MPI_ERR_TYPE;
1064 } else if(tag<0 && tag != MPI_ANY_TAG){
1065 retval = MPI_ERR_TAG;
1068 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1069 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1070 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1071 extra->type = TRACING_ISEND;
1073 extra->dst = dst_traced;
1075 extra->datatype1 = encode_datatype(datatype, &known);
1076 int dt_size_send = 1;
1078 dt_size_send = smpi_datatype_size(datatype);
1079 extra->send_size = count*dt_size_send;
1080 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1081 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1083 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1084 retval = MPI_SUCCESS;
1086 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1087 (*request)->send = 1;
1091 if (retval != MPI_SUCCESS && request!=nullptr)
1092 *request = MPI_REQUEST_NULL;
1096 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
1101 if (request == nullptr) {
1102 retval = MPI_ERR_ARG;
1103 } else if (comm == MPI_COMM_NULL) {
1104 retval = MPI_ERR_COMM;
1105 } else if (dst == MPI_PROC_NULL) {
1106 *request = MPI_REQUEST_NULL;
1107 retval = MPI_SUCCESS;
1108 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1109 retval = MPI_ERR_RANK;
1110 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
1111 retval = MPI_ERR_COUNT;
1112 } else if (!is_datatype_valid(datatype)) {
1113 retval = MPI_ERR_TYPE;
1114 } else if(tag<0 && tag != MPI_ANY_TAG){
1115 retval = MPI_ERR_TAG;
1118 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1119 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1120 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1121 extra->type = TRACING_ISSEND;
1123 extra->dst = dst_traced;
1125 extra->datatype1 = encode_datatype(datatype, &known);
1126 int dt_size_send = 1;
1128 dt_size_send = smpi_datatype_size(datatype);
1129 extra->send_size = count*dt_size_send;
1130 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1131 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1133 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1134 retval = MPI_SUCCESS;
1136 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1137 (*request)->send = 1;
1141 if (retval != MPI_SUCCESS && request!=nullptr)
1142 *request = MPI_REQUEST_NULL;
1146 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1151 if (comm == MPI_COMM_NULL) {
1152 retval = MPI_ERR_COMM;
1153 } else if (src == MPI_PROC_NULL) {
1154 smpi_empty_status(status);
1155 status->MPI_SOURCE = MPI_PROC_NULL;
1156 retval = MPI_SUCCESS;
1157 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1158 retval = MPI_ERR_RANK;
1159 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1160 retval = MPI_ERR_COUNT;
1161 } else if (!is_datatype_valid(datatype)) {
1162 retval = MPI_ERR_TYPE;
1163 } else if(tag<0 && tag != MPI_ANY_TAG){
1164 retval = MPI_ERR_TAG;
1166 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1167 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1168 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1169 extra->type = TRACING_RECV;
1170 extra->src = src_traced;
1173 extra->datatype1 = encode_datatype(datatype, &known);
1174 int dt_size_send = 1;
1176 dt_size_send = smpi_datatype_size(datatype);
1177 extra->send_size = count*dt_size_send;
1178 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1180 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1181 retval = MPI_SUCCESS;
1183 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1184 if(status!=MPI_STATUS_IGNORE){
1185 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1186 if (!TRACE_smpi_view_internals()) {
1187 TRACE_smpi_recv(rank, src_traced, rank, tag);
1190 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1197 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1203 if (comm == MPI_COMM_NULL) {
1204 retval = MPI_ERR_COMM;
1205 } else if (dst == MPI_PROC_NULL) {
1206 retval = MPI_SUCCESS;
1207 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1208 retval = MPI_ERR_RANK;
1209 } else if ((count < 0) || (buf == nullptr && count > 0)) {
1210 retval = MPI_ERR_COUNT;
1211 } else if (!is_datatype_valid(datatype)) {
1212 retval = MPI_ERR_TYPE;
1213 } else if(tag < 0 && tag != MPI_ANY_TAG){
1214 retval = MPI_ERR_TAG;
1216 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1217 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1218 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1219 extra->type = TRACING_SEND;
1221 extra->dst = dst_traced;
1223 extra->datatype1 = encode_datatype(datatype, &known);
1224 int dt_size_send = 1;
1226 dt_size_send = smpi_datatype_size(datatype);
1228 extra->send_size = count*dt_size_send;
1229 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1230 if (!TRACE_smpi_view_internals()) {
1231 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1234 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1235 retval = MPI_SUCCESS;
1237 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1244 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1249 if (comm == MPI_COMM_NULL) {
1250 retval = MPI_ERR_COMM;
1251 } else if (dst == MPI_PROC_NULL) {
1252 retval = MPI_SUCCESS;
1253 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1254 retval = MPI_ERR_RANK;
1255 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1256 retval = MPI_ERR_COUNT;
1257 } else if (!is_datatype_valid(datatype)){
1258 retval = MPI_ERR_TYPE;
1259 } else if(tag<0 && tag != MPI_ANY_TAG){
1260 retval = MPI_ERR_TAG;
1262 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1263 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1264 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1265 extra->type = TRACING_SSEND;
1267 extra->dst = dst_traced;
1269 extra->datatype1 = encode_datatype(datatype, &known);
1270 int dt_size_send = 1;
1272 dt_size_send = smpi_datatype_size(datatype);
1274 extra->send_size = count*dt_size_send;
1275 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1276 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1278 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1279 retval = MPI_SUCCESS;
1281 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1288 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1289 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1295 if (comm == MPI_COMM_NULL) {
1296 retval = MPI_ERR_COMM;
1297 } else if (!is_datatype_valid(sendtype)
1298 || !is_datatype_valid(recvtype)) {
1299 retval = MPI_ERR_TYPE;
1300 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1301 smpi_empty_status(status);
1302 status->MPI_SOURCE = MPI_PROC_NULL;
1303 retval = MPI_SUCCESS;
1304 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1305 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1306 retval = MPI_ERR_RANK;
1307 } else if ((sendcount < 0 || recvcount<0) ||
1308 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1309 retval = MPI_ERR_COUNT;
1310 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1311 retval = MPI_ERR_TAG;
1314 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1315 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1316 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1317 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1318 extra->type = TRACING_SENDRECV;
1319 extra->src = src_traced;
1320 extra->dst = dst_traced;
1322 extra->datatype1 = encode_datatype(sendtype, &known);
1323 int dt_size_send = 1;
1325 dt_size_send = smpi_datatype_size(sendtype);
1326 extra->send_size = sendcount*dt_size_send;
1327 extra->datatype2 = encode_datatype(recvtype, &known);
1328 int dt_size_recv = 1;
1330 dt_size_recv = smpi_datatype_size(recvtype);
1331 extra->recv_size = recvcount*dt_size_recv;
1333 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1334 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1336 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1337 recvcount, recvtype, src, recvtag, comm, status);
1338 retval = MPI_SUCCESS;
1340 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1341 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1348 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1349 MPI_Comm comm, MPI_Status * status)
1353 if (!is_datatype_valid(datatype)) {
1354 retval = MPI_ERR_TYPE;
1355 } else if (count < 0) {
1356 retval = MPI_ERR_COUNT;
1358 int size = smpi_datatype_get_extent(datatype) * count;
1359 recvbuf = xbt_new0(char, size);
1360 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1361 if(retval==MPI_SUCCESS){
1362 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1370 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1374 if (request == nullptr || flag == nullptr) {
1375 retval = MPI_ERR_ARG;
1376 } else if (*request == MPI_REQUEST_NULL) {
1378 smpi_empty_status(status);
1379 retval = MPI_SUCCESS;
1381 int rank = ((*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1383 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1384 extra->type = TRACING_TEST;
1385 TRACE_smpi_testing_in(rank, extra);
1387 *flag = smpi_mpi_test(request, status);
1389 TRACE_smpi_testing_out(rank);
1390 retval = MPI_SUCCESS;
1396 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1401 if (index == nullptr || flag == nullptr) {
1402 retval = MPI_ERR_ARG;
1404 *flag = smpi_mpi_testany(count, requests, index, status);
1405 retval = MPI_SUCCESS;
1411 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1416 if (flag == nullptr) {
1417 retval = MPI_ERR_ARG;
1419 *flag = smpi_mpi_testall(count, requests, statuses);
1420 retval = MPI_SUCCESS;
1426 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1430 if (status == nullptr) {
1431 retval = MPI_ERR_ARG;
1432 } else if (comm == MPI_COMM_NULL) {
1433 retval = MPI_ERR_COMM;
1434 } else if (source == MPI_PROC_NULL) {
1435 smpi_empty_status(status);
1436 status->MPI_SOURCE = MPI_PROC_NULL;
1437 retval = MPI_SUCCESS;
1439 smpi_mpi_probe(source, tag, comm, status);
1440 retval = MPI_SUCCESS;
1446 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1450 if ((flag == nullptr) || (status == nullptr)) {
1451 retval = MPI_ERR_ARG;
1452 } else if (comm == MPI_COMM_NULL) {
1453 retval = MPI_ERR_COMM;
1454 } else if (source == MPI_PROC_NULL) {
1456 smpi_empty_status(status);
1457 status->MPI_SOURCE = MPI_PROC_NULL;
1458 retval = MPI_SUCCESS;
1460 smpi_mpi_iprobe(source, tag, comm, flag, status);
1461 retval = MPI_SUCCESS;
1467 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1473 smpi_empty_status(status);
1475 if (request == nullptr) {
1476 retval = MPI_ERR_ARG;
1477 } else if (*request == MPI_REQUEST_NULL) {
1478 retval = MPI_SUCCESS;
1481 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1483 int src_traced = (*request)->src;
1484 int dst_traced = (*request)->dst;
1485 int tag_traced= (*request)->tag;
1486 MPI_Comm comm = (*request)->comm;
1487 int is_wait_for_receive = (*request)->recv;
1488 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1489 extra->type = TRACING_WAIT;
1490 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1492 smpi_mpi_wait(request, status);
1493 retval = MPI_SUCCESS;
1495 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1496 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1497 if (is_wait_for_receive) {
1498 if(src_traced==MPI_ANY_SOURCE)
1499 src_traced = (status!=MPI_STATUS_IGNORE) ?
1500 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1502 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1510 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1512 if (index == nullptr)
1516 //save requests information for tracing
1525 savedvalstype* savedvals=nullptr;
1527 savedvals = xbt_new0(savedvalstype, count);
1529 for (i = 0; i < count; i++) {
1530 MPI_Request req = requests[i]; //already received requests are no longer valid
1532 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1535 int rank_traced = smpi_process_index();
1536 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1537 extra->type = TRACING_WAITANY;
1538 extra->send_size=count;
1539 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1541 *index = smpi_mpi_waitany(count, requests, status);
1543 if(*index!=MPI_UNDEFINED){
1544 int src_traced = savedvals[*index].src;
1545 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1546 int dst_traced = savedvals[*index].dst;
1547 int is_wait_for_receive = savedvals[*index].recv;
1548 if (is_wait_for_receive) {
1549 if(savedvals[*index].src==MPI_ANY_SOURCE)
1550 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1551 smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE) : savedvals[*index].src;
1552 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1554 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1556 xbt_free(savedvals);
1562 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1565 //save information from requests
1575 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1577 for (i = 0; i < count; i++) {
1578 MPI_Request req = requests[i];
1579 if(req!=MPI_REQUEST_NULL){
1580 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1582 savedvals[i].valid=0;
1585 int rank_traced = smpi_process_index();
1586 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1587 extra->type = TRACING_WAITALL;
1588 extra->send_size=count;
1589 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1591 int retval = smpi_mpi_waitall(count, requests, status);
1593 for (i = 0; i < count; i++) {
1594 if(savedvals[i].valid){
1595 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1596 int src_traced = savedvals[i].src;
1597 int dst_traced = savedvals[i].dst;
1598 int is_wait_for_receive = savedvals[i].recv;
1599 if (is_wait_for_receive) {
1600 if(src_traced==MPI_ANY_SOURCE)
1601 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1602 smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
1603 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1607 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1608 xbt_free(savedvals);
1614 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1619 if (outcount == nullptr) {
1620 retval = MPI_ERR_ARG;
1622 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1623 retval = MPI_SUCCESS;
1629 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1634 if (outcount == nullptr) {
1635 retval = MPI_ERR_ARG;
1637 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1638 retval = MPI_SUCCESS;
1645 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1651 if (comm == MPI_COMM_NULL) {
1652 retval = MPI_ERR_COMM;
1653 } else if (!is_datatype_valid(datatype)) {
1654 retval = MPI_ERR_ARG;
1656 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1657 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1659 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1660 extra->type = TRACING_BCAST;
1661 extra->root = root_traced;
1663 extra->datatype1 = encode_datatype(datatype, &known);
1664 int dt_size_send = 1;
1666 dt_size_send = smpi_datatype_size(datatype);
1667 extra->send_size = count*dt_size_send;
1668 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1669 if(smpi_comm_size(comm)>1)
1670 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1671 retval = MPI_SUCCESS;
1673 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1680 int PMPI_Barrier(MPI_Comm comm)
1686 if (comm == MPI_COMM_NULL) {
1687 retval = MPI_ERR_COMM;
1689 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1690 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1691 extra->type = TRACING_BARRIER;
1692 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1694 mpi_coll_barrier_fun(comm);
1695 retval = MPI_SUCCESS;
1697 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1704 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1705 int root, MPI_Comm comm)
1711 if (comm == MPI_COMM_NULL) {
1712 retval = MPI_ERR_COMM;
1713 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1714 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1715 retval = MPI_ERR_TYPE;
1716 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1717 retval = MPI_ERR_COUNT;
1720 char* sendtmpbuf = static_cast<char*>(sendbuf);
1721 int sendtmpcount = sendcount;
1722 MPI_Datatype sendtmptype = sendtype;
1723 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1725 sendtmptype=recvtype;
1727 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1728 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1729 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1730 extra->type = TRACING_GATHER;
1731 extra->root = root_traced;
1733 extra->datatype1 = encode_datatype(sendtmptype, &known);
1734 int dt_size_send = 1;
1736 dt_size_send = smpi_datatype_size(sendtmptype);
1737 extra->send_size = sendtmpcount*dt_size_send;
1738 extra->datatype2 = encode_datatype(recvtype, &known);
1739 int dt_size_recv = 1;
1740 if((smpi_comm_rank(comm)==root) && known==0)
1741 dt_size_recv = smpi_datatype_size(recvtype);
1742 extra->recv_size = recvcount*dt_size_recv;
1744 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1746 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1748 retval = MPI_SUCCESS;
1749 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1756 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1757 MPI_Datatype recvtype, int root, MPI_Comm comm)
1763 if (comm == MPI_COMM_NULL) {
1764 retval = MPI_ERR_COMM;
1765 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1766 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1767 retval = MPI_ERR_TYPE;
1768 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1769 retval = MPI_ERR_COUNT;
1770 } else if (recvcounts == nullptr || displs == nullptr) {
1771 retval = MPI_ERR_ARG;
1773 char* sendtmpbuf = static_cast<char*>(sendbuf);
1774 int sendtmpcount = sendcount;
1775 MPI_Datatype sendtmptype = sendtype;
1776 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1778 sendtmptype=recvtype;
1781 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1782 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1784 int size = smpi_comm_size(comm);
1785 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1786 extra->type = TRACING_GATHERV;
1787 extra->num_processes = size;
1788 extra->root = root_traced;
1790 extra->datatype1 = encode_datatype(sendtmptype, &known);
1791 int dt_size_send = 1;
1793 dt_size_send = smpi_datatype_size(sendtype);
1794 extra->send_size = sendtmpcount*dt_size_send;
1795 extra->datatype2 = encode_datatype(recvtype, &known);
1796 int dt_size_recv = 1;
1798 dt_size_recv = smpi_datatype_size(recvtype);
1799 if((smpi_comm_rank(comm)==root)){
1800 extra->recvcounts= xbt_new(int,size);
1801 for(i=0; i< size; i++)//copy data to avoid bad free
1802 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1804 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1806 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1807 retval = MPI_SUCCESS;
1808 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1815 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1816 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1822 if (comm == MPI_COMM_NULL) {
1823 retval = MPI_ERR_COMM;
1824 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1825 (recvtype == MPI_DATATYPE_NULL)){
1826 retval = MPI_ERR_TYPE;
1827 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1829 retval = MPI_ERR_COUNT;
1831 if(sendbuf == MPI_IN_PLACE) {
1832 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1833 sendcount=recvcount;
1836 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1837 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1838 extra->type = TRACING_ALLGATHER;
1840 extra->datatype1 = encode_datatype(sendtype, &known);
1841 int dt_size_send = 1;
1843 dt_size_send = smpi_datatype_size(sendtype);
1844 extra->send_size = sendcount*dt_size_send;
1845 extra->datatype2 = encode_datatype(recvtype, &known);
1846 int dt_size_recv = 1;
1848 dt_size_recv = smpi_datatype_size(recvtype);
1849 extra->recv_size = recvcount*dt_size_recv;
1851 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1853 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1854 retval = MPI_SUCCESS;
1855 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1861 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1862 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1868 if (comm == MPI_COMM_NULL) {
1869 retval = MPI_ERR_COMM;
1870 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1871 (recvtype == MPI_DATATYPE_NULL)){
1872 retval = MPI_ERR_TYPE;
1873 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1874 retval = MPI_ERR_COUNT;
1875 } else if (recvcounts == nullptr || displs == nullptr) {
1876 retval = MPI_ERR_ARG;
1879 if(sendbuf == MPI_IN_PLACE) {
1880 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1881 sendcount=recvcounts[smpi_comm_rank(comm)];
1884 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1886 int size = smpi_comm_size(comm);
1887 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1888 extra->type = TRACING_ALLGATHERV;
1889 extra->num_processes = size;
1891 extra->datatype1 = encode_datatype(sendtype, &known);
1892 int dt_size_send = 1;
1894 dt_size_send = smpi_datatype_size(sendtype);
1895 extra->send_size = sendcount*dt_size_send;
1896 extra->datatype2 = encode_datatype(recvtype, &known);
1897 int dt_size_recv = 1;
1899 dt_size_recv = smpi_datatype_size(recvtype);
1900 extra->recvcounts= xbt_new(int, size);
1901 for(i=0; i< size; i++)//copy data to avoid bad free
1902 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1904 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1906 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1907 retval = MPI_SUCCESS;
1908 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1915 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1916 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1922 if (comm == MPI_COMM_NULL) {
1923 retval = MPI_ERR_COMM;
1924 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1925 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1926 retval = MPI_ERR_TYPE;
1927 } else if ((sendbuf == recvbuf) ||
1928 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1929 retval = MPI_ERR_BUFFER;
1932 if (recvbuf == MPI_IN_PLACE) {
1934 recvcount=sendcount;
1936 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1937 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1938 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1939 extra->type = TRACING_SCATTER;
1940 extra->root = root_traced;
1942 extra->datatype1 = encode_datatype(sendtype, &known);
1943 int dt_size_send = 1;
1944 if((smpi_comm_rank(comm)==root) && known==0)
1945 dt_size_send = smpi_datatype_size(sendtype);
1946 extra->send_size = sendcount*dt_size_send;
1947 extra->datatype2 = encode_datatype(recvtype, &known);
1948 int dt_size_recv = 1;
1950 dt_size_recv = smpi_datatype_size(recvtype);
1951 extra->recv_size = recvcount*dt_size_recv;
1952 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1954 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1955 retval = MPI_SUCCESS;
1956 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1963 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1964 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1970 if (comm == MPI_COMM_NULL) {
1971 retval = MPI_ERR_COMM;
1972 } else if (sendcounts == nullptr || displs == nullptr) {
1973 retval = MPI_ERR_ARG;
1974 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1975 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1976 retval = MPI_ERR_TYPE;
1978 if (recvbuf == MPI_IN_PLACE) {
1980 recvcount=sendcounts[smpi_comm_rank(comm)];
1982 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1983 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1985 int size = smpi_comm_size(comm);
1986 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1987 extra->type = TRACING_SCATTERV;
1988 extra->num_processes = size;
1989 extra->root = root_traced;
1991 extra->datatype1 = encode_datatype(sendtype, &known);
1992 int dt_size_send = 1;
1994 dt_size_send = smpi_datatype_size(sendtype);
1995 if((smpi_comm_rank(comm)==root)){
1996 extra->sendcounts= xbt_new(int, size);
1997 for(i=0; i< size; i++)//copy data to avoid bad free
1998 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2000 extra->datatype2 = encode_datatype(recvtype, &known);
2001 int dt_size_recv = 1;
2003 dt_size_recv = smpi_datatype_size(recvtype);
2004 extra->recv_size = recvcount*dt_size_recv;
2005 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2007 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
2009 retval = MPI_SUCCESS;
2010 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2017 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2023 if (comm == MPI_COMM_NULL) {
2024 retval = MPI_ERR_COMM;
2025 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2026 retval = MPI_ERR_ARG;
2028 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2029 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2030 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2031 extra->type = TRACING_REDUCE;
2033 extra->datatype1 = encode_datatype(datatype, &known);
2034 int dt_size_send = 1;
2036 dt_size_send = smpi_datatype_size(datatype);
2037 extra->send_size = count*dt_size_send;
2038 extra->root = root_traced;
2040 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2042 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2044 retval = MPI_SUCCESS;
2045 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2052 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2056 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2057 retval = MPI_ERR_ARG;
2059 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2066 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2072 if (comm == MPI_COMM_NULL) {
2073 retval = MPI_ERR_COMM;
2074 } else if (!is_datatype_valid(datatype)) {
2075 retval = MPI_ERR_TYPE;
2076 } else if (op == MPI_OP_NULL) {
2077 retval = MPI_ERR_OP;
2080 char* sendtmpbuf = static_cast<char*>(sendbuf);
2081 if( sendbuf == MPI_IN_PLACE ) {
2082 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
2083 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2085 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2086 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2087 extra->type = TRACING_ALLREDUCE;
2089 extra->datatype1 = encode_datatype(datatype, &known);
2090 int dt_size_send = 1;
2092 dt_size_send = smpi_datatype_size(datatype);
2093 extra->send_size = count*dt_size_send;
2095 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2097 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2099 if( sendbuf == MPI_IN_PLACE )
2100 xbt_free(sendtmpbuf);
2102 retval = MPI_SUCCESS;
2103 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2110 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2116 if (comm == MPI_COMM_NULL) {
2117 retval = MPI_ERR_COMM;
2118 } else if (!is_datatype_valid(datatype)) {
2119 retval = MPI_ERR_TYPE;
2120 } else if (op == MPI_OP_NULL) {
2121 retval = MPI_ERR_OP;
2123 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2124 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2125 extra->type = TRACING_SCAN;
2127 extra->datatype1 = encode_datatype(datatype, &known);
2128 int dt_size_send = 1;
2130 dt_size_send = smpi_datatype_size(datatype);
2131 extra->send_size = count*dt_size_send;
2133 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2135 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2137 retval = MPI_SUCCESS;
2138 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2145 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2150 if (comm == MPI_COMM_NULL) {
2151 retval = MPI_ERR_COMM;
2152 } else if (!is_datatype_valid(datatype)) {
2153 retval = MPI_ERR_TYPE;
2154 } else if (op == MPI_OP_NULL) {
2155 retval = MPI_ERR_OP;
2157 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2158 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2159 extra->type = TRACING_EXSCAN;
2161 extra->datatype1 = encode_datatype(datatype, &known);
2162 int dt_size_send = 1;
2164 dt_size_send = smpi_datatype_size(datatype);
2165 extra->send_size = count*dt_size_send;
2166 void * sendtmpbuf = sendbuf;
2167 if(sendbuf==MPI_IN_PLACE){
2168 sendtmpbuf= static_cast<void*>(xbt_malloc(count*smpi_datatype_size(datatype)));
2169 memcpy(sendtmpbuf,recvbuf, count*smpi_datatype_size(datatype));
2171 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2173 smpi_mpi_exscan(sendtmpbuf, recvbuf, count, datatype, op, comm);
2174 retval = MPI_SUCCESS;
2175 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2176 if(sendbuf==MPI_IN_PLACE)
2177 xbt_free(sendtmpbuf);
2184 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2189 if (comm == MPI_COMM_NULL) {
2190 retval = MPI_ERR_COMM;
2191 } else if (!is_datatype_valid(datatype)) {
2192 retval = MPI_ERR_TYPE;
2193 } else if (op == MPI_OP_NULL) {
2194 retval = MPI_ERR_OP;
2195 } else if (recvcounts == nullptr) {
2196 retval = MPI_ERR_ARG;
2198 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2200 int size = smpi_comm_size(comm);
2201 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2202 extra->type = TRACING_REDUCE_SCATTER;
2203 extra->num_processes = size;
2205 extra->datatype1 = encode_datatype(datatype, &known);
2206 int dt_size_send = 1;
2208 dt_size_send = smpi_datatype_size(datatype);
2209 extra->send_size = 0;
2210 extra->recvcounts= xbt_new(int, size);
2212 for(i=0; i< size; i++){//copy data to avoid bad free
2213 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2214 totalcount+= recvcounts[i];
2216 void* sendtmpbuf=sendbuf;
2217 if(sendbuf==MPI_IN_PLACE){
2218 sendtmpbuf= static_cast<void*>(xbt_malloc(totalcount*smpi_datatype_size(datatype)));
2219 memcpy(sendtmpbuf,recvbuf, totalcount*smpi_datatype_size(datatype));
2222 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2224 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2225 retval = MPI_SUCCESS;
2226 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2228 if(sendbuf==MPI_IN_PLACE)
2229 xbt_free(sendtmpbuf);
2236 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2237 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2242 if (comm == MPI_COMM_NULL) {
2243 retval = MPI_ERR_COMM;
2244 } else if (!is_datatype_valid(datatype)) {
2245 retval = MPI_ERR_TYPE;
2246 } else if (op == MPI_OP_NULL) {
2247 retval = MPI_ERR_OP;
2248 } else if (recvcount < 0) {
2249 retval = MPI_ERR_ARG;
2251 int count=smpi_comm_size(comm);
2253 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2254 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2255 extra->type = TRACING_REDUCE_SCATTER;
2256 extra->num_processes = count;
2258 extra->datatype1 = encode_datatype(datatype, &known);
2259 int dt_size_send = 1;
2261 dt_size_send = smpi_datatype_size(datatype);
2262 extra->send_size = 0;
2263 extra->recvcounts= xbt_new(int, count);
2264 for(i=0; i< count; i++)//copy data to avoid bad free
2265 extra->recvcounts[i] = recvcount*dt_size_send;
2266 void* sendtmpbuf=sendbuf;
2267 if(sendbuf==MPI_IN_PLACE){
2268 sendtmpbuf= static_cast<void*>(xbt_malloc(recvcount*count*smpi_datatype_size(datatype)));
2269 memcpy(sendtmpbuf,recvbuf, recvcount*count*smpi_datatype_size(datatype));
2272 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2274 int* recvcounts=static_cast<int*>(xbt_malloc(count*sizeof(int)));
2275 for (i=0; i<count;i++)
2276 recvcounts[i]=recvcount;
2277 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2278 xbt_free(recvcounts);
2279 retval = MPI_SUCCESS;
2281 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2283 if(sendbuf==MPI_IN_PLACE)
2284 xbt_free(sendtmpbuf);
2291 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2292 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2298 if (comm == MPI_COMM_NULL) {
2299 retval = MPI_ERR_COMM;
2300 } else if ((sendbuf != MPI_IN_PLACE && sendtype == MPI_DATATYPE_NULL)
2301 || recvtype == MPI_DATATYPE_NULL) {
2302 retval = MPI_ERR_TYPE;
2304 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2305 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2306 extra->type = TRACING_ALLTOALL;
2308 void* sendtmpbuf = static_cast<char*>(sendbuf);
2309 int sendtmpcount = sendcount;
2310 MPI_Datatype sendtmptype = sendtype;
2311 if( sendbuf == MPI_IN_PLACE ) {
2312 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount*smpi_comm_size(comm)*smpi_datatype_size(recvtype)));
2313 memcpy(sendtmpbuf,recvbuf, recvcount*smpi_comm_size(comm)*smpi_datatype_size(recvtype));
2314 sendtmpcount = recvcount;
2315 sendtmptype = recvtype;
2319 extra->datatype1 = encode_datatype(sendtmptype, &known);
2321 extra->send_size = sendtmpcount*smpi_datatype_size(sendtmptype);
2323 extra->send_size = sendtmpcount;
2324 extra->datatype2 = encode_datatype(recvtype, &known);
2326 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2328 extra->recv_size = recvcount;
2330 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2332 retval = mpi_coll_alltoall_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, comm);
2334 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2336 if( sendbuf == MPI_IN_PLACE )
2337 xbt_free(sendtmpbuf);
2344 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2345 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2351 if (comm == MPI_COMM_NULL) {
2352 retval = MPI_ERR_COMM;
2353 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2354 retval = MPI_ERR_TYPE;
2355 } else if ((sendbuf!= MPI_IN_PLACE && (sendcounts == nullptr || senddisps == nullptr)) || recvcounts == nullptr || recvdisps == nullptr) {
2356 retval = MPI_ERR_ARG;
2358 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2360 int size = smpi_comm_size(comm);
2361 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2362 extra->type = TRACING_ALLTOALLV;
2363 extra->send_size = 0;
2364 extra->recv_size = 0;
2365 extra->recvcounts= xbt_new(int, size);
2366 extra->sendcounts= xbt_new(int, size);
2368 int dt_size_recv = 1;
2369 extra->datatype2 = encode_datatype(recvtype, &known);
2370 dt_size_recv = smpi_datatype_size(recvtype);
2372 void* sendtmpbuf = static_cast<char*>(sendbuf);
2373 int * sendtmpcounts = sendcounts;
2374 int *sendtmpdisps = senddisps;
2375 MPI_Datatype sendtmptype = sendtype;
2377 for(i=0; i< size; i++){//copy data to avoid bad free
2378 extra->recv_size += recvcounts[i]*dt_size_recv;
2379 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2380 if (((recvdisps[i]+recvcounts[i])*dt_size_recv) > maxsize)
2381 maxsize=(recvdisps[i]+recvcounts[i])*dt_size_recv;
2384 if( sendbuf == MPI_IN_PLACE ) {
2385 sendtmpbuf = static_cast<void*>(xbt_malloc(maxsize));
2386 memcpy(sendtmpbuf,recvbuf, maxsize);
2387 sendtmpcounts= static_cast<int*>(xbt_malloc(size*sizeof(int)));
2388 memcpy(sendtmpcounts,recvcounts, size*sizeof(int));
2389 sendtmpdisps= static_cast<int*>(xbt_malloc(size*sizeof(int)));
2390 memcpy(sendtmpdisps,recvdisps, size*sizeof(int));
2391 sendtmptype=recvtype;
2394 extra->datatype1 = encode_datatype(sendtmptype, &known);
2395 int dt_size_send = 1;
2396 dt_size_send = smpi_datatype_size(sendtmptype);
2398 for(i=0; i< size; i++){//copy data to avoid bad free
2399 extra->send_size += sendtmpcounts[i]*dt_size_send;
2400 extra->sendcounts[i] = sendtmpcounts[i]*dt_size_send;
2402 extra->num_processes = size;
2403 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2404 retval = mpi_coll_alltoallv_fun(sendtmpbuf, sendtmpcounts, sendtmpdisps, sendtmptype, recvbuf, recvcounts, recvdisps, recvtype,
2406 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2408 if( sendbuf == MPI_IN_PLACE ) {
2409 xbt_free(sendtmpbuf);
2410 xbt_free(sendtmpcounts);
2411 xbt_free(sendtmpdisps);
2420 int PMPI_Get_processor_name(char *name, int *resultlen)
2422 int retval = MPI_SUCCESS;
2424 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2425 ? strlen(SIMIX_host_self()->cname()) + 1
2426 : MPI_MAX_PROCESSOR_NAME - 1);
2427 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2432 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2434 int retval = MPI_SUCCESS;
2437 if (status == nullptr || count == nullptr) {
2438 retval = MPI_ERR_ARG;
2439 } else if (!is_datatype_valid(datatype)) {
2440 retval = MPI_ERR_TYPE;
2442 size = smpi_datatype_size(datatype);
2445 } else if (status->count % size != 0) {
2446 retval = MPI_UNDEFINED;
2448 *count = smpi_mpi_get_count(status, datatype);
2454 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2457 if (old_type == MPI_DATATYPE_NULL) {
2458 retval = MPI_ERR_TYPE;
2459 } else if (count<0){
2460 retval = MPI_ERR_COUNT;
2462 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2467 int PMPI_Type_commit(MPI_Datatype* datatype) {
2470 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2471 retval = MPI_ERR_TYPE;
2473 smpi_datatype_commit(datatype);
2474 retval = MPI_SUCCESS;
2479 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2482 if (old_type == MPI_DATATYPE_NULL) {
2483 retval = MPI_ERR_TYPE;
2484 } else if (count<0 || blocklen<0){
2485 retval = MPI_ERR_COUNT;
2487 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2492 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2495 if (old_type == MPI_DATATYPE_NULL) {
2496 retval = MPI_ERR_TYPE;
2497 } else if (count<0 || blocklen<0){
2498 retval = MPI_ERR_COUNT;
2500 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2505 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2506 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2509 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2512 if (old_type == MPI_DATATYPE_NULL) {
2513 retval = MPI_ERR_TYPE;
2514 } else if (count<0){
2515 retval = MPI_ERR_COUNT;
2517 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2522 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2525 if (old_type == MPI_DATATYPE_NULL) {
2526 retval = MPI_ERR_TYPE;
2527 } else if (count<0){
2528 retval = MPI_ERR_COUNT;
2530 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2535 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2536 MPI_Datatype* new_type) {
2539 if (old_type == MPI_DATATYPE_NULL) {
2540 retval = MPI_ERR_TYPE;
2541 } else if (count<0){
2542 retval = MPI_ERR_COUNT;
2544 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count*sizeof(int)));
2545 for (i=0; i<count;i++)
2546 blocklens[i]=blocklength;
2547 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2548 xbt_free(blocklens);
2553 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2556 if (old_type == MPI_DATATYPE_NULL) {
2557 retval = MPI_ERR_TYPE;
2558 } else if (count<0){
2559 retval = MPI_ERR_COUNT;
2561 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2566 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2567 MPI_Datatype* new_type) {
2568 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2571 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2572 MPI_Datatype* new_type) {
2575 if (old_type == MPI_DATATYPE_NULL) {
2576 retval = MPI_ERR_TYPE;
2577 } else if (count<0){
2578 retval = MPI_ERR_COUNT;
2580 int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int));
2581 for (i=0; i<count;i++)blocklens[i]=blocklength;
2582 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2583 xbt_free(blocklens);
2588 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2592 retval = MPI_ERR_COUNT;
2594 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2599 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2600 MPI_Datatype* new_type) {
2601 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2604 int PMPI_Error_class(int errorcode, int* errorclass) {
2605 // assume smpi uses only standard mpi error codes
2606 *errorclass=errorcode;
2610 int PMPI_Initialized(int* flag) {
2611 *flag=smpi_process_initialized();
2615 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2616 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2617 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2619 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2621 if (comm_old == MPI_COMM_NULL){
2622 retval = MPI_ERR_COMM;
2623 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2624 retval = MPI_ERR_ARG;
2626 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2631 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2632 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2633 return MPI_ERR_TOPOLOGY;
2635 if (coords == nullptr) {
2638 return smpi_mpi_cart_rank(comm, coords, rank);
2641 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2642 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2643 return MPI_ERR_TOPOLOGY;
2645 if (source == nullptr || dest == nullptr || direction < 0 ) {
2648 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2651 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2652 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2653 return MPI_ERR_TOPOLOGY;
2655 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2656 return MPI_ERR_RANK;
2661 if(coords == nullptr) {
2664 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2667 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2668 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2669 return MPI_ERR_TOPOLOGY;
2671 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2674 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2677 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2678 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2679 return MPI_ERR_TOPOLOGY;
2681 if (ndims == nullptr) {
2684 return smpi_mpi_cartdim_get(comm, ndims);
2687 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2688 if(dims == nullptr) {
2691 if (ndims < 1 || nnodes < 1) {
2692 return MPI_ERR_DIMS;
2695 return smpi_mpi_dims_create(nnodes, ndims, dims);
2698 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2699 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2700 return MPI_ERR_TOPOLOGY;
2702 if (comm_new == nullptr) {
2705 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2708 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2709 if(oldtype == MPI_DATATYPE_NULL) {
2710 return MPI_ERR_TYPE;
2712 int blocks[3] = { 1, 1, 1 };
2713 MPI_Aint disps[3] = { lb, 0, lb+extent };
2714 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2716 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2717 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t) , subtype, DT_FLAG_VECTOR);
2719 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2723 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2726 if (comm == MPI_COMM_NULL) {
2727 retval= MPI_ERR_COMM;
2728 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2729 retval= MPI_ERR_OTHER;
2731 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2732 retval = MPI_SUCCESS;
2738 int PMPI_Win_free( MPI_Win* win){
2741 if (win == nullptr || *win == MPI_WIN_NULL) {
2742 retval = MPI_ERR_WIN;
2744 retval=smpi_mpi_win_free(win);
2750 int PMPI_Win_set_name(MPI_Win win, char * name)
2753 if (win == MPI_WIN_NULL) {
2754 retval = MPI_ERR_TYPE;
2755 } else if (name == nullptr) {
2756 retval = MPI_ERR_ARG;
2758 smpi_mpi_win_set_name(win, name);
2759 retval = MPI_SUCCESS;
2764 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2766 int retval = MPI_SUCCESS;
2768 if (win == MPI_WIN_NULL) {
2769 retval = MPI_ERR_WIN;
2770 } else if (name == nullptr) {
2771 retval = MPI_ERR_ARG;
2773 smpi_mpi_win_get_name(win, name, len);
2778 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2779 int retval = MPI_SUCCESS;
2780 if (win == MPI_WIN_NULL) {
2781 retval = MPI_ERR_WIN;
2783 smpi_mpi_win_get_group(win, group);
2784 smpi_group_use(*group);
2790 int PMPI_Win_fence( int assert, MPI_Win win){
2793 if (win == MPI_WIN_NULL) {
2794 retval = MPI_ERR_WIN;
2796 int rank = smpi_process_index();
2797 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2798 retval = smpi_mpi_win_fence(assert, win);
2799 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2805 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2806 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2809 if (win == MPI_WIN_NULL) {
2810 retval = MPI_ERR_WIN;
2811 } else if (target_rank == MPI_PROC_NULL) {
2812 retval = MPI_SUCCESS;
2813 } else if (target_rank <0){
2814 retval = MPI_ERR_RANK;
2815 } else if (target_disp <0){
2816 retval = MPI_ERR_ARG;
2817 } else if ((origin_count < 0 || target_count < 0) ||
2818 (origin_addr==nullptr && origin_count > 0)){
2819 retval = MPI_ERR_COUNT;
2820 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2821 retval = MPI_ERR_TYPE;
2823 int rank = smpi_process_index();
2825 smpi_mpi_win_get_group(win, &group);
2826 int src_traced = smpi_group_index(group, target_rank);
2827 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2829 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2830 target_datatype, win);
2832 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2838 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2839 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2842 if (win == MPI_WIN_NULL) {
2843 retval = MPI_ERR_WIN;
2844 } else if (target_rank == MPI_PROC_NULL) {
2845 retval = MPI_SUCCESS;
2846 } else if (target_rank <0){
2847 retval = MPI_ERR_RANK;
2848 } else if (target_disp <0){
2849 retval = MPI_ERR_ARG;
2850 } else if ((origin_count < 0 || target_count < 0) ||
2851 (origin_addr==nullptr && origin_count > 0)){
2852 retval = MPI_ERR_COUNT;
2853 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2854 retval = MPI_ERR_TYPE;
2856 int rank = smpi_process_index();
2858 smpi_mpi_win_get_group(win, &group);
2859 int dst_traced = smpi_group_index(group, target_rank);
2860 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2861 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2863 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2864 target_datatype, win);
2866 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2872 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2873 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2876 if (win == MPI_WIN_NULL) {
2877 retval = MPI_ERR_WIN;
2878 } else if (target_rank == MPI_PROC_NULL) {
2879 retval = MPI_SUCCESS;
2880 } else if (target_rank <0){
2881 retval = MPI_ERR_RANK;
2882 } else if (target_disp <0){
2883 retval = MPI_ERR_ARG;
2884 } else if ((origin_count < 0 || target_count < 0) ||
2885 (origin_addr==nullptr && origin_count > 0)){
2886 retval = MPI_ERR_COUNT;
2887 } else if ((!is_datatype_valid(origin_datatype)) ||
2888 (!is_datatype_valid(target_datatype))) {
2889 retval = MPI_ERR_TYPE;
2890 } else if (op == MPI_OP_NULL) {
2891 retval = MPI_ERR_OP;
2893 int rank = smpi_process_index();
2895 smpi_mpi_win_get_group(win, &group);
2896 int src_traced = smpi_group_index(group, target_rank);
2897 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2899 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2900 target_datatype, op, win);
2902 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2908 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2911 if (win == MPI_WIN_NULL) {
2912 retval = MPI_ERR_WIN;
2913 } else if (group==MPI_GROUP_NULL){
2914 retval = MPI_ERR_GROUP;
2917 int rank = smpi_process_index();
2918 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2919 retval = smpi_mpi_win_post(group,assert,win);
2920 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2926 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2929 if (win == MPI_WIN_NULL) {
2930 retval = MPI_ERR_WIN;
2931 } else if (group==MPI_GROUP_NULL){
2932 retval = MPI_ERR_GROUP;
2935 int rank = smpi_process_index();
2936 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2937 retval = smpi_mpi_win_start(group,assert,win);
2938 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2944 int PMPI_Win_complete(MPI_Win win){
2947 if (win == MPI_WIN_NULL) {
2948 retval = MPI_ERR_WIN;
2951 int rank = smpi_process_index();
2952 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2954 retval = smpi_mpi_win_complete(win);
2956 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2962 int PMPI_Win_wait(MPI_Win win){
2965 if (win == MPI_WIN_NULL) {
2966 retval = MPI_ERR_WIN;
2969 int rank = smpi_process_index();
2970 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2972 retval = smpi_mpi_win_wait(win);
2974 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2980 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2981 void *ptr = xbt_malloc(size);
2983 return MPI_ERR_NO_MEM;
2985 *static_cast<void**>(baseptr) = ptr;
2990 int PMPI_Free_mem(void *baseptr){
2995 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2998 if (datatype == MPI_DATATYPE_NULL) {
2999 retval = MPI_ERR_TYPE;
3000 } else if (name == nullptr) {
3001 retval = MPI_ERR_ARG;
3003 smpi_datatype_set_name(datatype, name);
3004 retval = MPI_SUCCESS;
3009 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
3013 if (datatype == MPI_DATATYPE_NULL) {
3014 retval = MPI_ERR_TYPE;
3015 } else if (name == nullptr) {
3016 retval = MPI_ERR_ARG;
3018 smpi_datatype_get_name(datatype, name, len);
3019 retval = MPI_SUCCESS;
3024 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
3025 return smpi_type_f2c(datatype);
3028 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
3029 return smpi_type_c2f( datatype);
3032 MPI_Group PMPI_Group_f2c(MPI_Fint group){
3033 return smpi_group_f2c( group);
3036 MPI_Fint PMPI_Group_c2f(MPI_Group group){
3037 return smpi_group_c2f(group);
3040 MPI_Request PMPI_Request_f2c(MPI_Fint request){
3041 return smpi_request_f2c(request);
3044 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
3045 return smpi_request_c2f(request);
3048 MPI_Win PMPI_Win_f2c(MPI_Fint win){
3049 return smpi_win_f2c(win);
3052 MPI_Fint PMPI_Win_c2f(MPI_Win win){
3053 return smpi_win_c2f(win);
3056 MPI_Op PMPI_Op_f2c(MPI_Fint op){
3057 return smpi_op_f2c(op);
3060 MPI_Fint PMPI_Op_c2f(MPI_Op op){
3061 return smpi_op_c2f(op);
3064 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
3065 return smpi_comm_f2c(comm);
3068 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
3069 return smpi_comm_c2f(comm);
3072 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3073 return smpi_info_f2c(info);
3076 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3077 return smpi_info_c2f(info);
3080 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3081 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3084 int PMPI_Keyval_free(int* keyval) {
3085 return smpi_comm_keyval_free(keyval);
3088 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3089 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3090 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3092 else if (comm==MPI_COMM_NULL)
3093 return MPI_ERR_COMM;
3095 return smpi_comm_attr_delete(comm, keyval);
3098 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3100 static int zero = 0;
3101 static int tag_ub = 1000000;
3102 static int last_used_code = MPI_ERR_LASTCODE;
3104 if (comm==MPI_COMM_NULL){
3106 return MPI_ERR_COMM;
3114 *static_cast<int**>(attr_value) = &zero;
3116 case MPI_UNIVERSE_SIZE:
3118 *static_cast<int**>(attr_value) = &smpi_universe_size;
3120 case MPI_LASTUSEDCODE:
3122 *static_cast<int**>(attr_value) = &last_used_code;
3126 *static_cast<int**>(attr_value) = &tag_ub;
3128 case MPI_WTIME_IS_GLOBAL:
3130 *static_cast<int**>(attr_value) = &one;
3133 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3137 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3138 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3139 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3141 else if (comm==MPI_COMM_NULL)
3142 return MPI_ERR_COMM;
3144 return smpi_comm_attr_put(comm, keyval, attr_value);
3147 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3149 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3152 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3154 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3157 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3159 return PMPI_Attr_delete(comm, comm_keyval);
3162 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3165 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3168 int PMPI_Comm_free_keyval(int* keyval) {
3169 return PMPI_Keyval_free(keyval);
3172 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3174 if (type==MPI_DATATYPE_NULL)
3175 return MPI_ERR_TYPE;
3177 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3180 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3182 if (type==MPI_DATATYPE_NULL)
3183 return MPI_ERR_TYPE;
3185 return smpi_type_attr_put(type, type_keyval, attribute_val);
3188 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3190 if (type==MPI_DATATYPE_NULL)
3191 return MPI_ERR_TYPE;
3193 return smpi_type_attr_delete(type, type_keyval);
3196 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3199 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3202 int PMPI_Type_free_keyval(int* keyval) {
3203 return smpi_type_keyval_free(keyval);
3206 int PMPI_Info_create( MPI_Info *info){
3207 if (info == nullptr)
3209 *info = xbt_new(s_smpi_mpi_info_t, 1);
3210 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3211 (*info)->refcount=1;
3215 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3216 if (info == nullptr || key == nullptr || value == nullptr)
3219 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
3223 int PMPI_Info_free( MPI_Info *info){
3224 if (info == nullptr || *info==nullptr)
3226 (*info)->refcount--;
3227 if((*info)->refcount==0){
3228 xbt_dict_free(&((*info)->info_dict));
3231 *info=MPI_INFO_NULL;
3235 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3237 if (info == nullptr || key == nullptr || valuelen <0)
3239 if (value == nullptr)
3240 return MPI_ERR_INFO_VALUE;
3241 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
3243 memset(value, 0, valuelen);
3244 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3250 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3251 if (info == nullptr || newinfo==nullptr)
3253 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3254 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3255 (*newinfo)->refcount=1;
3256 xbt_dict_cursor_t cursor = nullptr;
3259 xbt_dict_foreach(info->info_dict,cursor,key,data){
3260 xbt_dict_set((*newinfo)->info_dict, reinterpret_cast<char*>(key), xbt_strdup(reinterpret_cast<char*>(data)), nullptr);
3265 int PMPI_Info_delete(MPI_Info info, char *key){
3266 if (info == nullptr || key==nullptr)
3269 xbt_dict_remove(info->info_dict, key);
3272 return MPI_ERR_INFO_NOKEY;
3277 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3278 if (info == nullptr || nkeys==nullptr)
3280 *nkeys=xbt_dict_size(info->info_dict);
3284 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3285 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
3288 xbt_dict_cursor_t cursor = nullptr;
3292 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3294 strncpy(key,keyn,strlen(keyn)+1);
3295 xbt_dict_cursor_free(&cursor);
3303 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3305 if (info == nullptr || key == nullptr || valuelen==nullptr)
3307 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3309 *valuelen=strlen(tmpvalue);
3315 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3316 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3318 if(!is_datatype_valid(type))
3319 return MPI_ERR_TYPE;
3320 if(comm==MPI_COMM_NULL)
3321 return MPI_ERR_COMM;
3322 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3325 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3326 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3328 if(!is_datatype_valid(type))
3329 return MPI_ERR_TYPE;
3330 if(comm==MPI_COMM_NULL)
3331 return MPI_ERR_COMM;
3332 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3335 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3338 if(!is_datatype_valid(datatype))
3339 return MPI_ERR_TYPE;
3340 if(comm==MPI_COMM_NULL)
3341 return MPI_ERR_COMM;
3343 *size=incount*smpi_datatype_size(datatype);