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 */
25 extern "C" { // Obviously, the C MPI interface should use the C linkage
27 int PMPI_Init(int *argc, char ***argv)
29 // PMPI_Init is call only one time by only by SMPI process
31 MPI_Initialized(&already_init);
32 if(already_init == 0){
33 smpi_process_init(argc, argv);
34 smpi_process_mark_as_initialized();
35 int rank = smpi_process_index();
36 TRACE_smpi_init(rank);
37 TRACE_smpi_computing_init(rank);
38 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
39 extra->type = TRACING_INIT;
40 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
41 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
53 int rank = smpi_process_index();
54 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
55 extra->type = TRACING_FINALIZE;
56 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
58 smpi_process_finalize();
60 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
61 TRACE_smpi_finalize(smpi_process_index());
62 smpi_process_destroy();
66 int PMPI_Finalized(int* flag)
68 *flag=smpi_process_finalized();
72 int PMPI_Get_version (int *version,int *subversion){
73 *version = MPI_VERSION;
74 *subversion= MPI_SUBVERSION;
78 int PMPI_Get_library_version (char *version,int *len){
79 int retval = MPI_SUCCESS;
81 snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2015",
82 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR);
83 *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
88 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
90 if (provided != nullptr) {
91 *provided = MPI_THREAD_SINGLE;
93 return MPI_Init(argc, argv);
96 int PMPI_Query_thread(int *provided)
100 if (provided == nullptr) {
101 retval = MPI_ERR_ARG;
103 *provided = MPI_THREAD_SINGLE;
104 retval = MPI_SUCCESS;
109 int PMPI_Is_thread_main(int *flag)
113 if (flag == nullptr) {
114 retval = MPI_ERR_ARG;
116 *flag = smpi_process_index() == 0;
117 retval = MPI_SUCCESS;
122 int PMPI_Abort(MPI_Comm comm, int errorcode)
125 smpi_process_destroy();
126 // FIXME: should kill all processes in comm instead
127 simcall_process_kill(SIMIX_process_self());
133 return smpi_mpi_wtime();
136 extern double sg_maxmin_precision;
139 return sg_maxmin_precision;
142 int PMPI_Address(void *location, MPI_Aint * address)
146 if (address==nullptr) {
147 retval = MPI_ERR_ARG;
149 *address = reinterpret_cast<MPI_Aint>(location);
150 retval = MPI_SUCCESS;
155 int PMPI_Get_address(void *location, MPI_Aint * address)
157 return PMPI_Address(location, address);
160 int PMPI_Type_free(MPI_Datatype * datatype)
163 /* Free a predefined datatype is an error according to the standard, and should be checked for */
164 if (*datatype == MPI_DATATYPE_NULL) {
165 retval = MPI_ERR_ARG;
167 smpi_datatype_unuse(*datatype);
168 retval = MPI_SUCCESS;
173 int PMPI_Type_size(MPI_Datatype datatype, int *size)
177 if (datatype == MPI_DATATYPE_NULL) {
178 retval = MPI_ERR_TYPE;
179 } else if (size == nullptr) {
180 retval = MPI_ERR_ARG;
182 *size = static_cast<int>(smpi_datatype_size(datatype));
183 retval = MPI_SUCCESS;
188 int PMPI_Type_size_x(MPI_Datatype datatype, MPI_Count *size)
192 if (datatype == MPI_DATATYPE_NULL) {
193 retval = MPI_ERR_TYPE;
194 } else if (size == nullptr) {
195 retval = MPI_ERR_ARG;
197 *size = static_cast<MPI_Count>(smpi_datatype_size(datatype));
198 retval = MPI_SUCCESS;
203 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
207 if (datatype == MPI_DATATYPE_NULL) {
208 retval = MPI_ERR_TYPE;
209 } else if (lb == nullptr || extent == nullptr) {
210 retval = MPI_ERR_ARG;
212 retval = smpi_datatype_extent(datatype, lb, extent);
217 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
219 return PMPI_Type_get_extent(datatype, lb, extent);
222 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
226 if (datatype == MPI_DATATYPE_NULL) {
227 retval = MPI_ERR_TYPE;
228 } else if (extent == nullptr) {
229 retval = MPI_ERR_ARG;
231 *extent = smpi_datatype_get_extent(datatype);
232 retval = MPI_SUCCESS;
237 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
241 if (datatype == MPI_DATATYPE_NULL) {
242 retval = MPI_ERR_TYPE;
243 } else if (disp == nullptr) {
244 retval = MPI_ERR_ARG;
246 *disp = smpi_datatype_lb(datatype);
247 retval = MPI_SUCCESS;
252 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
256 if (datatype == MPI_DATATYPE_NULL) {
257 retval = MPI_ERR_TYPE;
258 } else if (disp == nullptr) {
259 retval = MPI_ERR_ARG;
261 *disp = smpi_datatype_ub(datatype);
262 retval = MPI_SUCCESS;
267 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
270 if (datatype == MPI_DATATYPE_NULL) {
271 retval = MPI_ERR_TYPE;
273 retval = smpi_datatype_dup(datatype, newtype);
278 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
282 if (function == nullptr || op == nullptr) {
283 retval = MPI_ERR_ARG;
285 *op = smpi_op_new(function, (commute!=0));
286 retval = MPI_SUCCESS;
291 int PMPI_Op_free(MPI_Op * op)
296 retval = MPI_ERR_ARG;
297 } else if (*op == MPI_OP_NULL) {
300 smpi_op_destroy(*op);
302 retval = MPI_SUCCESS;
307 int PMPI_Group_free(MPI_Group * group)
311 if (group == nullptr) {
312 retval = MPI_ERR_ARG;
314 smpi_group_destroy(*group);
315 *group = MPI_GROUP_NULL;
316 retval = MPI_SUCCESS;
321 int PMPI_Group_size(MPI_Group group, int *size)
325 if (group == MPI_GROUP_NULL) {
326 retval = MPI_ERR_GROUP;
327 } else if (size == nullptr) {
328 retval = MPI_ERR_ARG;
330 *size = smpi_group_size(group);
331 retval = MPI_SUCCESS;
336 int PMPI_Group_rank(MPI_Group group, int *rank)
340 if (group == MPI_GROUP_NULL) {
341 retval = MPI_ERR_GROUP;
342 } else if (rank == nullptr) {
343 retval = MPI_ERR_ARG;
345 *rank = smpi_group_rank(group, smpi_process_index());
346 retval = MPI_SUCCESS;
351 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
353 int retval, i, index;
354 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
355 retval = MPI_ERR_GROUP;
357 for (i = 0; i < n; i++) {
358 if(ranks1[i]==MPI_PROC_NULL){
359 ranks2[i]=MPI_PROC_NULL;
361 index = smpi_group_index(group1, ranks1[i]);
362 ranks2[i] = smpi_group_rank(group2, index);
365 retval = MPI_SUCCESS;
370 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
374 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
375 retval = MPI_ERR_GROUP;
376 } else if (result == nullptr) {
377 retval = MPI_ERR_ARG;
379 *result = smpi_group_compare(group1, group2);
380 retval = MPI_SUCCESS;
385 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
387 int retval, i, proc1, proc2, size, size2;
389 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
390 retval = MPI_ERR_GROUP;
391 } else if (newgroup == nullptr) {
392 retval = MPI_ERR_ARG;
394 size = smpi_group_size(group1);
395 size2 = smpi_group_size(group2);
396 for (i = 0; i < size2; i++) {
397 proc2 = smpi_group_index(group2, i);
398 proc1 = smpi_group_rank(group1, proc2);
399 if (proc1 == MPI_UNDEFINED) {
404 *newgroup = MPI_GROUP_EMPTY;
406 *newgroup = smpi_group_new(size);
407 size2 = smpi_group_size(group1);
408 for (i = 0; i < size2; i++) {
409 proc1 = smpi_group_index(group1, i);
410 smpi_group_set_mapping(*newgroup, proc1, i);
412 for (i = size2; i < size; i++) {
413 proc2 = smpi_group_index(group2, i - size2);
414 smpi_group_set_mapping(*newgroup, proc2, i);
417 retval = MPI_SUCCESS;
422 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
424 int retval, i, proc1, proc2, size;
426 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
427 retval = MPI_ERR_GROUP;
428 } else if (newgroup == nullptr) {
429 retval = MPI_ERR_ARG;
431 size = smpi_group_size(group2);
432 for (i = 0; i < size; i++) {
433 proc2 = smpi_group_index(group2, i);
434 proc1 = smpi_group_rank(group1, proc2);
435 if (proc1 == MPI_UNDEFINED) {
440 *newgroup = MPI_GROUP_EMPTY;
442 *newgroup = smpi_group_new(size);
444 for (i = 0; i < smpi_group_size(group2); i++) {
445 proc2 = smpi_group_index(group2, i);
446 proc1 = smpi_group_rank(group1, proc2);
447 if (proc1 != MPI_UNDEFINED) {
448 smpi_group_set_mapping(*newgroup, proc2, j);
453 retval = MPI_SUCCESS;
458 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
460 int retval, i, proc1, proc2, size, size2;
462 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
463 retval = MPI_ERR_GROUP;
464 } else if (newgroup == nullptr) {
465 retval = MPI_ERR_ARG;
467 size = smpi_group_size(group1);
469 for (i = 0; i < size2; i++) {
470 proc1 = smpi_group_index(group1, i);
471 proc2 = smpi_group_rank(group2, proc1);
472 if (proc2 != MPI_UNDEFINED) {
477 *newgroup = MPI_GROUP_EMPTY;
479 *newgroup = smpi_group_new(size);
480 for (i = 0; i < size2; i++) {
481 proc1 = smpi_group_index(group1, i);
482 proc2 = smpi_group_rank(group2, proc1);
483 if (proc2 == MPI_UNDEFINED) {
484 smpi_group_set_mapping(*newgroup, proc1, i);
488 retval = MPI_SUCCESS;
493 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
497 if (group == MPI_GROUP_NULL) {
498 retval = MPI_ERR_GROUP;
499 } else if (newgroup == nullptr) {
500 retval = MPI_ERR_ARG;
502 retval = smpi_group_incl(group, n, ranks, newgroup);
507 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
509 int retval, i, j, newsize, oldsize, index;
511 if (group == MPI_GROUP_NULL) {
512 retval = MPI_ERR_GROUP;
513 } else if (newgroup == nullptr) {
514 retval = MPI_ERR_ARG;
518 if (group != smpi_comm_group(MPI_COMM_WORLD)
519 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
520 smpi_group_use(group);
521 } else if (n == smpi_group_size(group)) {
522 *newgroup = MPI_GROUP_EMPTY;
524 oldsize=smpi_group_size(group);
525 newsize = oldsize - n;
526 *newgroup = smpi_group_new(newsize);
528 int* to_exclude=xbt_new0(int, smpi_group_size(group));
529 for(i=0; i<oldsize; i++)
532 to_exclude[ranks[i]]=1;
535 for(i=0; i<oldsize; i++){
536 if(to_exclude[i]==0){
537 index = smpi_group_index(group, i);
538 smpi_group_set_mapping(*newgroup, index, j);
543 xbt_free(to_exclude);
545 retval = MPI_SUCCESS;
550 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
552 int retval, i, j, rank, size, index;
554 if (group == MPI_GROUP_NULL) {
555 retval = MPI_ERR_GROUP;
556 } else if (newgroup == nullptr) {
557 retval = MPI_ERR_ARG;
560 *newgroup = MPI_GROUP_EMPTY;
563 for (i = 0; i < n; i++) {
564 for (rank = ranges[i][0]; /* First */
565 rank >= 0 && rank < smpi_group_size(group); /* Last */
568 if(rank == ranges[i][1]){/*already last ?*/
571 rank += ranges[i][2]; /* Stride */
572 if (ranges[i][0]<ranges[i][1]){
573 if(rank > ranges[i][1])
576 if(rank < ranges[i][1])
582 *newgroup = smpi_group_new(size);
584 for (i = 0; i < n; i++) {
585 for (rank = ranges[i][0]; /* First */
586 rank >= 0 && rank < smpi_group_size(group); /* Last */
588 index = smpi_group_index(group, rank);
589 smpi_group_set_mapping(*newgroup, index, j);
591 if(rank == ranges[i][1]){/*already last ?*/
594 rank += ranges[i][2]; /* Stride */
595 if (ranges[i][0]<ranges[i][1]){
596 if(rank > ranges[i][1])
599 if(rank < ranges[i][1])
605 retval = MPI_SUCCESS;
610 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
612 int retval, i, rank, newrank,oldrank, size, index, add;
614 if (group == MPI_GROUP_NULL) {
615 retval = MPI_ERR_GROUP;
616 } else if (newgroup == nullptr) {
617 retval = MPI_ERR_ARG;
621 if (group!= smpi_comm_group(MPI_COMM_WORLD)
622 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
623 smpi_group_use(group);
625 size = smpi_group_size(group);
626 for (i = 0; i < n; i++) {
627 for (rank = ranges[i][0]; /* First */
628 rank >= 0 && rank < smpi_group_size(group); /* Last */
631 if(rank == ranges[i][1]){/*already last ?*/
634 rank += ranges[i][2]; /* Stride */
635 if (ranges[i][0]<ranges[i][1]){
636 if(rank > ranges[i][1])
639 if(rank < ranges[i][1])
645 *newgroup = MPI_GROUP_EMPTY;
647 *newgroup = smpi_group_new(size);
650 while (newrank < size) {
652 for (i = 0; i < n; i++) {
653 for (rank = ranges[i][0];
654 rank >= 0 && rank < smpi_group_size(group);
660 if(rank == ranges[i][1]){/*already last ?*/
663 rank += ranges[i][2]; /* Stride */
664 if (ranges[i][0]<ranges[i][1]){
665 if(rank > ranges[i][1])
668 if(rank < ranges[i][1])
674 index = smpi_group_index(group, oldrank);
675 smpi_group_set_mapping(*newgroup, index, newrank);
683 retval = MPI_SUCCESS;
688 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
691 if (comm == MPI_COMM_NULL) {
692 retval = MPI_ERR_COMM;
693 } else if (rank == nullptr) {
694 retval = MPI_ERR_ARG;
696 *rank = smpi_comm_rank(comm);
697 retval = MPI_SUCCESS;
702 int PMPI_Comm_size(MPI_Comm comm, int *size)
705 if (comm == MPI_COMM_NULL) {
706 retval = MPI_ERR_COMM;
707 } else if (size == nullptr) {
708 retval = MPI_ERR_ARG;
710 *size = smpi_comm_size(comm);
711 retval = MPI_SUCCESS;
716 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
720 if (comm == MPI_COMM_NULL) {
721 retval = MPI_ERR_COMM;
722 } else if (name == nullptr || len == nullptr) {
723 retval = MPI_ERR_ARG;
725 smpi_comm_get_name(comm, name, len);
726 retval = MPI_SUCCESS;
731 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
735 if (comm == MPI_COMM_NULL) {
736 retval = MPI_ERR_COMM;
737 } else if (group == nullptr) {
738 retval = MPI_ERR_ARG;
740 *group = smpi_comm_group(comm);
741 if(*group!= smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL
742 && *group != MPI_GROUP_EMPTY)
743 smpi_group_use(*group);
744 retval = MPI_SUCCESS;
749 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
753 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
754 retval = MPI_ERR_COMM;
755 } else if (result == nullptr) {
756 retval = MPI_ERR_ARG;
758 if (comm1 == comm2) { /* Same communicators means same groups */
761 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
762 if (*result == MPI_IDENT) {
763 *result = MPI_CONGRUENT;
766 retval = MPI_SUCCESS;
771 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
775 if (comm == MPI_COMM_NULL) {
776 retval = MPI_ERR_COMM;
777 } else if (newcomm == nullptr) {
778 retval = MPI_ERR_ARG;
780 retval = smpi_comm_dup(comm, newcomm);
785 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
789 if (comm == MPI_COMM_NULL) {
790 retval = MPI_ERR_COMM;
791 } else if (group == MPI_GROUP_NULL) {
792 retval = MPI_ERR_GROUP;
793 } else if (newcomm == nullptr) {
794 retval = MPI_ERR_ARG;
795 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
796 *newcomm= MPI_COMM_NULL;
797 retval = MPI_SUCCESS;
799 smpi_group_use(group);
800 *newcomm = smpi_comm_new(group, nullptr);
801 retval = MPI_SUCCESS;
806 int PMPI_Comm_free(MPI_Comm * comm)
810 if (comm == nullptr) {
811 retval = MPI_ERR_ARG;
812 } else if (*comm == MPI_COMM_NULL) {
813 retval = MPI_ERR_COMM;
815 smpi_comm_destroy(*comm);
816 *comm = MPI_COMM_NULL;
817 retval = MPI_SUCCESS;
822 int PMPI_Comm_disconnect(MPI_Comm * comm)
824 /* TODO: wait until all communication in comm are done */
827 if (comm == nullptr) {
828 retval = MPI_ERR_ARG;
829 } else if (*comm == MPI_COMM_NULL) {
830 retval = MPI_ERR_COMM;
832 smpi_comm_destroy(*comm);
833 *comm = MPI_COMM_NULL;
834 retval = MPI_SUCCESS;
839 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
844 if (comm_out == nullptr) {
845 retval = MPI_ERR_ARG;
846 } else if (comm == MPI_COMM_NULL) {
847 retval = MPI_ERR_COMM;
849 *comm_out = smpi_comm_split(comm, color, key);
850 retval = MPI_SUCCESS;
857 int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out)
862 if (comm_out == nullptr) {
863 retval = MPI_ERR_ARG;
864 } else if (comm == MPI_COMM_NULL) {
865 retval = MPI_ERR_COMM;
867 retval = MPI_Comm_create(comm, group, comm_out);
874 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
879 if (request == nullptr) {
880 retval = MPI_ERR_ARG;
881 } else if (comm == MPI_COMM_NULL) {
882 retval = MPI_ERR_COMM;
883 } else if (!is_datatype_valid(datatype)) {
884 retval = MPI_ERR_TYPE;
885 } else if (dst == MPI_PROC_NULL) {
886 retval = MPI_SUCCESS;
888 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
889 retval = MPI_SUCCESS;
892 if (retval != MPI_SUCCESS && request != nullptr)
893 *request = MPI_REQUEST_NULL;
897 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
902 if (request == nullptr) {
903 retval = MPI_ERR_ARG;
904 } else if (comm == MPI_COMM_NULL) {
905 retval = MPI_ERR_COMM;
906 } else if (!is_datatype_valid(datatype)) {
907 retval = MPI_ERR_TYPE;
908 } else if (src == MPI_PROC_NULL) {
909 retval = MPI_SUCCESS;
911 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
912 retval = MPI_SUCCESS;
915 if (retval != MPI_SUCCESS && request != nullptr)
916 *request = MPI_REQUEST_NULL;
920 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
925 if (request == nullptr) {
926 retval = MPI_ERR_ARG;
927 } else if (comm == MPI_COMM_NULL) {
928 retval = MPI_ERR_COMM;
929 } else if (!is_datatype_valid(datatype)) {
930 retval = MPI_ERR_TYPE;
931 } else if (dst == MPI_PROC_NULL) {
932 retval = MPI_SUCCESS;
934 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
935 retval = MPI_SUCCESS;
938 if (retval != MPI_SUCCESS && request != nullptr)
939 *request = MPI_REQUEST_NULL;
943 int PMPI_Start(MPI_Request * request)
948 if (request == nullptr || *request == MPI_REQUEST_NULL) {
949 retval = MPI_ERR_REQUEST;
951 smpi_mpi_start(*request);
952 retval = MPI_SUCCESS;
958 int PMPI_Startall(int count, MPI_Request * requests)
963 if (requests == nullptr) {
964 retval = MPI_ERR_ARG;
966 retval = MPI_SUCCESS;
967 for (i = 0 ; i < count ; i++) {
968 if(requests[i] == MPI_REQUEST_NULL) {
969 retval = MPI_ERR_REQUEST;
972 if(retval != MPI_ERR_REQUEST) {
973 smpi_mpi_startall(count, requests);
980 int PMPI_Request_free(MPI_Request * request)
985 if (*request == MPI_REQUEST_NULL) {
986 retval = MPI_ERR_ARG;
988 smpi_mpi_request_free(request);
989 retval = MPI_SUCCESS;
995 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
1001 if (request == nullptr) {
1002 retval = MPI_ERR_ARG;
1003 } else if (comm == MPI_COMM_NULL) {
1004 retval = MPI_ERR_COMM;
1005 } else if (src == MPI_PROC_NULL) {
1006 *request = MPI_REQUEST_NULL;
1007 retval = MPI_SUCCESS;
1008 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1009 retval = MPI_ERR_RANK;
1010 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1011 retval = MPI_ERR_COUNT;
1012 } else if (!is_datatype_valid(datatype)) {
1013 retval = MPI_ERR_TYPE;
1014 } else if(tag<0 && tag != MPI_ANY_TAG){
1015 retval = MPI_ERR_TAG;
1018 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1019 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1021 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1022 extra->type = TRACING_IRECV;
1023 extra->src = src_traced;
1026 extra->datatype1 = encode_datatype(datatype, &known);
1027 int dt_size_send = 1;
1029 dt_size_send = smpi_datatype_size(datatype);
1030 extra->send_size = count*dt_size_send;
1031 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1033 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1034 retval = MPI_SUCCESS;
1036 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1037 (*request)->recv = 1;
1041 if (retval != MPI_SUCCESS && request != nullptr)
1042 *request = MPI_REQUEST_NULL;
1047 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1052 if (request == nullptr) {
1053 retval = MPI_ERR_ARG;
1054 } else if (comm == MPI_COMM_NULL) {
1055 retval = MPI_ERR_COMM;
1056 } else if (dst == MPI_PROC_NULL) {
1057 *request = MPI_REQUEST_NULL;
1058 retval = MPI_SUCCESS;
1059 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1060 retval = MPI_ERR_RANK;
1061 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1062 retval = MPI_ERR_COUNT;
1063 } else if (!is_datatype_valid(datatype)) {
1064 retval = MPI_ERR_TYPE;
1065 } else if(tag<0 && tag != MPI_ANY_TAG){
1066 retval = MPI_ERR_TAG;
1069 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1070 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1071 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1072 extra->type = TRACING_ISEND;
1074 extra->dst = dst_traced;
1076 extra->datatype1 = encode_datatype(datatype, &known);
1077 int dt_size_send = 1;
1079 dt_size_send = smpi_datatype_size(datatype);
1080 extra->send_size = count*dt_size_send;
1081 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1082 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1084 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1085 retval = MPI_SUCCESS;
1087 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1088 (*request)->send = 1;
1092 if (retval != MPI_SUCCESS && request!=nullptr)
1093 *request = MPI_REQUEST_NULL;
1097 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
1102 if (request == nullptr) {
1103 retval = MPI_ERR_ARG;
1104 } else if (comm == MPI_COMM_NULL) {
1105 retval = MPI_ERR_COMM;
1106 } else if (dst == MPI_PROC_NULL) {
1107 *request = MPI_REQUEST_NULL;
1108 retval = MPI_SUCCESS;
1109 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1110 retval = MPI_ERR_RANK;
1111 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
1112 retval = MPI_ERR_COUNT;
1113 } else if (!is_datatype_valid(datatype)) {
1114 retval = MPI_ERR_TYPE;
1115 } else if(tag<0 && tag != MPI_ANY_TAG){
1116 retval = MPI_ERR_TAG;
1119 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1120 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1121 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1122 extra->type = TRACING_ISSEND;
1124 extra->dst = dst_traced;
1126 extra->datatype1 = encode_datatype(datatype, &known);
1127 int dt_size_send = 1;
1129 dt_size_send = smpi_datatype_size(datatype);
1130 extra->send_size = count*dt_size_send;
1131 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1132 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1134 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1135 retval = MPI_SUCCESS;
1137 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1138 (*request)->send = 1;
1142 if (retval != MPI_SUCCESS && request!=nullptr)
1143 *request = MPI_REQUEST_NULL;
1147 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1152 if (comm == MPI_COMM_NULL) {
1153 retval = MPI_ERR_COMM;
1154 } else if (src == MPI_PROC_NULL) {
1155 smpi_empty_status(status);
1156 status->MPI_SOURCE = MPI_PROC_NULL;
1157 retval = MPI_SUCCESS;
1158 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1159 retval = MPI_ERR_RANK;
1160 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1161 retval = MPI_ERR_COUNT;
1162 } else if (!is_datatype_valid(datatype)) {
1163 retval = MPI_ERR_TYPE;
1164 } else if(tag<0 && tag != MPI_ANY_TAG){
1165 retval = MPI_ERR_TAG;
1167 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1168 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1169 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1170 extra->type = TRACING_RECV;
1171 extra->src = src_traced;
1174 extra->datatype1 = encode_datatype(datatype, &known);
1175 int dt_size_send = 1;
1177 dt_size_send = smpi_datatype_size(datatype);
1178 extra->send_size = count*dt_size_send;
1179 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1181 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1182 retval = MPI_SUCCESS;
1184 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1185 if(status!=MPI_STATUS_IGNORE){
1186 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1187 if (!TRACE_smpi_view_internals()) {
1188 TRACE_smpi_recv(rank, src_traced, rank, tag);
1191 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1198 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1204 if (comm == MPI_COMM_NULL) {
1205 retval = MPI_ERR_COMM;
1206 } else if (dst == MPI_PROC_NULL) {
1207 retval = MPI_SUCCESS;
1208 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1209 retval = MPI_ERR_RANK;
1210 } else if ((count < 0) || (buf == nullptr && count > 0)) {
1211 retval = MPI_ERR_COUNT;
1212 } else if (!is_datatype_valid(datatype)) {
1213 retval = MPI_ERR_TYPE;
1214 } else if(tag < 0 && tag != MPI_ANY_TAG){
1215 retval = MPI_ERR_TAG;
1217 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1218 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1219 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1220 extra->type = TRACING_SEND;
1222 extra->dst = dst_traced;
1224 extra->datatype1 = encode_datatype(datatype, &known);
1225 int dt_size_send = 1;
1227 dt_size_send = smpi_datatype_size(datatype);
1229 extra->send_size = count*dt_size_send;
1230 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1231 if (!TRACE_smpi_view_internals()) {
1232 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1235 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1236 retval = MPI_SUCCESS;
1238 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1245 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1250 if (comm == MPI_COMM_NULL) {
1251 retval = MPI_ERR_COMM;
1252 } else if (dst == MPI_PROC_NULL) {
1253 retval = MPI_SUCCESS;
1254 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1255 retval = MPI_ERR_RANK;
1256 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1257 retval = MPI_ERR_COUNT;
1258 } else if (!is_datatype_valid(datatype)){
1259 retval = MPI_ERR_TYPE;
1260 } else if(tag<0 && tag != MPI_ANY_TAG){
1261 retval = MPI_ERR_TAG;
1263 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1264 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1265 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1266 extra->type = TRACING_SSEND;
1268 extra->dst = dst_traced;
1270 extra->datatype1 = encode_datatype(datatype, &known);
1271 int dt_size_send = 1;
1273 dt_size_send = smpi_datatype_size(datatype);
1275 extra->send_size = count*dt_size_send;
1276 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1277 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1279 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1280 retval = MPI_SUCCESS;
1282 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1289 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1290 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1296 if (comm == MPI_COMM_NULL) {
1297 retval = MPI_ERR_COMM;
1298 } else if (!is_datatype_valid(sendtype)
1299 || !is_datatype_valid(recvtype)) {
1300 retval = MPI_ERR_TYPE;
1301 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1302 smpi_empty_status(status);
1303 status->MPI_SOURCE = MPI_PROC_NULL;
1304 retval = MPI_SUCCESS;
1305 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1306 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1307 retval = MPI_ERR_RANK;
1308 } else if ((sendcount < 0 || recvcount<0) ||
1309 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1310 retval = MPI_ERR_COUNT;
1311 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1312 retval = MPI_ERR_TAG;
1315 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1316 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1317 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1318 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1319 extra->type = TRACING_SENDRECV;
1320 extra->src = src_traced;
1321 extra->dst = dst_traced;
1323 extra->datatype1 = encode_datatype(sendtype, &known);
1324 int dt_size_send = 1;
1326 dt_size_send = smpi_datatype_size(sendtype);
1327 extra->send_size = sendcount*dt_size_send;
1328 extra->datatype2 = encode_datatype(recvtype, &known);
1329 int dt_size_recv = 1;
1331 dt_size_recv = smpi_datatype_size(recvtype);
1332 extra->recv_size = recvcount*dt_size_recv;
1334 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1335 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1337 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1338 recvcount, recvtype, src, recvtag, comm, status);
1339 retval = MPI_SUCCESS;
1341 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1342 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1349 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1350 MPI_Comm comm, MPI_Status * status)
1354 if (!is_datatype_valid(datatype)) {
1355 retval = MPI_ERR_TYPE;
1356 } else if (count < 0) {
1357 retval = MPI_ERR_COUNT;
1359 int size = smpi_datatype_get_extent(datatype) * count;
1360 recvbuf = xbt_new0(char, size);
1361 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1362 if(retval==MPI_SUCCESS){
1363 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1371 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1375 if (request == nullptr || flag == nullptr) {
1376 retval = MPI_ERR_ARG;
1377 } else if (*request == MPI_REQUEST_NULL) {
1379 smpi_empty_status(status);
1380 retval = MPI_SUCCESS;
1382 int rank = ((*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1384 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1385 extra->type = TRACING_TEST;
1386 TRACE_smpi_testing_in(rank, extra);
1388 *flag = smpi_mpi_test(request, status);
1390 TRACE_smpi_testing_out(rank);
1391 retval = MPI_SUCCESS;
1397 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1402 if (index == nullptr || flag == nullptr) {
1403 retval = MPI_ERR_ARG;
1405 *flag = smpi_mpi_testany(count, requests, index, status);
1406 retval = MPI_SUCCESS;
1412 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1417 if (flag == nullptr) {
1418 retval = MPI_ERR_ARG;
1420 *flag = smpi_mpi_testall(count, requests, statuses);
1421 retval = MPI_SUCCESS;
1427 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1431 if (status == nullptr) {
1432 retval = MPI_ERR_ARG;
1433 } else if (comm == MPI_COMM_NULL) {
1434 retval = MPI_ERR_COMM;
1435 } else if (source == MPI_PROC_NULL) {
1436 smpi_empty_status(status);
1437 status->MPI_SOURCE = MPI_PROC_NULL;
1438 retval = MPI_SUCCESS;
1440 smpi_mpi_probe(source, tag, comm, status);
1441 retval = MPI_SUCCESS;
1447 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1451 if ((flag == nullptr) || (status == nullptr)) {
1452 retval = MPI_ERR_ARG;
1453 } else if (comm == MPI_COMM_NULL) {
1454 retval = MPI_ERR_COMM;
1455 } else if (source == MPI_PROC_NULL) {
1457 smpi_empty_status(status);
1458 status->MPI_SOURCE = MPI_PROC_NULL;
1459 retval = MPI_SUCCESS;
1461 smpi_mpi_iprobe(source, tag, comm, flag, status);
1462 retval = MPI_SUCCESS;
1468 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1474 smpi_empty_status(status);
1476 if (request == nullptr) {
1477 retval = MPI_ERR_ARG;
1478 } else if (*request == MPI_REQUEST_NULL) {
1479 retval = MPI_SUCCESS;
1482 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1484 int src_traced = (*request)->src;
1485 int dst_traced = (*request)->dst;
1486 int tag_traced= (*request)->tag;
1487 MPI_Comm comm = (*request)->comm;
1488 int is_wait_for_receive = (*request)->recv;
1489 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1490 extra->type = TRACING_WAIT;
1491 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1493 smpi_mpi_wait(request, status);
1494 retval = MPI_SUCCESS;
1496 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1497 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1498 if (is_wait_for_receive) {
1499 if(src_traced==MPI_ANY_SOURCE)
1500 src_traced = (status!=MPI_STATUS_IGNORE) ?
1501 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1503 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1511 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1513 if (index == nullptr)
1517 //save requests information for tracing
1526 savedvalstype* savedvals=nullptr;
1528 savedvals = xbt_new0(savedvalstype, count);
1530 for (i = 0; i < count; i++) {
1531 MPI_Request req = requests[i]; //already received requests are no longer valid
1533 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1536 int rank_traced = smpi_process_index();
1537 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1538 extra->type = TRACING_WAITANY;
1539 extra->send_size=count;
1540 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1542 *index = smpi_mpi_waitany(count, requests, status);
1544 if(*index!=MPI_UNDEFINED){
1545 int src_traced = savedvals[*index].src;
1546 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1547 int dst_traced = savedvals[*index].dst;
1548 int is_wait_for_receive = savedvals[*index].recv;
1549 if (is_wait_for_receive) {
1550 if(savedvals[*index].src==MPI_ANY_SOURCE)
1551 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1552 smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE) : savedvals[*index].src;
1553 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1555 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1557 xbt_free(savedvals);
1563 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1566 //save information from requests
1576 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1578 for (i = 0; i < count; i++) {
1579 MPI_Request req = requests[i];
1580 if(req!=MPI_REQUEST_NULL){
1581 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1583 savedvals[i].valid=0;
1586 int rank_traced = smpi_process_index();
1587 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1588 extra->type = TRACING_WAITALL;
1589 extra->send_size=count;
1590 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1592 int retval = smpi_mpi_waitall(count, requests, status);
1594 for (i = 0; i < count; i++) {
1595 if(savedvals[i].valid){
1596 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1597 int src_traced = savedvals[i].src;
1598 int dst_traced = savedvals[i].dst;
1599 int is_wait_for_receive = savedvals[i].recv;
1600 if (is_wait_for_receive) {
1601 if(src_traced==MPI_ANY_SOURCE)
1602 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1603 smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
1604 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1608 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1609 xbt_free(savedvals);
1615 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1620 if (outcount == nullptr) {
1621 retval = MPI_ERR_ARG;
1623 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1624 retval = MPI_SUCCESS;
1630 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1635 if (outcount == nullptr) {
1636 retval = MPI_ERR_ARG;
1638 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1639 retval = MPI_SUCCESS;
1646 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1652 if (comm == MPI_COMM_NULL) {
1653 retval = MPI_ERR_COMM;
1654 } else if (!is_datatype_valid(datatype)) {
1655 retval = MPI_ERR_ARG;
1657 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1658 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1660 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1661 extra->type = TRACING_BCAST;
1662 extra->root = root_traced;
1664 extra->datatype1 = encode_datatype(datatype, &known);
1665 int dt_size_send = 1;
1667 dt_size_send = smpi_datatype_size(datatype);
1668 extra->send_size = count*dt_size_send;
1669 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1670 if(smpi_comm_size(comm)>1)
1671 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1672 retval = MPI_SUCCESS;
1674 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1681 int PMPI_Barrier(MPI_Comm comm)
1687 if (comm == MPI_COMM_NULL) {
1688 retval = MPI_ERR_COMM;
1690 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1691 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1692 extra->type = TRACING_BARRIER;
1693 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1695 mpi_coll_barrier_fun(comm);
1696 retval = MPI_SUCCESS;
1698 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1705 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1706 int root, MPI_Comm comm)
1712 if (comm == MPI_COMM_NULL) {
1713 retval = MPI_ERR_COMM;
1714 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1715 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1716 retval = MPI_ERR_TYPE;
1717 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1718 retval = MPI_ERR_COUNT;
1721 char* sendtmpbuf = static_cast<char*>(sendbuf);
1722 int sendtmpcount = sendcount;
1723 MPI_Datatype sendtmptype = sendtype;
1724 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1726 sendtmptype=recvtype;
1728 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1729 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1730 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1731 extra->type = TRACING_GATHER;
1732 extra->root = root_traced;
1734 extra->datatype1 = encode_datatype(sendtmptype, &known);
1735 int dt_size_send = 1;
1737 dt_size_send = smpi_datatype_size(sendtmptype);
1738 extra->send_size = sendtmpcount*dt_size_send;
1739 extra->datatype2 = encode_datatype(recvtype, &known);
1740 int dt_size_recv = 1;
1741 if((smpi_comm_rank(comm)==root) && known==0)
1742 dt_size_recv = smpi_datatype_size(recvtype);
1743 extra->recv_size = recvcount*dt_size_recv;
1745 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1747 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1749 retval = MPI_SUCCESS;
1750 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1757 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1758 MPI_Datatype recvtype, int root, MPI_Comm comm)
1764 if (comm == MPI_COMM_NULL) {
1765 retval = MPI_ERR_COMM;
1766 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1767 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1768 retval = MPI_ERR_TYPE;
1769 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1770 retval = MPI_ERR_COUNT;
1771 } else if (recvcounts == nullptr || displs == nullptr) {
1772 retval = MPI_ERR_ARG;
1774 char* sendtmpbuf = static_cast<char*>(sendbuf);
1775 int sendtmpcount = sendcount;
1776 MPI_Datatype sendtmptype = sendtype;
1777 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1779 sendtmptype=recvtype;
1782 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1783 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1785 int size = smpi_comm_size(comm);
1786 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1787 extra->type = TRACING_GATHERV;
1788 extra->num_processes = size;
1789 extra->root = root_traced;
1791 extra->datatype1 = encode_datatype(sendtmptype, &known);
1792 int dt_size_send = 1;
1794 dt_size_send = smpi_datatype_size(sendtype);
1795 extra->send_size = sendtmpcount*dt_size_send;
1796 extra->datatype2 = encode_datatype(recvtype, &known);
1797 int dt_size_recv = 1;
1799 dt_size_recv = smpi_datatype_size(recvtype);
1800 if((smpi_comm_rank(comm)==root)){
1801 extra->recvcounts= xbt_new(int,size);
1802 for(i=0; i< size; i++)//copy data to avoid bad free
1803 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1805 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1807 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1808 retval = MPI_SUCCESS;
1809 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1816 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1817 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1823 if (comm == MPI_COMM_NULL) {
1824 retval = MPI_ERR_COMM;
1825 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1826 (recvtype == MPI_DATATYPE_NULL)){
1827 retval = MPI_ERR_TYPE;
1828 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1830 retval = MPI_ERR_COUNT;
1832 if(sendbuf == MPI_IN_PLACE) {
1833 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1834 sendcount=recvcount;
1837 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1838 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1839 extra->type = TRACING_ALLGATHER;
1841 extra->datatype1 = encode_datatype(sendtype, &known);
1842 int dt_size_send = 1;
1844 dt_size_send = smpi_datatype_size(sendtype);
1845 extra->send_size = sendcount*dt_size_send;
1846 extra->datatype2 = encode_datatype(recvtype, &known);
1847 int dt_size_recv = 1;
1849 dt_size_recv = smpi_datatype_size(recvtype);
1850 extra->recv_size = recvcount*dt_size_recv;
1852 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1854 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1855 retval = MPI_SUCCESS;
1856 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1862 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1863 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1869 if (comm == MPI_COMM_NULL) {
1870 retval = MPI_ERR_COMM;
1871 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1872 (recvtype == MPI_DATATYPE_NULL)){
1873 retval = MPI_ERR_TYPE;
1874 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1875 retval = MPI_ERR_COUNT;
1876 } else if (recvcounts == nullptr || displs == nullptr) {
1877 retval = MPI_ERR_ARG;
1880 if(sendbuf == MPI_IN_PLACE) {
1881 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1882 sendcount=recvcounts[smpi_comm_rank(comm)];
1885 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1887 int size = smpi_comm_size(comm);
1888 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1889 extra->type = TRACING_ALLGATHERV;
1890 extra->num_processes = size;
1892 extra->datatype1 = encode_datatype(sendtype, &known);
1893 int dt_size_send = 1;
1895 dt_size_send = smpi_datatype_size(sendtype);
1896 extra->send_size = sendcount*dt_size_send;
1897 extra->datatype2 = encode_datatype(recvtype, &known);
1898 int dt_size_recv = 1;
1900 dt_size_recv = smpi_datatype_size(recvtype);
1901 extra->recvcounts= xbt_new(int, size);
1902 for(i=0; i< size; i++)//copy data to avoid bad free
1903 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1905 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1907 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1908 retval = MPI_SUCCESS;
1909 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1916 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1917 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1923 if (comm == MPI_COMM_NULL) {
1924 retval = MPI_ERR_COMM;
1925 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1926 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1927 retval = MPI_ERR_TYPE;
1928 } else if ((sendbuf == recvbuf) ||
1929 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1930 retval = MPI_ERR_BUFFER;
1933 if (recvbuf == MPI_IN_PLACE) {
1935 recvcount=sendcount;
1937 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1938 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1939 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1940 extra->type = TRACING_SCATTER;
1941 extra->root = root_traced;
1943 extra->datatype1 = encode_datatype(sendtype, &known);
1944 int dt_size_send = 1;
1945 if((smpi_comm_rank(comm)==root) && known==0)
1946 dt_size_send = smpi_datatype_size(sendtype);
1947 extra->send_size = sendcount*dt_size_send;
1948 extra->datatype2 = encode_datatype(recvtype, &known);
1949 int dt_size_recv = 1;
1951 dt_size_recv = smpi_datatype_size(recvtype);
1952 extra->recv_size = recvcount*dt_size_recv;
1953 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1955 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1956 retval = MPI_SUCCESS;
1957 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1964 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1965 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1971 if (comm == MPI_COMM_NULL) {
1972 retval = MPI_ERR_COMM;
1973 } else if (sendcounts == nullptr || displs == nullptr) {
1974 retval = MPI_ERR_ARG;
1975 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1976 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1977 retval = MPI_ERR_TYPE;
1979 if (recvbuf == MPI_IN_PLACE) {
1981 recvcount=sendcounts[smpi_comm_rank(comm)];
1983 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1984 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1986 int size = smpi_comm_size(comm);
1987 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1988 extra->type = TRACING_SCATTERV;
1989 extra->num_processes = size;
1990 extra->root = root_traced;
1992 extra->datatype1 = encode_datatype(sendtype, &known);
1993 int dt_size_send = 1;
1995 dt_size_send = smpi_datatype_size(sendtype);
1996 if((smpi_comm_rank(comm)==root)){
1997 extra->sendcounts= xbt_new(int, size);
1998 for(i=0; i< size; i++)//copy data to avoid bad free
1999 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2001 extra->datatype2 = encode_datatype(recvtype, &known);
2002 int dt_size_recv = 1;
2004 dt_size_recv = smpi_datatype_size(recvtype);
2005 extra->recv_size = recvcount*dt_size_recv;
2006 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2008 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
2010 retval = MPI_SUCCESS;
2011 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2018 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2024 if (comm == MPI_COMM_NULL) {
2025 retval = MPI_ERR_COMM;
2026 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2027 retval = MPI_ERR_ARG;
2029 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2030 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2031 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2032 extra->type = TRACING_REDUCE;
2034 extra->datatype1 = encode_datatype(datatype, &known);
2035 int dt_size_send = 1;
2037 dt_size_send = smpi_datatype_size(datatype);
2038 extra->send_size = count*dt_size_send;
2039 extra->root = root_traced;
2041 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2043 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2045 retval = MPI_SUCCESS;
2046 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2053 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2057 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2058 retval = MPI_ERR_ARG;
2060 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2067 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2073 if (comm == MPI_COMM_NULL) {
2074 retval = MPI_ERR_COMM;
2075 } else if (!is_datatype_valid(datatype)) {
2076 retval = MPI_ERR_TYPE;
2077 } else if (op == MPI_OP_NULL) {
2078 retval = MPI_ERR_OP;
2081 char* sendtmpbuf = static_cast<char*>(sendbuf);
2082 if( sendbuf == MPI_IN_PLACE ) {
2083 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
2084 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2086 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2087 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2088 extra->type = TRACING_ALLREDUCE;
2090 extra->datatype1 = encode_datatype(datatype, &known);
2091 int dt_size_send = 1;
2093 dt_size_send = smpi_datatype_size(datatype);
2094 extra->send_size = count*dt_size_send;
2096 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2098 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2100 if( sendbuf == MPI_IN_PLACE )
2101 xbt_free(sendtmpbuf);
2103 retval = MPI_SUCCESS;
2104 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2111 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2117 if (comm == MPI_COMM_NULL) {
2118 retval = MPI_ERR_COMM;
2119 } else if (!is_datatype_valid(datatype)) {
2120 retval = MPI_ERR_TYPE;
2121 } else if (op == MPI_OP_NULL) {
2122 retval = MPI_ERR_OP;
2124 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2125 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2126 extra->type = TRACING_SCAN;
2128 extra->datatype1 = encode_datatype(datatype, &known);
2129 int dt_size_send = 1;
2131 dt_size_send = smpi_datatype_size(datatype);
2132 extra->send_size = count*dt_size_send;
2134 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2136 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2138 retval = MPI_SUCCESS;
2139 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2146 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2151 if (comm == MPI_COMM_NULL) {
2152 retval = MPI_ERR_COMM;
2153 } else if (!is_datatype_valid(datatype)) {
2154 retval = MPI_ERR_TYPE;
2155 } else if (op == MPI_OP_NULL) {
2156 retval = MPI_ERR_OP;
2158 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2159 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2160 extra->type = TRACING_EXSCAN;
2162 extra->datatype1 = encode_datatype(datatype, &known);
2163 int dt_size_send = 1;
2165 dt_size_send = smpi_datatype_size(datatype);
2166 extra->send_size = count*dt_size_send;
2167 void * sendtmpbuf = sendbuf;
2168 if(sendbuf==MPI_IN_PLACE){
2169 sendtmpbuf= static_cast<void*>(xbt_malloc(count*smpi_datatype_size(datatype)));
2170 memcpy(sendtmpbuf,recvbuf, count*smpi_datatype_size(datatype));
2172 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2174 smpi_mpi_exscan(sendtmpbuf, recvbuf, count, datatype, op, comm);
2175 retval = MPI_SUCCESS;
2176 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2177 if(sendbuf==MPI_IN_PLACE)
2178 xbt_free(sendtmpbuf);
2185 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2190 if (comm == MPI_COMM_NULL) {
2191 retval = MPI_ERR_COMM;
2192 } else if (!is_datatype_valid(datatype)) {
2193 retval = MPI_ERR_TYPE;
2194 } else if (op == MPI_OP_NULL) {
2195 retval = MPI_ERR_OP;
2196 } else if (recvcounts == nullptr) {
2197 retval = MPI_ERR_ARG;
2199 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2201 int size = smpi_comm_size(comm);
2202 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2203 extra->type = TRACING_REDUCE_SCATTER;
2204 extra->num_processes = size;
2206 extra->datatype1 = encode_datatype(datatype, &known);
2207 int dt_size_send = 1;
2209 dt_size_send = smpi_datatype_size(datatype);
2210 extra->send_size = 0;
2211 extra->recvcounts= xbt_new(int, size);
2213 for(i=0; i< size; i++){//copy data to avoid bad free
2214 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2215 totalcount+= recvcounts[i];
2217 void* sendtmpbuf=sendbuf;
2218 if(sendbuf==MPI_IN_PLACE){
2219 sendtmpbuf= static_cast<void*>(xbt_malloc(totalcount*smpi_datatype_size(datatype)));
2220 memcpy(sendtmpbuf,recvbuf, totalcount*smpi_datatype_size(datatype));
2223 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2225 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2226 retval = MPI_SUCCESS;
2227 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2229 if(sendbuf==MPI_IN_PLACE)
2230 xbt_free(sendtmpbuf);
2237 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2238 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2243 if (comm == MPI_COMM_NULL) {
2244 retval = MPI_ERR_COMM;
2245 } else if (!is_datatype_valid(datatype)) {
2246 retval = MPI_ERR_TYPE;
2247 } else if (op == MPI_OP_NULL) {
2248 retval = MPI_ERR_OP;
2249 } else if (recvcount < 0) {
2250 retval = MPI_ERR_ARG;
2252 int count=smpi_comm_size(comm);
2254 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2255 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2256 extra->type = TRACING_REDUCE_SCATTER;
2257 extra->num_processes = count;
2259 extra->datatype1 = encode_datatype(datatype, &known);
2260 int dt_size_send = 1;
2262 dt_size_send = smpi_datatype_size(datatype);
2263 extra->send_size = 0;
2264 extra->recvcounts= xbt_new(int, count);
2265 for(i=0; i< count; i++)//copy data to avoid bad free
2266 extra->recvcounts[i] = recvcount*dt_size_send;
2267 void* sendtmpbuf=sendbuf;
2268 if(sendbuf==MPI_IN_PLACE){
2269 sendtmpbuf= static_cast<void*>(xbt_malloc(recvcount*count*smpi_datatype_size(datatype)));
2270 memcpy(sendtmpbuf,recvbuf, recvcount*count*smpi_datatype_size(datatype));
2273 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2275 int* recvcounts=static_cast<int*>(xbt_malloc(count*sizeof(int)));
2276 for (i=0; i<count;i++)
2277 recvcounts[i]=recvcount;
2278 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2279 xbt_free(recvcounts);
2280 retval = MPI_SUCCESS;
2282 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2284 if(sendbuf==MPI_IN_PLACE)
2285 xbt_free(sendtmpbuf);
2292 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2293 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2299 if (comm == MPI_COMM_NULL) {
2300 retval = MPI_ERR_COMM;
2301 } else if ((sendbuf != MPI_IN_PLACE && sendtype == MPI_DATATYPE_NULL)
2302 || recvtype == MPI_DATATYPE_NULL) {
2303 retval = MPI_ERR_TYPE;
2305 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2306 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2307 extra->type = TRACING_ALLTOALL;
2309 void* sendtmpbuf = static_cast<char*>(sendbuf);
2310 int sendtmpcount = sendcount;
2311 MPI_Datatype sendtmptype = sendtype;
2312 if( sendbuf == MPI_IN_PLACE ) {
2313 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount*smpi_comm_size(comm)*smpi_datatype_size(recvtype)));
2314 memcpy(sendtmpbuf,recvbuf, recvcount*smpi_comm_size(comm)*smpi_datatype_size(recvtype));
2315 sendtmpcount = recvcount;
2316 sendtmptype = recvtype;
2320 extra->datatype1 = encode_datatype(sendtmptype, &known);
2322 extra->send_size = sendtmpcount*smpi_datatype_size(sendtmptype);
2324 extra->send_size = sendtmpcount;
2325 extra->datatype2 = encode_datatype(recvtype, &known);
2327 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2329 extra->recv_size = recvcount;
2331 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2333 retval = mpi_coll_alltoall_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, comm);
2335 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2337 if( sendbuf == MPI_IN_PLACE )
2338 xbt_free(sendtmpbuf);
2345 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2346 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2352 if (comm == MPI_COMM_NULL) {
2353 retval = MPI_ERR_COMM;
2354 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2355 retval = MPI_ERR_TYPE;
2356 } else if ((sendbuf!= MPI_IN_PLACE && (sendcounts == nullptr || senddisps == nullptr)) || recvcounts == nullptr || recvdisps == nullptr) {
2357 retval = MPI_ERR_ARG;
2359 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2361 int size = smpi_comm_size(comm);
2362 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2363 extra->type = TRACING_ALLTOALLV;
2364 extra->send_size = 0;
2365 extra->recv_size = 0;
2366 extra->recvcounts= xbt_new(int, size);
2367 extra->sendcounts= xbt_new(int, size);
2369 int dt_size_recv = 1;
2370 extra->datatype2 = encode_datatype(recvtype, &known);
2371 dt_size_recv = smpi_datatype_size(recvtype);
2373 void* sendtmpbuf = static_cast<char*>(sendbuf);
2374 int * sendtmpcounts = sendcounts;
2375 int *sendtmpdisps = senddisps;
2376 MPI_Datatype sendtmptype = sendtype;
2378 for(i=0; i< size; i++){//copy data to avoid bad free
2379 extra->recv_size += recvcounts[i]*dt_size_recv;
2380 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2381 if (((recvdisps[i]+recvcounts[i])*dt_size_recv) > maxsize)
2382 maxsize=(recvdisps[i]+recvcounts[i])*dt_size_recv;
2385 if( sendbuf == MPI_IN_PLACE ) {
2386 sendtmpbuf = static_cast<void*>(xbt_malloc(maxsize));
2387 memcpy(sendtmpbuf,recvbuf, maxsize);
2388 sendtmpcounts= static_cast<int*>(xbt_malloc(size*sizeof(int)));
2389 memcpy(sendtmpcounts,recvcounts, size*sizeof(int));
2390 sendtmpdisps= static_cast<int*>(xbt_malloc(size*sizeof(int)));
2391 memcpy(sendtmpdisps,recvdisps, size*sizeof(int));
2392 sendtmptype=recvtype;
2395 extra->datatype1 = encode_datatype(sendtmptype, &known);
2396 int dt_size_send = 1;
2397 dt_size_send = smpi_datatype_size(sendtmptype);
2399 for(i=0; i< size; i++){//copy data to avoid bad free
2400 extra->send_size += sendtmpcounts[i]*dt_size_send;
2401 extra->sendcounts[i] = sendtmpcounts[i]*dt_size_send;
2403 extra->num_processes = size;
2404 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2405 retval = mpi_coll_alltoallv_fun(sendtmpbuf, sendtmpcounts, sendtmpdisps, sendtmptype, recvbuf, recvcounts, recvdisps, recvtype,
2407 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2409 if( sendbuf == MPI_IN_PLACE ) {
2410 xbt_free(sendtmpbuf);
2411 xbt_free(sendtmpcounts);
2412 xbt_free(sendtmpdisps);
2421 int PMPI_Get_processor_name(char *name, int *resultlen)
2423 int retval = MPI_SUCCESS;
2425 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2426 ? strlen(SIMIX_host_self()->cname()) + 1
2427 : MPI_MAX_PROCESSOR_NAME - 1);
2428 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2433 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2435 int retval = MPI_SUCCESS;
2438 if (status == nullptr || count == nullptr) {
2439 retval = MPI_ERR_ARG;
2440 } else if (!is_datatype_valid(datatype)) {
2441 retval = MPI_ERR_TYPE;
2443 size = smpi_datatype_size(datatype);
2446 } else if (status->count % size != 0) {
2447 retval = MPI_UNDEFINED;
2449 *count = smpi_mpi_get_count(status, datatype);
2455 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2458 if (old_type == MPI_DATATYPE_NULL) {
2459 retval = MPI_ERR_TYPE;
2460 } else if (count<0){
2461 retval = MPI_ERR_COUNT;
2463 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2468 int PMPI_Type_commit(MPI_Datatype* datatype) {
2471 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2472 retval = MPI_ERR_TYPE;
2474 smpi_datatype_commit(datatype);
2475 retval = MPI_SUCCESS;
2480 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2483 if (old_type == MPI_DATATYPE_NULL) {
2484 retval = MPI_ERR_TYPE;
2485 } else if (count<0 || blocklen<0){
2486 retval = MPI_ERR_COUNT;
2488 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2493 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2496 if (old_type == MPI_DATATYPE_NULL) {
2497 retval = MPI_ERR_TYPE;
2498 } else if (count<0 || blocklen<0){
2499 retval = MPI_ERR_COUNT;
2501 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2506 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2507 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2510 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2513 if (old_type == MPI_DATATYPE_NULL) {
2514 retval = MPI_ERR_TYPE;
2515 } else if (count<0){
2516 retval = MPI_ERR_COUNT;
2518 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2523 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2526 if (old_type == MPI_DATATYPE_NULL) {
2527 retval = MPI_ERR_TYPE;
2528 } else if (count<0){
2529 retval = MPI_ERR_COUNT;
2531 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2536 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2537 MPI_Datatype* new_type) {
2540 if (old_type == MPI_DATATYPE_NULL) {
2541 retval = MPI_ERR_TYPE;
2542 } else if (count<0){
2543 retval = MPI_ERR_COUNT;
2545 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count*sizeof(int)));
2546 for (i=0; i<count;i++)
2547 blocklens[i]=blocklength;
2548 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2549 xbt_free(blocklens);
2554 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2557 if (old_type == MPI_DATATYPE_NULL) {
2558 retval = MPI_ERR_TYPE;
2559 } else if (count<0){
2560 retval = MPI_ERR_COUNT;
2562 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2567 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2568 MPI_Datatype* new_type) {
2569 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2572 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2573 MPI_Datatype* new_type) {
2576 if (old_type == MPI_DATATYPE_NULL) {
2577 retval = MPI_ERR_TYPE;
2578 } else if (count<0){
2579 retval = MPI_ERR_COUNT;
2581 int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int));
2582 for (i=0; i<count;i++)blocklens[i]=blocklength;
2583 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2584 xbt_free(blocklens);
2589 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2593 retval = MPI_ERR_COUNT;
2595 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2600 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2601 MPI_Datatype* new_type) {
2602 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2605 int PMPI_Error_class(int errorcode, int* errorclass) {
2606 // assume smpi uses only standard mpi error codes
2607 *errorclass=errorcode;
2611 int PMPI_Initialized(int* flag) {
2612 *flag=smpi_process_initialized();
2616 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2617 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2618 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2620 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2622 if (comm_old == MPI_COMM_NULL){
2623 retval = MPI_ERR_COMM;
2624 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2625 retval = MPI_ERR_ARG;
2627 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2632 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2633 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2634 return MPI_ERR_TOPOLOGY;
2636 if (coords == nullptr) {
2639 return smpi_mpi_cart_rank(comm, coords, rank);
2642 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2643 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2644 return MPI_ERR_TOPOLOGY;
2646 if (source == nullptr || dest == nullptr || direction < 0 ) {
2649 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2652 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2653 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2654 return MPI_ERR_TOPOLOGY;
2656 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2657 return MPI_ERR_RANK;
2662 if(coords == nullptr) {
2665 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2668 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2669 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2670 return MPI_ERR_TOPOLOGY;
2672 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2675 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2678 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2679 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2680 return MPI_ERR_TOPOLOGY;
2682 if (ndims == nullptr) {
2685 return smpi_mpi_cartdim_get(comm, ndims);
2688 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2689 if(dims == nullptr) {
2692 if (ndims < 1 || nnodes < 1) {
2693 return MPI_ERR_DIMS;
2696 return smpi_mpi_dims_create(nnodes, ndims, dims);
2699 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2700 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2701 return MPI_ERR_TOPOLOGY;
2703 if (comm_new == nullptr) {
2706 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2709 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2710 if(oldtype == MPI_DATATYPE_NULL) {
2711 return MPI_ERR_TYPE;
2713 int blocks[3] = { 1, 1, 1 };
2714 MPI_Aint disps[3] = { lb, 0, lb+extent };
2715 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2717 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2718 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t) , subtype, DT_FLAG_VECTOR);
2720 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2724 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2727 if (comm == MPI_COMM_NULL) {
2728 retval= MPI_ERR_COMM;
2729 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2730 retval= MPI_ERR_OTHER;
2732 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2733 retval = MPI_SUCCESS;
2739 int PMPI_Win_free( MPI_Win* win){
2742 if (win == nullptr || *win == MPI_WIN_NULL) {
2743 retval = MPI_ERR_WIN;
2745 retval=smpi_mpi_win_free(win);
2751 int PMPI_Win_set_name(MPI_Win win, char * name)
2754 if (win == MPI_WIN_NULL) {
2755 retval = MPI_ERR_TYPE;
2756 } else if (name == nullptr) {
2757 retval = MPI_ERR_ARG;
2759 smpi_mpi_win_set_name(win, name);
2760 retval = MPI_SUCCESS;
2765 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2767 int retval = MPI_SUCCESS;
2769 if (win == MPI_WIN_NULL) {
2770 retval = MPI_ERR_WIN;
2771 } else if (name == nullptr) {
2772 retval = MPI_ERR_ARG;
2774 smpi_mpi_win_get_name(win, name, len);
2779 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2780 int retval = MPI_SUCCESS;
2781 if (win == MPI_WIN_NULL) {
2782 retval = MPI_ERR_WIN;
2784 smpi_mpi_win_get_group(win, group);
2785 smpi_group_use(*group);
2791 int PMPI_Win_fence( int assert, MPI_Win win){
2794 if (win == MPI_WIN_NULL) {
2795 retval = MPI_ERR_WIN;
2797 int rank = smpi_process_index();
2798 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2799 retval = smpi_mpi_win_fence(assert, win);
2800 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2806 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2807 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2810 if (win == MPI_WIN_NULL) {
2811 retval = MPI_ERR_WIN;
2812 } else if (target_rank == MPI_PROC_NULL) {
2813 retval = MPI_SUCCESS;
2814 } else if (target_rank <0){
2815 retval = MPI_ERR_RANK;
2816 } else if (target_disp <0){
2817 retval = MPI_ERR_ARG;
2818 } else if ((origin_count < 0 || target_count < 0) ||
2819 (origin_addr==nullptr && origin_count > 0)){
2820 retval = MPI_ERR_COUNT;
2821 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2822 retval = MPI_ERR_TYPE;
2824 int rank = smpi_process_index();
2826 smpi_mpi_win_get_group(win, &group);
2827 int src_traced = smpi_group_index(group, target_rank);
2828 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2830 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2831 target_datatype, win);
2833 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2839 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2840 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2843 if (win == MPI_WIN_NULL) {
2844 retval = MPI_ERR_WIN;
2845 } else if (target_rank == MPI_PROC_NULL) {
2846 retval = MPI_SUCCESS;
2847 } else if (target_rank <0){
2848 retval = MPI_ERR_RANK;
2849 } else if (target_disp <0){
2850 retval = MPI_ERR_ARG;
2851 } else if ((origin_count < 0 || target_count < 0) ||
2852 (origin_addr==nullptr && origin_count > 0)){
2853 retval = MPI_ERR_COUNT;
2854 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2855 retval = MPI_ERR_TYPE;
2857 int rank = smpi_process_index();
2859 smpi_mpi_win_get_group(win, &group);
2860 int dst_traced = smpi_group_index(group, target_rank);
2861 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2862 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2864 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2865 target_datatype, win);
2867 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2873 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2874 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2877 if (win == MPI_WIN_NULL) {
2878 retval = MPI_ERR_WIN;
2879 } else if (target_rank == MPI_PROC_NULL) {
2880 retval = MPI_SUCCESS;
2881 } else if (target_rank <0){
2882 retval = MPI_ERR_RANK;
2883 } else if (target_disp <0){
2884 retval = MPI_ERR_ARG;
2885 } else if ((origin_count < 0 || target_count < 0) ||
2886 (origin_addr==nullptr && origin_count > 0)){
2887 retval = MPI_ERR_COUNT;
2888 } else if ((!is_datatype_valid(origin_datatype)) ||
2889 (!is_datatype_valid(target_datatype))) {
2890 retval = MPI_ERR_TYPE;
2891 } else if (op == MPI_OP_NULL) {
2892 retval = MPI_ERR_OP;
2894 int rank = smpi_process_index();
2896 smpi_mpi_win_get_group(win, &group);
2897 int src_traced = smpi_group_index(group, target_rank);
2898 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2900 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2901 target_datatype, op, win);
2903 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2909 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2912 if (win == MPI_WIN_NULL) {
2913 retval = MPI_ERR_WIN;
2914 } else if (group==MPI_GROUP_NULL){
2915 retval = MPI_ERR_GROUP;
2918 int rank = smpi_process_index();
2919 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2920 retval = smpi_mpi_win_post(group,assert,win);
2921 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2927 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2930 if (win == MPI_WIN_NULL) {
2931 retval = MPI_ERR_WIN;
2932 } else if (group==MPI_GROUP_NULL){
2933 retval = MPI_ERR_GROUP;
2936 int rank = smpi_process_index();
2937 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2938 retval = smpi_mpi_win_start(group,assert,win);
2939 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2945 int PMPI_Win_complete(MPI_Win win){
2948 if (win == MPI_WIN_NULL) {
2949 retval = MPI_ERR_WIN;
2952 int rank = smpi_process_index();
2953 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2955 retval = smpi_mpi_win_complete(win);
2957 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2963 int PMPI_Win_wait(MPI_Win win){
2966 if (win == MPI_WIN_NULL) {
2967 retval = MPI_ERR_WIN;
2970 int rank = smpi_process_index();
2971 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2973 retval = smpi_mpi_win_wait(win);
2975 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2981 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2982 void *ptr = xbt_malloc(size);
2984 return MPI_ERR_NO_MEM;
2986 *static_cast<void**>(baseptr) = ptr;
2991 int PMPI_Free_mem(void *baseptr){
2996 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2999 if (datatype == MPI_DATATYPE_NULL) {
3000 retval = MPI_ERR_TYPE;
3001 } else if (name == nullptr) {
3002 retval = MPI_ERR_ARG;
3004 smpi_datatype_set_name(datatype, name);
3005 retval = MPI_SUCCESS;
3010 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
3014 if (datatype == MPI_DATATYPE_NULL) {
3015 retval = MPI_ERR_TYPE;
3016 } else if (name == nullptr) {
3017 retval = MPI_ERR_ARG;
3019 smpi_datatype_get_name(datatype, name, len);
3020 retval = MPI_SUCCESS;
3025 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
3026 return smpi_type_f2c(datatype);
3029 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
3030 return smpi_type_c2f( datatype);
3033 MPI_Group PMPI_Group_f2c(MPI_Fint group){
3034 return smpi_group_f2c( group);
3037 MPI_Fint PMPI_Group_c2f(MPI_Group group){
3038 return smpi_group_c2f(group);
3041 MPI_Request PMPI_Request_f2c(MPI_Fint request){
3042 return smpi_request_f2c(request);
3045 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
3046 return smpi_request_c2f(request);
3049 MPI_Win PMPI_Win_f2c(MPI_Fint win){
3050 return smpi_win_f2c(win);
3053 MPI_Fint PMPI_Win_c2f(MPI_Win win){
3054 return smpi_win_c2f(win);
3057 MPI_Op PMPI_Op_f2c(MPI_Fint op){
3058 return smpi_op_f2c(op);
3061 MPI_Fint PMPI_Op_c2f(MPI_Op op){
3062 return smpi_op_c2f(op);
3065 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
3066 return smpi_comm_f2c(comm);
3069 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
3070 return smpi_comm_c2f(comm);
3073 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3074 return smpi_info_f2c(info);
3077 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3078 return smpi_info_c2f(info);
3081 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3082 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3085 int PMPI_Keyval_free(int* keyval) {
3086 return smpi_comm_keyval_free(keyval);
3089 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3090 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3091 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3093 else if (comm==MPI_COMM_NULL)
3094 return MPI_ERR_COMM;
3096 return smpi_comm_attr_delete(comm, keyval);
3099 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3101 static int zero = 0;
3102 static int tag_ub = 1000000;
3103 static int last_used_code = MPI_ERR_LASTCODE;
3105 if (comm==MPI_COMM_NULL){
3107 return MPI_ERR_COMM;
3115 *static_cast<int**>(attr_value) = &zero;
3117 case MPI_UNIVERSE_SIZE:
3119 *static_cast<int**>(attr_value) = &smpi_universe_size;
3121 case MPI_LASTUSEDCODE:
3123 *static_cast<int**>(attr_value) = &last_used_code;
3127 *static_cast<int**>(attr_value) = &tag_ub;
3129 case MPI_WTIME_IS_GLOBAL:
3131 *static_cast<int**>(attr_value) = &one;
3134 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3138 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3139 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3140 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3142 else if (comm==MPI_COMM_NULL)
3143 return MPI_ERR_COMM;
3145 return smpi_comm_attr_put(comm, keyval, attr_value);
3148 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3150 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3153 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3155 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3158 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3160 return PMPI_Attr_delete(comm, comm_keyval);
3163 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3166 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3169 int PMPI_Comm_free_keyval(int* keyval) {
3170 return PMPI_Keyval_free(keyval);
3173 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3175 if (type==MPI_DATATYPE_NULL)
3176 return MPI_ERR_TYPE;
3178 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3181 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3183 if (type==MPI_DATATYPE_NULL)
3184 return MPI_ERR_TYPE;
3186 return smpi_type_attr_put(type, type_keyval, attribute_val);
3189 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3191 if (type==MPI_DATATYPE_NULL)
3192 return MPI_ERR_TYPE;
3194 return smpi_type_attr_delete(type, type_keyval);
3197 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3200 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3203 int PMPI_Type_free_keyval(int* keyval) {
3204 return smpi_type_keyval_free(keyval);
3207 int PMPI_Info_create( MPI_Info *info){
3208 if (info == nullptr)
3210 *info = xbt_new(s_smpi_mpi_info_t, 1);
3211 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3212 (*info)->refcount=1;
3216 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3217 if (info == nullptr || key == nullptr || value == nullptr)
3220 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
3224 int PMPI_Info_free( MPI_Info *info){
3225 if (info == nullptr || *info==nullptr)
3227 (*info)->refcount--;
3228 if((*info)->refcount==0){
3229 xbt_dict_free(&((*info)->info_dict));
3232 *info=MPI_INFO_NULL;
3236 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3238 if (info == nullptr || key == nullptr || valuelen <0)
3240 if (value == nullptr)
3241 return MPI_ERR_INFO_VALUE;
3242 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
3244 memset(value, 0, valuelen);
3245 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3251 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3252 if (info == nullptr || newinfo==nullptr)
3254 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3255 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3256 (*newinfo)->refcount=1;
3257 xbt_dict_cursor_t cursor = nullptr;
3260 xbt_dict_foreach(info->info_dict,cursor,key,data){
3261 xbt_dict_set((*newinfo)->info_dict, reinterpret_cast<char*>(key), xbt_strdup(reinterpret_cast<char*>(data)), nullptr);
3266 int PMPI_Info_delete(MPI_Info info, char *key){
3267 if (info == nullptr || key==nullptr)
3270 xbt_dict_remove(info->info_dict, key);
3273 return MPI_ERR_INFO_NOKEY;
3278 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3279 if (info == nullptr || nkeys==nullptr)
3281 *nkeys=xbt_dict_size(info->info_dict);
3285 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3286 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
3289 xbt_dict_cursor_t cursor = nullptr;
3293 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3295 strncpy(key,keyn,strlen(keyn)+1);
3296 xbt_dict_cursor_free(&cursor);
3304 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3306 if (info == nullptr || key == nullptr || valuelen==nullptr)
3308 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3310 *valuelen=strlen(tmpvalue);
3316 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3317 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3319 if(!is_datatype_valid(type))
3320 return MPI_ERR_TYPE;
3321 if(comm==MPI_COMM_NULL)
3322 return MPI_ERR_COMM;
3323 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3326 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3327 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3329 if(!is_datatype_valid(type))
3330 return MPI_ERR_TYPE;
3331 if(comm==MPI_COMM_NULL)
3332 return MPI_ERR_COMM;
3333 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3336 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3339 if(!is_datatype_valid(datatype))
3340 return MPI_ERR_TYPE;
3341 if(comm==MPI_COMM_NULL)
3342 return MPI_ERR_COMM;
3344 *size=incount*smpi_datatype_size(datatype);