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_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
191 if (datatype == MPI_DATATYPE_NULL) {
192 retval = MPI_ERR_TYPE;
193 } else if (lb == nullptr || extent == nullptr) {
194 retval = MPI_ERR_ARG;
196 retval = smpi_datatype_extent(datatype, lb, extent);
201 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
203 return PMPI_Type_get_extent(datatype, lb, extent);
206 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
210 if (datatype == MPI_DATATYPE_NULL) {
211 retval = MPI_ERR_TYPE;
212 } else if (extent == nullptr) {
213 retval = MPI_ERR_ARG;
215 *extent = smpi_datatype_get_extent(datatype);
216 retval = MPI_SUCCESS;
221 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
225 if (datatype == MPI_DATATYPE_NULL) {
226 retval = MPI_ERR_TYPE;
227 } else if (disp == nullptr) {
228 retval = MPI_ERR_ARG;
230 *disp = smpi_datatype_lb(datatype);
231 retval = MPI_SUCCESS;
236 int PMPI_Type_ub(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_ub(datatype);
246 retval = MPI_SUCCESS;
251 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
254 if (datatype == MPI_DATATYPE_NULL) {
255 retval = MPI_ERR_TYPE;
257 retval = smpi_datatype_dup(datatype, newtype);
262 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
266 if (function == nullptr || op == nullptr) {
267 retval = MPI_ERR_ARG;
269 *op = smpi_op_new(function, (commute!=0));
270 retval = MPI_SUCCESS;
275 int PMPI_Op_free(MPI_Op * op)
280 retval = MPI_ERR_ARG;
281 } else if (*op == MPI_OP_NULL) {
284 smpi_op_destroy(*op);
286 retval = MPI_SUCCESS;
291 int PMPI_Group_free(MPI_Group * group)
295 if (group == nullptr) {
296 retval = MPI_ERR_ARG;
298 smpi_group_destroy(*group);
299 *group = MPI_GROUP_NULL;
300 retval = MPI_SUCCESS;
305 int PMPI_Group_size(MPI_Group group, int *size)
309 if (group == MPI_GROUP_NULL) {
310 retval = MPI_ERR_GROUP;
311 } else if (size == nullptr) {
312 retval = MPI_ERR_ARG;
314 *size = smpi_group_size(group);
315 retval = MPI_SUCCESS;
320 int PMPI_Group_rank(MPI_Group group, int *rank)
324 if (group == MPI_GROUP_NULL) {
325 retval = MPI_ERR_GROUP;
326 } else if (rank == nullptr) {
327 retval = MPI_ERR_ARG;
329 *rank = smpi_group_rank(group, smpi_process_index());
330 retval = MPI_SUCCESS;
335 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
337 int retval, i, index;
338 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
339 retval = MPI_ERR_GROUP;
341 for (i = 0; i < n; i++) {
342 if(ranks1[i]==MPI_PROC_NULL){
343 ranks2[i]=MPI_PROC_NULL;
345 index = smpi_group_index(group1, ranks1[i]);
346 ranks2[i] = smpi_group_rank(group2, index);
349 retval = MPI_SUCCESS;
354 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
358 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
359 retval = MPI_ERR_GROUP;
360 } else if (result == nullptr) {
361 retval = MPI_ERR_ARG;
363 *result = smpi_group_compare(group1, group2);
364 retval = MPI_SUCCESS;
369 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
371 int retval, i, proc1, proc2, size, size2;
373 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
374 retval = MPI_ERR_GROUP;
375 } else if (newgroup == nullptr) {
376 retval = MPI_ERR_ARG;
378 size = smpi_group_size(group1);
379 size2 = smpi_group_size(group2);
380 for (i = 0; i < size2; i++) {
381 proc2 = smpi_group_index(group2, i);
382 proc1 = smpi_group_rank(group1, proc2);
383 if (proc1 == MPI_UNDEFINED) {
388 *newgroup = MPI_GROUP_EMPTY;
390 *newgroup = smpi_group_new(size);
391 size2 = smpi_group_size(group1);
392 for (i = 0; i < size2; i++) {
393 proc1 = smpi_group_index(group1, i);
394 smpi_group_set_mapping(*newgroup, proc1, i);
396 for (i = size2; i < size; i++) {
397 proc2 = smpi_group_index(group2, i - size2);
398 smpi_group_set_mapping(*newgroup, proc2, i);
401 retval = MPI_SUCCESS;
406 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
408 int retval, i, proc1, proc2, size;
410 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
411 retval = MPI_ERR_GROUP;
412 } else if (newgroup == nullptr) {
413 retval = MPI_ERR_ARG;
415 size = smpi_group_size(group2);
416 for (i = 0; i < size; i++) {
417 proc2 = smpi_group_index(group2, i);
418 proc1 = smpi_group_rank(group1, proc2);
419 if (proc1 == MPI_UNDEFINED) {
424 *newgroup = MPI_GROUP_EMPTY;
426 *newgroup = smpi_group_new(size);
428 for (i = 0; i < smpi_group_size(group2); i++) {
429 proc2 = smpi_group_index(group2, i);
430 proc1 = smpi_group_rank(group1, proc2);
431 if (proc1 != MPI_UNDEFINED) {
432 smpi_group_set_mapping(*newgroup, proc2, j);
437 retval = MPI_SUCCESS;
442 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
444 int retval, i, proc1, proc2, size, size2;
446 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
447 retval = MPI_ERR_GROUP;
448 } else if (newgroup == nullptr) {
449 retval = MPI_ERR_ARG;
451 size = smpi_group_size(group1);
453 for (i = 0; i < size2; i++) {
454 proc1 = smpi_group_index(group1, i);
455 proc2 = smpi_group_rank(group2, proc1);
456 if (proc2 != MPI_UNDEFINED) {
461 *newgroup = MPI_GROUP_EMPTY;
463 *newgroup = smpi_group_new(size);
464 for (i = 0; i < size2; i++) {
465 proc1 = smpi_group_index(group1, i);
466 proc2 = smpi_group_rank(group2, proc1);
467 if (proc2 == MPI_UNDEFINED) {
468 smpi_group_set_mapping(*newgroup, proc1, i);
472 retval = MPI_SUCCESS;
477 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
481 if (group == MPI_GROUP_NULL) {
482 retval = MPI_ERR_GROUP;
483 } else if (newgroup == nullptr) {
484 retval = MPI_ERR_ARG;
486 retval = smpi_group_incl(group, n, ranks, newgroup);
491 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
493 int retval, i, j, newsize, oldsize, index;
495 if (group == MPI_GROUP_NULL) {
496 retval = MPI_ERR_GROUP;
497 } else if (newgroup == nullptr) {
498 retval = MPI_ERR_ARG;
502 if(group!= smpi_comm_group(MPI_COMM_WORLD) && group != MPI_GROUP_NULL
503 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
504 smpi_group_use(group);
505 } else if (n == smpi_group_size(group)) {
506 *newgroup = MPI_GROUP_EMPTY;
508 oldsize=smpi_group_size(group);
509 newsize = oldsize - n;
510 *newgroup = smpi_group_new(newsize);
512 int* to_exclude=xbt_new0(int, smpi_group_size(group));
513 for(i=0; i<oldsize; i++)
516 to_exclude[ranks[i]]=1;
519 for(i=0; i<oldsize; i++){
520 if(to_exclude[i]==0){
521 index = smpi_group_index(group, i);
522 smpi_group_set_mapping(*newgroup, index, j);
527 xbt_free(to_exclude);
529 retval = MPI_SUCCESS;
534 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
536 int retval, i, j, rank, size, index;
538 if (group == MPI_GROUP_NULL) {
539 retval = MPI_ERR_GROUP;
540 } else if (newgroup == nullptr) {
541 retval = MPI_ERR_ARG;
544 *newgroup = MPI_GROUP_EMPTY;
547 for (i = 0; i < n; i++) {
548 for (rank = ranges[i][0]; /* First */
549 rank >= 0 && rank < smpi_group_size(group); /* Last */
552 if(rank == ranges[i][1]){/*already last ?*/
555 rank += ranges[i][2]; /* Stride */
556 if (ranges[i][0]<ranges[i][1]){
557 if(rank > ranges[i][1])
560 if(rank < ranges[i][1])
566 *newgroup = smpi_group_new(size);
568 for (i = 0; i < n; i++) {
569 for (rank = ranges[i][0]; /* First */
570 rank >= 0 && rank < smpi_group_size(group); /* Last */
572 index = smpi_group_index(group, rank);
573 smpi_group_set_mapping(*newgroup, index, j);
575 if(rank == ranges[i][1]){/*already last ?*/
578 rank += ranges[i][2]; /* Stride */
579 if (ranges[i][0]<ranges[i][1]){
580 if(rank > ranges[i][1])
583 if(rank < ranges[i][1])
589 retval = MPI_SUCCESS;
594 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
596 int retval, i, rank, newrank,oldrank, size, index, add;
598 if (group == MPI_GROUP_NULL) {
599 retval = MPI_ERR_GROUP;
600 } else if (newgroup == nullptr) {
601 retval = MPI_ERR_ARG;
605 if(group!= smpi_comm_group(MPI_COMM_WORLD) && group != MPI_GROUP_NULL
606 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
607 smpi_group_use(group);
609 size = smpi_group_size(group);
610 for (i = 0; i < n; i++) {
611 for (rank = ranges[i][0]; /* First */
612 rank >= 0 && rank < smpi_group_size(group); /* Last */
615 if(rank == ranges[i][1]){/*already last ?*/
618 rank += ranges[i][2]; /* Stride */
619 if (ranges[i][0]<ranges[i][1]){
620 if(rank > ranges[i][1])
623 if(rank < ranges[i][1])
629 *newgroup = MPI_GROUP_EMPTY;
631 *newgroup = smpi_group_new(size);
634 while (newrank < size) {
636 for (i = 0; i < n; i++) {
637 for (rank = ranges[i][0];
638 rank >= 0 && rank < smpi_group_size(group);
644 if(rank == ranges[i][1]){/*already last ?*/
647 rank += ranges[i][2]; /* Stride */
648 if (ranges[i][0]<ranges[i][1]){
649 if(rank > ranges[i][1])
652 if(rank < ranges[i][1])
658 index = smpi_group_index(group, oldrank);
659 smpi_group_set_mapping(*newgroup, index, newrank);
667 retval = MPI_SUCCESS;
672 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
675 if (comm == MPI_COMM_NULL) {
676 retval = MPI_ERR_COMM;
677 } else if (rank == nullptr) {
678 retval = MPI_ERR_ARG;
680 *rank = smpi_comm_rank(comm);
681 retval = MPI_SUCCESS;
686 int PMPI_Comm_size(MPI_Comm comm, int *size)
689 if (comm == MPI_COMM_NULL) {
690 retval = MPI_ERR_COMM;
691 } else if (size == nullptr) {
692 retval = MPI_ERR_ARG;
694 *size = smpi_comm_size(comm);
695 retval = MPI_SUCCESS;
700 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
704 if (comm == MPI_COMM_NULL) {
705 retval = MPI_ERR_COMM;
706 } else if (name == nullptr || len == nullptr) {
707 retval = MPI_ERR_ARG;
709 smpi_comm_get_name(comm, name, len);
710 retval = MPI_SUCCESS;
715 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
719 if (comm == MPI_COMM_NULL) {
720 retval = MPI_ERR_COMM;
721 } else if (group == nullptr) {
722 retval = MPI_ERR_ARG;
724 *group = smpi_comm_group(comm);
725 if(*group!= smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL
726 && *group != MPI_GROUP_EMPTY)
727 smpi_group_use(*group);
728 retval = MPI_SUCCESS;
733 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
737 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
738 retval = MPI_ERR_COMM;
739 } else if (result == nullptr) {
740 retval = MPI_ERR_ARG;
742 if (comm1 == comm2) { /* Same communicators means same groups */
745 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
746 if (*result == MPI_IDENT) {
747 *result = MPI_CONGRUENT;
750 retval = MPI_SUCCESS;
755 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
759 if (comm == MPI_COMM_NULL) {
760 retval = MPI_ERR_COMM;
761 } else if (newcomm == nullptr) {
762 retval = MPI_ERR_ARG;
764 retval = smpi_comm_dup(comm, newcomm);
769 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
773 if (comm == MPI_COMM_NULL) {
774 retval = MPI_ERR_COMM;
775 } else if (group == MPI_GROUP_NULL) {
776 retval = MPI_ERR_GROUP;
777 } else if (newcomm == nullptr) {
778 retval = MPI_ERR_ARG;
779 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
780 *newcomm= MPI_COMM_NULL;
781 retval = MPI_SUCCESS;
783 smpi_group_use(group);
784 *newcomm = smpi_comm_new(group, nullptr);
785 retval = MPI_SUCCESS;
790 int PMPI_Comm_free(MPI_Comm * comm)
794 if (comm == nullptr) {
795 retval = MPI_ERR_ARG;
796 } else if (*comm == MPI_COMM_NULL) {
797 retval = MPI_ERR_COMM;
799 smpi_comm_destroy(*comm);
800 *comm = MPI_COMM_NULL;
801 retval = MPI_SUCCESS;
806 int PMPI_Comm_disconnect(MPI_Comm * comm)
808 /* TODO: wait until all communication in comm are done */
811 if (comm == nullptr) {
812 retval = MPI_ERR_ARG;
813 } else if (*comm == MPI_COMM_NULL) {
814 retval = MPI_ERR_COMM;
816 smpi_comm_destroy(*comm);
817 *comm = MPI_COMM_NULL;
818 retval = MPI_SUCCESS;
823 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
828 if (comm_out == nullptr) {
829 retval = MPI_ERR_ARG;
830 } else if (comm == MPI_COMM_NULL) {
831 retval = MPI_ERR_COMM;
833 *comm_out = smpi_comm_split(comm, color, key);
834 retval = MPI_SUCCESS;
841 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
846 if (request == nullptr) {
847 retval = MPI_ERR_ARG;
848 } else if (comm == MPI_COMM_NULL) {
849 retval = MPI_ERR_COMM;
850 } else if (!is_datatype_valid(datatype)) {
851 retval = MPI_ERR_TYPE;
852 } else if (dst == MPI_PROC_NULL) {
853 retval = MPI_SUCCESS;
855 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
856 retval = MPI_SUCCESS;
859 if (retval != MPI_SUCCESS && request != nullptr)
860 *request = MPI_REQUEST_NULL;
864 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
869 if (request == nullptr) {
870 retval = MPI_ERR_ARG;
871 } else if (comm == MPI_COMM_NULL) {
872 retval = MPI_ERR_COMM;
873 } else if (!is_datatype_valid(datatype)) {
874 retval = MPI_ERR_TYPE;
875 } else if (src == MPI_PROC_NULL) {
876 retval = MPI_SUCCESS;
878 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
879 retval = MPI_SUCCESS;
882 if (retval != MPI_SUCCESS && request != nullptr)
883 *request = MPI_REQUEST_NULL;
887 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
892 if (request == nullptr) {
893 retval = MPI_ERR_ARG;
894 } else if (comm == MPI_COMM_NULL) {
895 retval = MPI_ERR_COMM;
896 } else if (!is_datatype_valid(datatype)) {
897 retval = MPI_ERR_TYPE;
898 } else if (dst == MPI_PROC_NULL) {
899 retval = MPI_SUCCESS;
901 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
902 retval = MPI_SUCCESS;
905 if (retval != MPI_SUCCESS && request != nullptr)
906 *request = MPI_REQUEST_NULL;
910 int PMPI_Start(MPI_Request * request)
915 if (request == nullptr || *request == MPI_REQUEST_NULL) {
916 retval = MPI_ERR_REQUEST;
918 smpi_mpi_start(*request);
919 retval = MPI_SUCCESS;
925 int PMPI_Startall(int count, MPI_Request * requests)
930 if (requests == nullptr) {
931 retval = MPI_ERR_ARG;
933 retval = MPI_SUCCESS;
934 for (i = 0 ; i < count ; i++) {
935 if(requests[i] == MPI_REQUEST_NULL) {
936 retval = MPI_ERR_REQUEST;
939 if(retval != MPI_ERR_REQUEST) {
940 smpi_mpi_startall(count, requests);
947 int PMPI_Request_free(MPI_Request * request)
952 if (*request == MPI_REQUEST_NULL) {
953 retval = MPI_ERR_ARG;
955 smpi_mpi_request_free(request);
956 retval = MPI_SUCCESS;
962 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
968 if (request == nullptr) {
969 retval = MPI_ERR_ARG;
970 } else if (comm == MPI_COMM_NULL) {
971 retval = MPI_ERR_COMM;
972 } else if (src == MPI_PROC_NULL) {
973 *request = MPI_REQUEST_NULL;
974 retval = MPI_SUCCESS;
975 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
976 retval = MPI_ERR_RANK;
977 } else if ((count < 0) || (buf==nullptr && count > 0)) {
978 retval = MPI_ERR_COUNT;
979 } else if (!is_datatype_valid(datatype)) {
980 retval = MPI_ERR_TYPE;
981 } else if(tag<0 && tag != MPI_ANY_TAG){
982 retval = MPI_ERR_TAG;
985 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
986 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
988 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
989 extra->type = TRACING_IRECV;
990 extra->src = src_traced;
993 extra->datatype1 = encode_datatype(datatype, &known);
994 int dt_size_send = 1;
996 dt_size_send = smpi_datatype_size(datatype);
997 extra->send_size = count*dt_size_send;
998 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1000 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1001 retval = MPI_SUCCESS;
1003 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1004 (*request)->recv = 1;
1008 if (retval != MPI_SUCCESS && request != nullptr)
1009 *request = MPI_REQUEST_NULL;
1014 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1019 if (request == nullptr) {
1020 retval = MPI_ERR_ARG;
1021 } else if (comm == MPI_COMM_NULL) {
1022 retval = MPI_ERR_COMM;
1023 } else if (dst == MPI_PROC_NULL) {
1024 *request = MPI_REQUEST_NULL;
1025 retval = MPI_SUCCESS;
1026 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1027 retval = MPI_ERR_RANK;
1028 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1029 retval = MPI_ERR_COUNT;
1030 } else if (!is_datatype_valid(datatype)) {
1031 retval = MPI_ERR_TYPE;
1032 } else if(tag<0 && tag != MPI_ANY_TAG){
1033 retval = MPI_ERR_TAG;
1036 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1037 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1038 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1039 extra->type = TRACING_ISEND;
1041 extra->dst = dst_traced;
1043 extra->datatype1 = encode_datatype(datatype, &known);
1044 int dt_size_send = 1;
1046 dt_size_send = smpi_datatype_size(datatype);
1047 extra->send_size = count*dt_size_send;
1048 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1049 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1051 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1052 retval = MPI_SUCCESS;
1054 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1055 (*request)->send = 1;
1059 if (retval != MPI_SUCCESS && request!=nullptr)
1060 *request = MPI_REQUEST_NULL;
1064 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
1069 if (request == nullptr) {
1070 retval = MPI_ERR_ARG;
1071 } else if (comm == MPI_COMM_NULL) {
1072 retval = MPI_ERR_COMM;
1073 } else if (dst == MPI_PROC_NULL) {
1074 *request = MPI_REQUEST_NULL;
1075 retval = MPI_SUCCESS;
1076 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1077 retval = MPI_ERR_RANK;
1078 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
1079 retval = MPI_ERR_COUNT;
1080 } else if (!is_datatype_valid(datatype)) {
1081 retval = MPI_ERR_TYPE;
1082 } else if(tag<0 && tag != MPI_ANY_TAG){
1083 retval = MPI_ERR_TAG;
1086 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1087 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1088 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1089 extra->type = TRACING_ISSEND;
1091 extra->dst = dst_traced;
1093 extra->datatype1 = encode_datatype(datatype, &known);
1094 int dt_size_send = 1;
1096 dt_size_send = smpi_datatype_size(datatype);
1097 extra->send_size = count*dt_size_send;
1098 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1099 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
1101 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1102 retval = MPI_SUCCESS;
1104 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1105 (*request)->send = 1;
1109 if (retval != MPI_SUCCESS && request!=nullptr)
1110 *request = MPI_REQUEST_NULL;
1114 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1119 if (comm == MPI_COMM_NULL) {
1120 retval = MPI_ERR_COMM;
1121 } else if (src == MPI_PROC_NULL) {
1122 smpi_empty_status(status);
1123 status->MPI_SOURCE = MPI_PROC_NULL;
1124 retval = MPI_SUCCESS;
1125 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1126 retval = MPI_ERR_RANK;
1127 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1128 retval = MPI_ERR_COUNT;
1129 } else if (!is_datatype_valid(datatype)) {
1130 retval = MPI_ERR_TYPE;
1131 } else if(tag<0 && tag != MPI_ANY_TAG){
1132 retval = MPI_ERR_TAG;
1134 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1135 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1136 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1137 extra->type = TRACING_RECV;
1138 extra->src = src_traced;
1141 extra->datatype1 = encode_datatype(datatype, &known);
1142 int dt_size_send = 1;
1144 dt_size_send = smpi_datatype_size(datatype);
1145 extra->send_size = count*dt_size_send;
1146 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1148 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1149 retval = MPI_SUCCESS;
1151 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1152 if(status!=MPI_STATUS_IGNORE){
1153 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1154 if (!TRACE_smpi_view_internals()) {
1155 TRACE_smpi_recv(rank, src_traced, rank, tag);
1158 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1165 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1171 if (comm == MPI_COMM_NULL) {
1172 retval = MPI_ERR_COMM;
1173 } else if (dst == MPI_PROC_NULL) {
1174 retval = MPI_SUCCESS;
1175 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1176 retval = MPI_ERR_RANK;
1177 } else if ((count < 0) || (buf == nullptr && count > 0)) {
1178 retval = MPI_ERR_COUNT;
1179 } else if (!is_datatype_valid(datatype)) {
1180 retval = MPI_ERR_TYPE;
1181 } else if(tag < 0 && tag != MPI_ANY_TAG){
1182 retval = MPI_ERR_TAG;
1184 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1185 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1186 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1187 extra->type = TRACING_SEND;
1189 extra->dst = dst_traced;
1191 extra->datatype1 = encode_datatype(datatype, &known);
1192 int dt_size_send = 1;
1194 dt_size_send = smpi_datatype_size(datatype);
1196 extra->send_size = count*dt_size_send;
1197 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1198 if (!TRACE_smpi_view_internals()) {
1199 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1202 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1203 retval = MPI_SUCCESS;
1205 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1212 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1217 if (comm == MPI_COMM_NULL) {
1218 retval = MPI_ERR_COMM;
1219 } else if (dst == MPI_PROC_NULL) {
1220 retval = MPI_SUCCESS;
1221 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1222 retval = MPI_ERR_RANK;
1223 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1224 retval = MPI_ERR_COUNT;
1225 } else if (!is_datatype_valid(datatype)){
1226 retval = MPI_ERR_TYPE;
1227 } else if(tag<0 && tag != MPI_ANY_TAG){
1228 retval = MPI_ERR_TAG;
1230 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1231 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1232 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1233 extra->type = TRACING_SSEND;
1235 extra->dst = dst_traced;
1237 extra->datatype1 = encode_datatype(datatype, &known);
1238 int dt_size_send = 1;
1240 dt_size_send = smpi_datatype_size(datatype);
1242 extra->send_size = count*dt_size_send;
1243 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1244 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
1246 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1247 retval = MPI_SUCCESS;
1249 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1256 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1257 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1263 if (comm == MPI_COMM_NULL) {
1264 retval = MPI_ERR_COMM;
1265 } else if (!is_datatype_valid(sendtype)
1266 || !is_datatype_valid(recvtype)) {
1267 retval = MPI_ERR_TYPE;
1268 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1269 smpi_empty_status(status);
1270 status->MPI_SOURCE = MPI_PROC_NULL;
1271 retval = MPI_SUCCESS;
1272 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1273 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1274 retval = MPI_ERR_RANK;
1275 } else if ((sendcount < 0 || recvcount<0) ||
1276 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1277 retval = MPI_ERR_COUNT;
1278 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1279 retval = MPI_ERR_TAG;
1282 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1283 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1284 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1285 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1286 extra->type = TRACING_SENDRECV;
1287 extra->src = src_traced;
1288 extra->dst = dst_traced;
1290 extra->datatype1 = encode_datatype(sendtype, &known);
1291 int dt_size_send = 1;
1293 dt_size_send = smpi_datatype_size(sendtype);
1294 extra->send_size = sendcount*dt_size_send;
1295 extra->datatype2 = encode_datatype(recvtype, &known);
1296 int dt_size_recv = 1;
1298 dt_size_recv = smpi_datatype_size(recvtype);
1299 extra->recv_size = recvcount*dt_size_recv;
1301 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1302 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1304 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1305 recvcount, recvtype, src, recvtag, comm, status);
1306 retval = MPI_SUCCESS;
1308 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1309 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1316 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1317 MPI_Comm comm, MPI_Status * status)
1321 if (!is_datatype_valid(datatype)) {
1322 retval = MPI_ERR_TYPE;
1323 } else if (count < 0) {
1324 retval = MPI_ERR_COUNT;
1326 int size = smpi_datatype_get_extent(datatype) * count;
1327 recvbuf = xbt_new0(char, size);
1328 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1329 if(retval==MPI_SUCCESS){
1330 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1338 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1342 if (request == nullptr || flag == nullptr) {
1343 retval = MPI_ERR_ARG;
1344 } else if (*request == MPI_REQUEST_NULL) {
1346 smpi_empty_status(status);
1347 retval = MPI_SUCCESS;
1349 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1351 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1352 extra->type = TRACING_TEST;
1353 TRACE_smpi_testing_in(rank, extra);
1355 *flag = smpi_mpi_test(request, status);
1357 TRACE_smpi_testing_out(rank);
1358 retval = MPI_SUCCESS;
1364 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1369 if (index == nullptr || flag == nullptr) {
1370 retval = MPI_ERR_ARG;
1372 *flag = smpi_mpi_testany(count, requests, index, status);
1373 retval = MPI_SUCCESS;
1379 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1384 if (flag == nullptr) {
1385 retval = MPI_ERR_ARG;
1387 *flag = smpi_mpi_testall(count, requests, statuses);
1388 retval = MPI_SUCCESS;
1394 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1398 if (status == nullptr) {
1399 retval = MPI_ERR_ARG;
1400 } else if (comm == MPI_COMM_NULL) {
1401 retval = MPI_ERR_COMM;
1402 } else if (source == MPI_PROC_NULL) {
1403 smpi_empty_status(status);
1404 status->MPI_SOURCE = MPI_PROC_NULL;
1405 retval = MPI_SUCCESS;
1407 smpi_mpi_probe(source, tag, comm, status);
1408 retval = MPI_SUCCESS;
1414 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1418 if ((flag == nullptr) || (status == nullptr)) {
1419 retval = MPI_ERR_ARG;
1420 } else if (comm == MPI_COMM_NULL) {
1421 retval = MPI_ERR_COMM;
1422 } else if (source == MPI_PROC_NULL) {
1424 smpi_empty_status(status);
1425 status->MPI_SOURCE = MPI_PROC_NULL;
1426 retval = MPI_SUCCESS;
1428 smpi_mpi_iprobe(source, tag, comm, flag, status);
1429 retval = MPI_SUCCESS;
1435 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1441 smpi_empty_status(status);
1443 if (request == nullptr) {
1444 retval = MPI_ERR_ARG;
1445 } else if (*request == MPI_REQUEST_NULL) {
1446 retval = MPI_SUCCESS;
1449 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1451 int src_traced = (*request)->src;
1452 int dst_traced = (*request)->dst;
1453 int tag_traced= (*request)->tag;
1454 MPI_Comm comm = (*request)->comm;
1455 int is_wait_for_receive = (*request)->recv;
1456 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1457 extra->type = TRACING_WAIT;
1458 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1460 smpi_mpi_wait(request, status);
1461 retval = MPI_SUCCESS;
1463 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1464 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1465 if (is_wait_for_receive) {
1466 if(src_traced==MPI_ANY_SOURCE)
1467 src_traced = (status!=MPI_STATUS_IGNORE) ?
1468 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1470 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1478 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1480 if (index == nullptr)
1484 //save requests information for tracing
1493 savedvalstype* savedvals=nullptr;
1495 savedvals = xbt_new0(savedvalstype, count);
1497 for (i = 0; i < count; i++) {
1498 MPI_Request req = requests[i]; //already received requests are no longer valid
1500 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1503 int rank_traced = smpi_process_index();
1504 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1505 extra->type = TRACING_WAITANY;
1506 extra->send_size=count;
1507 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1509 *index = smpi_mpi_waitany(count, requests, status);
1511 if(*index!=MPI_UNDEFINED){
1512 int src_traced = savedvals[*index].src;
1513 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1514 int dst_traced = savedvals[*index].dst;
1515 int is_wait_for_receive = savedvals[*index].recv;
1516 if (is_wait_for_receive) {
1517 if(savedvals[*index].src==MPI_ANY_SOURCE)
1518 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1519 smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE) : savedvals[*index].src;
1520 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1522 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1524 xbt_free(savedvals);
1530 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1533 //save information from requests
1543 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1545 for (i = 0; i < count; i++) {
1546 MPI_Request req = requests[i];
1547 if(req!=MPI_REQUEST_NULL){
1548 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1550 savedvals[i].valid=0;
1553 int rank_traced = smpi_process_index();
1554 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1555 extra->type = TRACING_WAITALL;
1556 extra->send_size=count;
1557 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1559 int retval = smpi_mpi_waitall(count, requests, status);
1561 for (i = 0; i < count; i++) {
1562 if(savedvals[i].valid){
1563 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1564 int src_traced = savedvals[i].src;
1565 int dst_traced = savedvals[i].dst;
1566 int is_wait_for_receive = savedvals[i].recv;
1567 if (is_wait_for_receive) {
1568 if(src_traced==MPI_ANY_SOURCE)
1569 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1570 smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
1571 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1575 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1576 xbt_free(savedvals);
1582 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1587 if (outcount == nullptr) {
1588 retval = MPI_ERR_ARG;
1590 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1591 retval = MPI_SUCCESS;
1597 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1602 if (outcount == nullptr) {
1603 retval = MPI_ERR_ARG;
1605 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1606 retval = MPI_SUCCESS;
1613 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1619 if (comm == MPI_COMM_NULL) {
1620 retval = MPI_ERR_COMM;
1621 } else if (!is_datatype_valid(datatype)) {
1622 retval = MPI_ERR_ARG;
1624 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1625 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1627 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1628 extra->type = TRACING_BCAST;
1629 extra->root = root_traced;
1631 extra->datatype1 = encode_datatype(datatype, &known);
1632 int dt_size_send = 1;
1634 dt_size_send = smpi_datatype_size(datatype);
1635 extra->send_size = count*dt_size_send;
1636 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1637 if(smpi_comm_size(comm)>1)
1638 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1639 retval = MPI_SUCCESS;
1641 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1648 int PMPI_Barrier(MPI_Comm comm)
1654 if (comm == MPI_COMM_NULL) {
1655 retval = MPI_ERR_COMM;
1657 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1658 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1659 extra->type = TRACING_BARRIER;
1660 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1662 mpi_coll_barrier_fun(comm);
1663 retval = MPI_SUCCESS;
1665 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1672 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1673 int root, MPI_Comm comm)
1679 if (comm == MPI_COMM_NULL) {
1680 retval = MPI_ERR_COMM;
1681 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1682 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1683 retval = MPI_ERR_TYPE;
1684 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1685 retval = MPI_ERR_COUNT;
1688 char* sendtmpbuf = static_cast<char*>(sendbuf);
1689 int sendtmpcount = sendcount;
1690 MPI_Datatype sendtmptype = sendtype;
1691 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1693 sendtmptype=recvtype;
1695 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1696 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1697 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1698 extra->type = TRACING_GATHER;
1699 extra->root = root_traced;
1701 extra->datatype1 = encode_datatype(sendtmptype, &known);
1702 int dt_size_send = 1;
1704 dt_size_send = smpi_datatype_size(sendtmptype);
1705 extra->send_size = sendtmpcount*dt_size_send;
1706 extra->datatype2 = encode_datatype(recvtype, &known);
1707 int dt_size_recv = 1;
1708 if((smpi_comm_rank(comm)==root) && known==0)
1709 dt_size_recv = smpi_datatype_size(recvtype);
1710 extra->recv_size = recvcount*dt_size_recv;
1712 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1714 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1716 retval = MPI_SUCCESS;
1717 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1724 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1725 MPI_Datatype recvtype, int root, MPI_Comm comm)
1731 if (comm == MPI_COMM_NULL) {
1732 retval = MPI_ERR_COMM;
1733 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1734 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1735 retval = MPI_ERR_TYPE;
1736 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1737 retval = MPI_ERR_COUNT;
1738 } else if (recvcounts == nullptr || displs == nullptr) {
1739 retval = MPI_ERR_ARG;
1741 char* sendtmpbuf = static_cast<char*>(sendbuf);
1742 int sendtmpcount = sendcount;
1743 MPI_Datatype sendtmptype = sendtype;
1744 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1746 sendtmptype=recvtype;
1749 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1750 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1752 int size = smpi_comm_size(comm);
1753 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1754 extra->type = TRACING_GATHERV;
1755 extra->num_processes = size;
1756 extra->root = root_traced;
1758 extra->datatype1 = encode_datatype(sendtmptype, &known);
1759 int dt_size_send = 1;
1761 dt_size_send = smpi_datatype_size(sendtype);
1762 extra->send_size = sendtmpcount*dt_size_send;
1763 extra->datatype2 = encode_datatype(recvtype, &known);
1764 int dt_size_recv = 1;
1766 dt_size_recv = smpi_datatype_size(recvtype);
1767 if((smpi_comm_rank(comm)==root)){
1768 extra->recvcounts= xbt_new(int,size);
1769 for(i=0; i< size; i++)//copy data to avoid bad free
1770 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1772 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1774 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1775 retval = MPI_SUCCESS;
1776 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1783 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1784 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1790 if (comm == MPI_COMM_NULL) {
1791 retval = MPI_ERR_COMM;
1792 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1793 (recvtype == MPI_DATATYPE_NULL)){
1794 retval = MPI_ERR_TYPE;
1795 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1797 retval = MPI_ERR_COUNT;
1799 if(sendbuf == MPI_IN_PLACE) {
1800 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1801 sendcount=recvcount;
1804 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1805 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1806 extra->type = TRACING_ALLGATHER;
1808 extra->datatype1 = encode_datatype(sendtype, &known);
1809 int dt_size_send = 1;
1811 dt_size_send = smpi_datatype_size(sendtype);
1812 extra->send_size = sendcount*dt_size_send;
1813 extra->datatype2 = encode_datatype(recvtype, &known);
1814 int dt_size_recv = 1;
1816 dt_size_recv = smpi_datatype_size(recvtype);
1817 extra->recv_size = recvcount*dt_size_recv;
1819 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1821 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1822 retval = MPI_SUCCESS;
1823 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1829 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1830 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1836 if (comm == MPI_COMM_NULL) {
1837 retval = MPI_ERR_COMM;
1838 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1839 (recvtype == MPI_DATATYPE_NULL)){
1840 retval = MPI_ERR_TYPE;
1841 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1842 retval = MPI_ERR_COUNT;
1843 } else if (recvcounts == nullptr || displs == nullptr) {
1844 retval = MPI_ERR_ARG;
1847 if(sendbuf == MPI_IN_PLACE) {
1848 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1849 sendcount=recvcounts[smpi_comm_rank(comm)];
1852 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1854 int size = smpi_comm_size(comm);
1855 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1856 extra->type = TRACING_ALLGATHERV;
1857 extra->num_processes = size;
1859 extra->datatype1 = encode_datatype(sendtype, &known);
1860 int dt_size_send = 1;
1862 dt_size_send = smpi_datatype_size(sendtype);
1863 extra->send_size = sendcount*dt_size_send;
1864 extra->datatype2 = encode_datatype(recvtype, &known);
1865 int dt_size_recv = 1;
1867 dt_size_recv = smpi_datatype_size(recvtype);
1868 extra->recvcounts= xbt_new(int, size);
1869 for(i=0; i< size; i++)//copy data to avoid bad free
1870 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1872 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1874 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1875 retval = MPI_SUCCESS;
1876 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1883 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1884 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1890 if (comm == MPI_COMM_NULL) {
1891 retval = MPI_ERR_COMM;
1892 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1893 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1894 retval = MPI_ERR_TYPE;
1895 } else if ((sendbuf == recvbuf) ||
1896 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1897 retval = MPI_ERR_BUFFER;
1900 if (recvbuf == MPI_IN_PLACE) {
1902 recvcount=sendcount;
1904 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1905 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1906 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1907 extra->type = TRACING_SCATTER;
1908 extra->root = root_traced;
1910 extra->datatype1 = encode_datatype(sendtype, &known);
1911 int dt_size_send = 1;
1912 if((smpi_comm_rank(comm)==root) && known==0)
1913 dt_size_send = smpi_datatype_size(sendtype);
1914 extra->send_size = sendcount*dt_size_send;
1915 extra->datatype2 = encode_datatype(recvtype, &known);
1916 int dt_size_recv = 1;
1918 dt_size_recv = smpi_datatype_size(recvtype);
1919 extra->recv_size = recvcount*dt_size_recv;
1920 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1922 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1923 retval = MPI_SUCCESS;
1924 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1931 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1932 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1938 if (comm == MPI_COMM_NULL) {
1939 retval = MPI_ERR_COMM;
1940 } else if (sendcounts == nullptr || displs == nullptr) {
1941 retval = MPI_ERR_ARG;
1942 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1943 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1944 retval = MPI_ERR_TYPE;
1946 if (recvbuf == MPI_IN_PLACE) {
1948 recvcount=sendcounts[smpi_comm_rank(comm)];
1950 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1951 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1953 int size = smpi_comm_size(comm);
1954 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1955 extra->type = TRACING_SCATTERV;
1956 extra->num_processes = size;
1957 extra->root = root_traced;
1959 extra->datatype1 = encode_datatype(sendtype, &known);
1960 int dt_size_send = 1;
1962 dt_size_send = smpi_datatype_size(sendtype);
1963 if((smpi_comm_rank(comm)==root)){
1964 extra->sendcounts= xbt_new(int, size);
1965 for(i=0; i< size; i++)//copy data to avoid bad free
1966 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
1968 extra->datatype2 = encode_datatype(recvtype, &known);
1969 int dt_size_recv = 1;
1971 dt_size_recv = smpi_datatype_size(recvtype);
1972 extra->recv_size = recvcount*dt_size_recv;
1973 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1975 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1977 retval = MPI_SUCCESS;
1978 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1985 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1991 if (comm == MPI_COMM_NULL) {
1992 retval = MPI_ERR_COMM;
1993 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1994 retval = MPI_ERR_ARG;
1996 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1997 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1998 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1999 extra->type = TRACING_REDUCE;
2001 extra->datatype1 = encode_datatype(datatype, &known);
2002 int dt_size_send = 1;
2004 dt_size_send = smpi_datatype_size(datatype);
2005 extra->send_size = count*dt_size_send;
2006 extra->root = root_traced;
2008 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2010 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2012 retval = MPI_SUCCESS;
2013 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2020 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2024 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2025 retval = MPI_ERR_ARG;
2027 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2034 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2040 if (comm == MPI_COMM_NULL) {
2041 retval = MPI_ERR_COMM;
2042 } else if (!is_datatype_valid(datatype)) {
2043 retval = MPI_ERR_TYPE;
2044 } else if (op == MPI_OP_NULL) {
2045 retval = MPI_ERR_OP;
2048 char* sendtmpbuf = static_cast<char*>(sendbuf);
2049 if( sendbuf == MPI_IN_PLACE ) {
2050 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
2051 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2053 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2054 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2055 extra->type = TRACING_ALLREDUCE;
2057 extra->datatype1 = encode_datatype(datatype, &known);
2058 int dt_size_send = 1;
2060 dt_size_send = smpi_datatype_size(datatype);
2061 extra->send_size = count*dt_size_send;
2063 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2065 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2067 if( sendbuf == MPI_IN_PLACE )
2068 xbt_free(sendtmpbuf);
2070 retval = MPI_SUCCESS;
2071 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2078 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2084 if (comm == MPI_COMM_NULL) {
2085 retval = MPI_ERR_COMM;
2086 } else if (!is_datatype_valid(datatype)) {
2087 retval = MPI_ERR_TYPE;
2088 } else if (op == MPI_OP_NULL) {
2089 retval = MPI_ERR_OP;
2091 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2092 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2093 extra->type = TRACING_SCAN;
2095 extra->datatype1 = encode_datatype(datatype, &known);
2096 int dt_size_send = 1;
2098 dt_size_send = smpi_datatype_size(datatype);
2099 extra->send_size = count*dt_size_send;
2101 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2103 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2105 retval = MPI_SUCCESS;
2106 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2113 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2118 if (comm == MPI_COMM_NULL) {
2119 retval = MPI_ERR_COMM;
2120 } else if (!is_datatype_valid(datatype)) {
2121 retval = MPI_ERR_TYPE;
2122 } else if (op == MPI_OP_NULL) {
2123 retval = MPI_ERR_OP;
2125 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2126 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2127 extra->type = TRACING_EXSCAN;
2129 extra->datatype1 = encode_datatype(datatype, &known);
2130 int dt_size_send = 1;
2132 dt_size_send = smpi_datatype_size(datatype);
2133 extra->send_size = count*dt_size_send;
2134 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2136 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2137 retval = MPI_SUCCESS;
2138 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2145 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, 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;
2156 } else if (recvcounts == nullptr) {
2157 retval = MPI_ERR_ARG;
2159 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2161 int size = smpi_comm_size(comm);
2162 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2163 extra->type = TRACING_REDUCE_SCATTER;
2164 extra->num_processes = size;
2166 extra->datatype1 = encode_datatype(datatype, &known);
2167 int dt_size_send = 1;
2169 dt_size_send = smpi_datatype_size(datatype);
2170 extra->send_size = 0;
2171 extra->recvcounts= xbt_new(int, size);
2172 for(i=0; i< size; i++)//copy data to avoid bad free
2173 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2174 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2176 void* sendtmpbuf=sendbuf;
2177 if(sendbuf==MPI_IN_PLACE)
2180 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2181 retval = MPI_SUCCESS;
2182 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2189 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2190 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2195 if (comm == MPI_COMM_NULL) {
2196 retval = MPI_ERR_COMM;
2197 } else if (!is_datatype_valid(datatype)) {
2198 retval = MPI_ERR_TYPE;
2199 } else if (op == MPI_OP_NULL) {
2200 retval = MPI_ERR_OP;
2201 } else if (recvcount < 0) {
2202 retval = MPI_ERR_ARG;
2204 int count=smpi_comm_size(comm);
2206 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2207 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2208 extra->type = TRACING_REDUCE_SCATTER;
2209 extra->num_processes = count;
2211 extra->datatype1 = encode_datatype(datatype, &known);
2212 int dt_size_send = 1;
2214 dt_size_send = smpi_datatype_size(datatype);
2215 extra->send_size = 0;
2216 extra->recvcounts= xbt_new(int, count);
2217 for(i=0; i< count; i++)//copy data to avoid bad free
2218 extra->recvcounts[i] = recvcount*dt_size_send;
2220 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2222 int* recvcounts=static_cast<int*>(xbt_malloc(count));
2223 for (i=0; i<count;i++)
2224 recvcounts[i]=recvcount;
2225 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts, datatype, op, comm);
2226 xbt_free(recvcounts);
2227 retval = MPI_SUCCESS;
2229 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2236 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2237 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2243 if (comm == MPI_COMM_NULL) {
2244 retval = MPI_ERR_COMM;
2245 } else if (sendtype == MPI_DATATYPE_NULL
2246 || recvtype == MPI_DATATYPE_NULL) {
2247 retval = MPI_ERR_TYPE;
2249 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2250 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2251 extra->type = TRACING_ALLTOALL;
2253 extra->datatype1 = encode_datatype(sendtype, &known);
2255 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2257 extra->send_size = sendcount;
2258 extra->datatype2 = encode_datatype(recvtype, &known);
2260 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2262 extra->recv_size = recvcount;
2263 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2265 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2267 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2274 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2275 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2281 if (comm == MPI_COMM_NULL) {
2282 retval = MPI_ERR_COMM;
2283 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2284 retval = MPI_ERR_TYPE;
2285 } else if (sendcounts == nullptr || senddisps == nullptr || recvcounts == nullptr || recvdisps == nullptr) {
2286 retval = MPI_ERR_ARG;
2288 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2290 int size = smpi_comm_size(comm);
2291 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2292 extra->type = TRACING_ALLTOALLV;
2293 extra->send_size = 0;
2294 extra->recv_size = 0;
2295 extra->recvcounts= xbt_new(int, size);
2296 extra->sendcounts= xbt_new(int, size);
2298 extra->datatype1 = encode_datatype(sendtype, &known);
2299 int dt_size_send = 1;
2301 dt_size_send = smpi_datatype_size(sendtype);
2302 int dt_size_recv = 1;
2303 extra->datatype2 = encode_datatype(recvtype, &known);
2305 dt_size_recv = smpi_datatype_size(recvtype);
2306 for(i=0; i< size; i++){//copy data to avoid bad free
2307 extra->send_size += sendcounts[i]*dt_size_send;
2308 extra->recv_size += recvcounts[i]*dt_size_recv;
2310 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2311 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2313 extra->num_processes = size;
2314 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2316 retval = mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype,
2318 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2326 int PMPI_Get_processor_name(char *name, int *resultlen)
2328 int retval = MPI_SUCCESS;
2330 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2331 ? strlen(SIMIX_host_self()->cname()) + 1
2332 : MPI_MAX_PROCESSOR_NAME - 1);
2333 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2338 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2340 int retval = MPI_SUCCESS;
2343 if (status == nullptr || count == nullptr) {
2344 retval = MPI_ERR_ARG;
2345 } else if (!is_datatype_valid(datatype)) {
2346 retval = MPI_ERR_TYPE;
2348 size = smpi_datatype_size(datatype);
2351 } else if (status->count % size != 0) {
2352 retval = MPI_UNDEFINED;
2354 *count = smpi_mpi_get_count(status, datatype);
2360 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2363 if (old_type == MPI_DATATYPE_NULL) {
2364 retval = MPI_ERR_TYPE;
2365 } else if (count<0){
2366 retval = MPI_ERR_COUNT;
2368 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2373 int PMPI_Type_commit(MPI_Datatype* datatype) {
2376 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2377 retval = MPI_ERR_TYPE;
2379 smpi_datatype_commit(datatype);
2380 retval = MPI_SUCCESS;
2385 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2388 if (old_type == MPI_DATATYPE_NULL) {
2389 retval = MPI_ERR_TYPE;
2390 } else if (count<0 || blocklen<0){
2391 retval = MPI_ERR_COUNT;
2393 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2398 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2401 if (old_type == MPI_DATATYPE_NULL) {
2402 retval = MPI_ERR_TYPE;
2403 } else if (count<0 || blocklen<0){
2404 retval = MPI_ERR_COUNT;
2406 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2411 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2412 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2415 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2418 if (old_type == MPI_DATATYPE_NULL) {
2419 retval = MPI_ERR_TYPE;
2420 } else if (count<0){
2421 retval = MPI_ERR_COUNT;
2423 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2428 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2431 if (old_type == MPI_DATATYPE_NULL) {
2432 retval = MPI_ERR_TYPE;
2433 } else if (count<0){
2434 retval = MPI_ERR_COUNT;
2436 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2441 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2442 MPI_Datatype* new_type) {
2445 if (old_type == MPI_DATATYPE_NULL) {
2446 retval = MPI_ERR_TYPE;
2447 } else if (count<0){
2448 retval = MPI_ERR_COUNT;
2450 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count));
2451 for (i=0; i<count;i++)
2452 blocklens[i]=blocklength;
2453 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2454 xbt_free(blocklens);
2459 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2462 if (old_type == MPI_DATATYPE_NULL) {
2463 retval = MPI_ERR_TYPE;
2464 } else if (count<0){
2465 retval = MPI_ERR_COUNT;
2467 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2472 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2473 MPI_Datatype* new_type) {
2474 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2477 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2478 MPI_Datatype* new_type) {
2481 if (old_type == MPI_DATATYPE_NULL) {
2482 retval = MPI_ERR_TYPE;
2483 } else if (count<0){
2484 retval = MPI_ERR_COUNT;
2486 int* blocklens=(int*)xbt_malloc(blocklength*count);
2487 for (i=0; i<count;i++)blocklens[i]=blocklength;
2488 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2489 xbt_free(blocklens);
2494 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2498 retval = MPI_ERR_COUNT;
2500 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2505 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2506 MPI_Datatype* new_type) {
2507 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2510 int PMPI_Error_class(int errorcode, int* errorclass) {
2511 // assume smpi uses only standard mpi error codes
2512 *errorclass=errorcode;
2516 int PMPI_Initialized(int* flag) {
2517 *flag=smpi_process_initialized();
2521 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2522 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2523 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2525 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2527 if (comm_old == MPI_COMM_NULL){
2528 retval = MPI_ERR_COMM;
2529 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2530 retval = MPI_ERR_ARG;
2532 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2537 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2538 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2539 return MPI_ERR_TOPOLOGY;
2541 if (coords == nullptr) {
2544 return smpi_mpi_cart_rank(comm, coords, rank);
2547 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2548 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2549 return MPI_ERR_TOPOLOGY;
2551 if (source == nullptr || dest == nullptr || direction < 0 ) {
2554 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2557 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2558 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2559 return MPI_ERR_TOPOLOGY;
2561 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2562 return MPI_ERR_RANK;
2567 if(coords == nullptr) {
2570 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2573 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2574 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2575 return MPI_ERR_TOPOLOGY;
2577 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2580 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2583 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2584 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2585 return MPI_ERR_TOPOLOGY;
2587 if (ndims == nullptr) {
2590 return smpi_mpi_cartdim_get(comm, ndims);
2593 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2594 if(dims == nullptr) {
2597 if (ndims < 1 || nnodes < 1) {
2598 return MPI_ERR_DIMS;
2601 return smpi_mpi_dims_create(nnodes, ndims, dims);
2604 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2605 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2606 return MPI_ERR_TOPOLOGY;
2608 if (comm_new == nullptr) {
2611 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2614 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2615 if(oldtype == MPI_DATATYPE_NULL) {
2616 return MPI_ERR_TYPE;
2618 int blocks[3] = { 1, 1, 1 };
2619 MPI_Aint disps[3] = { lb, 0, lb+extent };
2620 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2622 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2623 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t) , subtype, DT_FLAG_VECTOR);
2625 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2629 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2632 if (comm == MPI_COMM_NULL) {
2633 retval= MPI_ERR_COMM;
2634 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2635 retval= MPI_ERR_OTHER;
2637 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2638 retval = MPI_SUCCESS;
2644 int PMPI_Win_free( MPI_Win* win){
2647 if (win == nullptr || *win == MPI_WIN_NULL) {
2648 retval = MPI_ERR_WIN;
2650 retval=smpi_mpi_win_free(win);
2656 int PMPI_Win_set_name(MPI_Win win, char * name)
2659 if (win == MPI_WIN_NULL) {
2660 retval = MPI_ERR_TYPE;
2661 } else if (name == nullptr) {
2662 retval = MPI_ERR_ARG;
2664 smpi_mpi_win_set_name(win, name);
2665 retval = MPI_SUCCESS;
2670 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2672 int retval = MPI_SUCCESS;
2674 if (win == MPI_WIN_NULL) {
2675 retval = MPI_ERR_WIN;
2676 } else if (name == nullptr) {
2677 retval = MPI_ERR_ARG;
2679 smpi_mpi_win_get_name(win, name, len);
2684 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2685 int retval = MPI_SUCCESS;
2686 if (win == MPI_WIN_NULL) {
2687 retval = MPI_ERR_WIN;
2689 smpi_mpi_win_get_group(win, group);
2690 smpi_group_use(*group);
2696 int PMPI_Win_fence( int assert, MPI_Win win){
2699 if (win == MPI_WIN_NULL) {
2700 retval = MPI_ERR_WIN;
2702 int rank = smpi_process_index();
2703 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2704 retval = smpi_mpi_win_fence(assert, win);
2705 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2711 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2712 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2715 if (win == MPI_WIN_NULL) {
2716 retval = MPI_ERR_WIN;
2717 } else if (target_rank == MPI_PROC_NULL) {
2718 retval = MPI_SUCCESS;
2719 } else if (target_rank <0){
2720 retval = MPI_ERR_RANK;
2721 } else if (target_disp <0){
2722 retval = MPI_ERR_ARG;
2723 } else if ((origin_count < 0 || target_count < 0) ||
2724 (origin_addr==nullptr && origin_count > 0)){
2725 retval = MPI_ERR_COUNT;
2726 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2727 retval = MPI_ERR_TYPE;
2729 int rank = smpi_process_index();
2731 smpi_mpi_win_get_group(win, &group);
2732 int src_traced = smpi_group_index(group, target_rank);
2733 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2735 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2736 target_datatype, win);
2738 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2744 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2745 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2748 if (win == MPI_WIN_NULL) {
2749 retval = MPI_ERR_WIN;
2750 } else if (target_rank == MPI_PROC_NULL) {
2751 retval = MPI_SUCCESS;
2752 } else if (target_rank <0){
2753 retval = MPI_ERR_RANK;
2754 } else if (target_disp <0){
2755 retval = MPI_ERR_ARG;
2756 } else if ((origin_count < 0 || target_count < 0) ||
2757 (origin_addr==nullptr && origin_count > 0)){
2758 retval = MPI_ERR_COUNT;
2759 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2760 retval = MPI_ERR_TYPE;
2762 int rank = smpi_process_index();
2764 smpi_mpi_win_get_group(win, &group);
2765 int dst_traced = smpi_group_index(group, target_rank);
2766 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2767 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2769 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2770 target_datatype, win);
2772 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2778 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2779 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2782 if (win == MPI_WIN_NULL) {
2783 retval = MPI_ERR_WIN;
2784 } else if (target_rank == MPI_PROC_NULL) {
2785 retval = MPI_SUCCESS;
2786 } else if (target_rank <0){
2787 retval = MPI_ERR_RANK;
2788 } else if (target_disp <0){
2789 retval = MPI_ERR_ARG;
2790 } else if ((origin_count < 0 || target_count < 0) ||
2791 (origin_addr==nullptr && origin_count > 0)){
2792 retval = MPI_ERR_COUNT;
2793 } else if ((!is_datatype_valid(origin_datatype)) ||
2794 (!is_datatype_valid(target_datatype))) {
2795 retval = MPI_ERR_TYPE;
2796 } else if (op == MPI_OP_NULL) {
2797 retval = MPI_ERR_OP;
2799 int rank = smpi_process_index();
2801 smpi_mpi_win_get_group(win, &group);
2802 int src_traced = smpi_group_index(group, target_rank);
2803 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2805 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2806 target_datatype, op, win);
2808 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2814 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2817 if (win == MPI_WIN_NULL) {
2818 retval = MPI_ERR_WIN;
2819 } else if (group==MPI_GROUP_NULL){
2820 retval = MPI_ERR_GROUP;
2823 int rank = smpi_process_index();
2824 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2825 retval = smpi_mpi_win_post(group,assert,win);
2826 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2832 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2835 if (win == MPI_WIN_NULL) {
2836 retval = MPI_ERR_WIN;
2837 } else if (group==MPI_GROUP_NULL){
2838 retval = MPI_ERR_GROUP;
2841 int rank = smpi_process_index();
2842 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2843 retval = smpi_mpi_win_start(group,assert,win);
2844 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2850 int PMPI_Win_complete(MPI_Win win){
2853 if (win == MPI_WIN_NULL) {
2854 retval = MPI_ERR_WIN;
2857 int rank = smpi_process_index();
2858 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2860 retval = smpi_mpi_win_complete(win);
2862 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2868 int PMPI_Win_wait(MPI_Win win){
2871 if (win == MPI_WIN_NULL) {
2872 retval = MPI_ERR_WIN;
2875 int rank = smpi_process_index();
2876 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2878 retval = smpi_mpi_win_wait(win);
2880 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2886 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2887 void *ptr = xbt_malloc(size);
2889 return MPI_ERR_NO_MEM;
2891 *static_cast<void**>(baseptr) = ptr;
2896 int PMPI_Free_mem(void *baseptr){
2901 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2904 if (datatype == MPI_DATATYPE_NULL) {
2905 retval = MPI_ERR_TYPE;
2906 } else if (name == nullptr) {
2907 retval = MPI_ERR_ARG;
2909 smpi_datatype_set_name(datatype, name);
2910 retval = MPI_SUCCESS;
2915 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2919 if (datatype == MPI_DATATYPE_NULL) {
2920 retval = MPI_ERR_TYPE;
2921 } else if (name == nullptr) {
2922 retval = MPI_ERR_ARG;
2924 smpi_datatype_get_name(datatype, name, len);
2925 retval = MPI_SUCCESS;
2930 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2931 return smpi_type_f2c(datatype);
2934 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2935 return smpi_type_c2f( datatype);
2938 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2939 return smpi_group_f2c( group);
2942 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2943 return smpi_group_c2f(group);
2946 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2947 return smpi_request_f2c(request);
2950 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2951 return smpi_request_c2f(request);
2954 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2955 return smpi_win_f2c(win);
2958 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2959 return smpi_win_c2f(win);
2962 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2963 return smpi_op_f2c(op);
2966 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2967 return smpi_op_c2f(op);
2970 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2971 return smpi_comm_f2c(comm);
2974 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2975 return smpi_comm_c2f(comm);
2978 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2979 return smpi_info_f2c(info);
2982 MPI_Fint PMPI_Info_c2f(MPI_Info info){
2983 return smpi_info_c2f(info);
2986 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2987 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2990 int PMPI_Keyval_free(int* keyval) {
2991 return smpi_comm_keyval_free(keyval);
2994 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2995 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2996 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2998 else if (comm==MPI_COMM_NULL)
2999 return MPI_ERR_COMM;
3001 return smpi_comm_attr_delete(comm, keyval);
3004 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3006 static int zero = 0;
3007 static int tag_ub = 1000000;
3008 static int last_used_code = MPI_ERR_LASTCODE;
3010 if (comm==MPI_COMM_NULL){
3012 return MPI_ERR_COMM;
3020 *static_cast<int**>(attr_value) = &zero;
3022 case MPI_UNIVERSE_SIZE:
3024 *static_cast<int**>(attr_value) = &smpi_universe_size;
3026 case MPI_LASTUSEDCODE:
3028 *static_cast<int**>(attr_value) = &last_used_code;
3032 *static_cast<int**>(attr_value) = &tag_ub;
3034 case MPI_WTIME_IS_GLOBAL:
3036 *static_cast<int**>(attr_value) = &one;
3039 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3043 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3044 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3045 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3047 else if (comm==MPI_COMM_NULL)
3048 return MPI_ERR_COMM;
3050 return smpi_comm_attr_put(comm, keyval, attr_value);
3053 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3055 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3058 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3060 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3063 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3065 return PMPI_Attr_delete(comm, comm_keyval);
3068 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3071 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3074 int PMPI_Comm_free_keyval(int* keyval) {
3075 return PMPI_Keyval_free(keyval);
3078 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3080 if (type==MPI_DATATYPE_NULL)
3081 return MPI_ERR_TYPE;
3083 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3086 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3088 if (type==MPI_DATATYPE_NULL)
3089 return MPI_ERR_TYPE;
3091 return smpi_type_attr_put(type, type_keyval, attribute_val);
3094 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3096 if (type==MPI_DATATYPE_NULL)
3097 return MPI_ERR_TYPE;
3099 return smpi_type_attr_delete(type, type_keyval);
3102 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3105 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3108 int PMPI_Type_free_keyval(int* keyval) {
3109 return smpi_type_keyval_free(keyval);
3112 int PMPI_Info_create( MPI_Info *info){
3113 if (info == nullptr)
3115 *info = xbt_new(s_smpi_mpi_info_t, 1);
3116 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3117 (*info)->refcount=1;
3121 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3122 if (info == nullptr || key == nullptr || value == nullptr)
3125 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
3129 int PMPI_Info_free( MPI_Info *info){
3130 if (info == nullptr || *info==nullptr)
3132 (*info)->refcount--;
3133 if((*info)->refcount==0){
3134 xbt_dict_free(&((*info)->info_dict));
3137 *info=MPI_INFO_NULL;
3141 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3143 if (info == nullptr || key == nullptr || valuelen <0)
3145 if (value == nullptr)
3146 return MPI_ERR_INFO_VALUE;
3147 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
3149 memset(value, 0, valuelen);
3150 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3156 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3157 if (info == nullptr || newinfo==nullptr)
3159 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3160 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
3161 (*newinfo)->refcount=1;
3162 xbt_dict_cursor_t cursor = nullptr;
3165 xbt_dict_foreach(info->info_dict,cursor,key,data){
3166 xbt_dict_set((*newinfo)->info_dict, reinterpret_cast<char*>(key), xbt_strdup(reinterpret_cast<char*>(data)), nullptr);
3171 int PMPI_Info_delete(MPI_Info info, char *key){
3172 if (info == nullptr || key==nullptr)
3175 xbt_dict_remove(info->info_dict, key);
3178 return MPI_ERR_INFO_NOKEY;
3183 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3184 if (info == nullptr || nkeys==nullptr)
3186 *nkeys=xbt_dict_size(info->info_dict);
3190 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3191 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
3194 xbt_dict_cursor_t cursor = nullptr;
3198 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3200 strncpy(key,keyn,strlen(keyn)+1);
3201 xbt_dict_cursor_free(&cursor);
3209 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3211 if (info == nullptr || key == nullptr || valuelen==nullptr)
3213 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3215 *valuelen=strlen(tmpvalue);
3221 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3222 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3224 if(!is_datatype_valid(type))
3225 return MPI_ERR_TYPE;
3226 if(comm==MPI_COMM_NULL)
3227 return MPI_ERR_COMM;
3228 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3231 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3232 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3234 if(!is_datatype_valid(type))
3235 return MPI_ERR_TYPE;
3236 if(comm==MPI_COMM_NULL)
3237 return MPI_ERR_COMM;
3238 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3241 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3244 if(!is_datatype_valid(datatype))
3245 return MPI_ERR_TYPE;
3246 if(comm==MPI_COMM_NULL)
3247 return MPI_ERR_COMM;
3249 *size=incount*smpi_datatype_size(datatype);