1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u/host.hpp>
7 #include <src/smpi/smpi_group.hpp>
11 #include "smpi_mpi_dt_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi)");
15 //this function need to be here because of the calls to smpi_bench
16 void TRACE_smpi_set_category(const char *category)
18 //need to end bench otherwise categories for execution tasks are wrong
20 TRACE_internal_smpi_set_category (category);
21 //begin bench after changing process's category
25 /* PMPI User level calls */
26 extern "C" { // Obviously, the C MPI interface should use the C linkage
28 int PMPI_Init(int *argc, char ***argv)
30 // PMPI_Init is call only one time by only by SMPI process
32 MPI_Initialized(&already_init);
33 if(already_init == 0){
34 smpi_process_init(argc, argv);
35 smpi_process_mark_as_initialized();
36 int rank = smpi_process_index();
37 TRACE_smpi_init(rank);
38 TRACE_smpi_computing_init(rank);
39 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
40 extra->type = TRACING_INIT;
41 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
42 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
54 int rank = smpi_process_index();
55 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
56 extra->type = TRACING_FINALIZE;
57 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
59 smpi_process_finalize();
61 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
62 TRACE_smpi_finalize(smpi_process_index());
63 smpi_process_destroy();
67 int PMPI_Finalized(int* flag)
69 *flag=smpi_process_finalized();
73 int PMPI_Get_version (int *version,int *subversion){
74 *version = MPI_VERSION;
75 *subversion= MPI_SUBVERSION;
79 int PMPI_Get_library_version (char *version,int *len){
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)
98 if (provided == nullptr) {
101 *provided = MPI_THREAD_SINGLE;
106 int PMPI_Is_thread_main(int *flag)
108 if (flag == nullptr) {
111 *flag = smpi_process_index() == 0;
116 int PMPI_Abort(MPI_Comm comm, int errorcode)
119 smpi_process_destroy();
120 // FIXME: should kill all processes in comm instead
121 simcall_process_kill(SIMIX_process_self());
127 return smpi_mpi_wtime();
130 extern double sg_maxmin_precision;
133 return sg_maxmin_precision;
136 int PMPI_Address(void *location, MPI_Aint * address)
138 if (address==nullptr) {
141 *address = reinterpret_cast<MPI_Aint>(location);
146 int PMPI_Get_address(void *location, MPI_Aint * address)
148 return PMPI_Address(location, address);
151 int PMPI_Type_free(MPI_Datatype * datatype)
153 /* Free a predefined datatype is an error according to the standard, and should be checked for */
154 if (*datatype == MPI_DATATYPE_NULL) {
157 smpi_datatype_unuse(*datatype);
162 int PMPI_Type_size(MPI_Datatype datatype, int *size)
164 if (datatype == MPI_DATATYPE_NULL) {
166 } else if (size == nullptr) {
169 *size = static_cast<int>(smpi_datatype_size(datatype));
174 int PMPI_Type_size_x(MPI_Datatype datatype, MPI_Count *size)
176 if (datatype == MPI_DATATYPE_NULL) {
178 } else if (size == nullptr) {
181 *size = static_cast<MPI_Count>(smpi_datatype_size(datatype));
186 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
188 if (datatype == MPI_DATATYPE_NULL) {
190 } else if (lb == nullptr || extent == nullptr) {
193 return smpi_datatype_extent(datatype, lb, extent);
197 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
199 return PMPI_Type_get_extent(datatype, lb, extent);
202 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
204 if (datatype == MPI_DATATYPE_NULL) {
206 } else if (extent == nullptr) {
209 *extent = smpi_datatype_get_extent(datatype);
214 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
216 if (datatype == MPI_DATATYPE_NULL) {
218 } else if (disp == nullptr) {
221 *disp = smpi_datatype_lb(datatype);
226 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
228 if (datatype == MPI_DATATYPE_NULL) {
230 } else if (disp == nullptr) {
233 *disp = smpi_datatype_ub(datatype);
238 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
239 if (datatype == MPI_DATATYPE_NULL) {
242 return smpi_datatype_dup(datatype, newtype);
246 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
248 if (function == nullptr || op == nullptr) {
251 *op = smpi_op_new(function, (commute!=0));
256 int PMPI_Op_free(MPI_Op * op)
260 } else if (*op == MPI_OP_NULL) {
263 smpi_op_destroy(*op);
269 int PMPI_Group_free(MPI_Group * group)
271 if (group == nullptr) {
275 *group = MPI_GROUP_NULL;
280 int PMPI_Group_size(MPI_Group group, int *size)
282 if (group == MPI_GROUP_NULL) {
283 return MPI_ERR_GROUP;
284 } else if (size == nullptr) {
287 *size = group->size();
292 int PMPI_Group_rank(MPI_Group group, int *rank)
294 if (group == MPI_GROUP_NULL) {
295 return MPI_ERR_GROUP;
296 } else if (rank == nullptr) {
299 *rank = group->rank(smpi_process_index());
304 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
306 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
307 return MPI_ERR_GROUP;
309 for (int i = 0; i < n; i++) {
310 if(ranks1[i]==MPI_PROC_NULL){
311 ranks2[i]=MPI_PROC_NULL;
313 int index = group1->index(ranks1[i]);
314 ranks2[i] = group2->rank(index);
321 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
323 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
324 return MPI_ERR_GROUP;
325 } else if (result == nullptr) {
328 *result = group1->compare(group2);
333 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
336 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
337 return MPI_ERR_GROUP;
338 } else if (newgroup == nullptr) {
341 return group1->group_union(group2, newgroup);
345 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
348 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
349 return MPI_ERR_GROUP;
350 } else if (newgroup == nullptr) {
353 return group1->intersection(group2,newgroup);
357 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
359 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
360 return MPI_ERR_GROUP;
361 } else if (newgroup == nullptr) {
364 return group1->difference(group2,newgroup);
368 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
370 if (group == MPI_GROUP_NULL) {
371 return MPI_ERR_GROUP;
372 } else if (newgroup == nullptr) {
375 return group->incl(n, ranks, newgroup);
379 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
381 if (group == MPI_GROUP_NULL) {
382 return MPI_ERR_GROUP;
383 } else if (newgroup == nullptr) {
388 if (group != smpi_comm_group(MPI_COMM_WORLD)
389 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
392 } else if (n == group->size()) {
393 *newgroup = MPI_GROUP_EMPTY;
396 return group->excl(n,ranks,newgroup);
401 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
403 if (group == MPI_GROUP_NULL) {
404 return MPI_ERR_GROUP;
405 } else if (newgroup == nullptr) {
409 *newgroup = MPI_GROUP_EMPTY;
412 return group->range_incl(n,ranges,newgroup);
417 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
419 if (group == MPI_GROUP_NULL) {
420 return MPI_ERR_GROUP;
421 } else if (newgroup == nullptr) {
426 if (group != smpi_comm_group(MPI_COMM_WORLD) && group != smpi_comm_group(MPI_COMM_SELF) &&
427 group != MPI_GROUP_EMPTY)
431 return group->range_excl(n,ranges,newgroup);
436 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
438 if (comm == MPI_COMM_NULL) {
440 } else if (rank == nullptr) {
443 *rank = smpi_comm_rank(comm);
448 int PMPI_Comm_size(MPI_Comm comm, int *size)
450 if (comm == MPI_COMM_NULL) {
452 } else if (size == nullptr) {
455 *size = smpi_comm_size(comm);
460 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
462 if (comm == MPI_COMM_NULL) {
464 } else if (name == nullptr || len == nullptr) {
467 smpi_comm_get_name(comm, name, len);
472 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
474 if (comm == MPI_COMM_NULL) {
476 } else if (group == nullptr) {
479 *group = smpi_comm_group(comm);
480 if (*group != smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
486 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
488 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
490 } else if (result == nullptr) {
493 if (comm1 == comm2) { /* Same communicators means same groups */
496 *result = smpi_comm_group(comm1)->compare(smpi_comm_group(comm2));
497 if (*result == MPI_IDENT) {
498 *result = MPI_CONGRUENT;
505 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
507 if (comm == MPI_COMM_NULL) {
509 } else if (newcomm == nullptr) {
512 return smpi_comm_dup(comm, newcomm);
516 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
518 if (comm == MPI_COMM_NULL) {
520 } else if (group == MPI_GROUP_NULL) {
521 return MPI_ERR_GROUP;
522 } else if (newcomm == nullptr) {
524 } else if(group->rank(smpi_process_index())==MPI_UNDEFINED){
525 *newcomm= MPI_COMM_NULL;
529 *newcomm = smpi_comm_new(group, nullptr);
534 int PMPI_Comm_free(MPI_Comm * comm)
536 if (comm == nullptr) {
538 } else if (*comm == MPI_COMM_NULL) {
541 smpi_comm_destroy(*comm);
542 *comm = MPI_COMM_NULL;
547 int PMPI_Comm_disconnect(MPI_Comm * comm)
549 /* TODO: wait until all communication in comm are done */
550 if (comm == nullptr) {
552 } else if (*comm == MPI_COMM_NULL) {
555 smpi_comm_destroy(*comm);
556 *comm = MPI_COMM_NULL;
561 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
566 if (comm_out == nullptr) {
567 retval = MPI_ERR_ARG;
568 } else if (comm == MPI_COMM_NULL) {
569 retval = MPI_ERR_COMM;
571 *comm_out = smpi_comm_split(comm, color, key);
572 retval = MPI_SUCCESS;
579 int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out)
584 if (comm_out == nullptr) {
585 retval = MPI_ERR_ARG;
586 } else if (comm == MPI_COMM_NULL) {
587 retval = MPI_ERR_COMM;
589 retval = MPI_Comm_create(comm, group, comm_out);
596 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
601 if (request == nullptr) {
602 retval = MPI_ERR_ARG;
603 } else if (comm == MPI_COMM_NULL) {
604 retval = MPI_ERR_COMM;
605 } else if (!is_datatype_valid(datatype)) {
606 retval = MPI_ERR_TYPE;
607 } else if (dst == MPI_PROC_NULL) {
608 retval = MPI_SUCCESS;
610 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
611 retval = MPI_SUCCESS;
614 if (retval != MPI_SUCCESS && request != nullptr)
615 *request = MPI_REQUEST_NULL;
619 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
624 if (request == nullptr) {
625 retval = MPI_ERR_ARG;
626 } else if (comm == MPI_COMM_NULL) {
627 retval = MPI_ERR_COMM;
628 } else if (!is_datatype_valid(datatype)) {
629 retval = MPI_ERR_TYPE;
630 } else if (src == MPI_PROC_NULL) {
631 retval = MPI_SUCCESS;
633 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
634 retval = MPI_SUCCESS;
637 if (retval != MPI_SUCCESS && request != nullptr)
638 *request = MPI_REQUEST_NULL;
642 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
647 if (request == nullptr) {
648 retval = MPI_ERR_ARG;
649 } else if (comm == MPI_COMM_NULL) {
650 retval = MPI_ERR_COMM;
651 } else if (!is_datatype_valid(datatype)) {
652 retval = MPI_ERR_TYPE;
653 } else if (dst == MPI_PROC_NULL) {
654 retval = MPI_SUCCESS;
656 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
657 retval = MPI_SUCCESS;
660 if (retval != MPI_SUCCESS && request != nullptr)
661 *request = MPI_REQUEST_NULL;
665 int PMPI_Start(MPI_Request * request)
670 if (request == nullptr || *request == MPI_REQUEST_NULL) {
671 retval = MPI_ERR_REQUEST;
673 smpi_mpi_start(*request);
674 retval = MPI_SUCCESS;
680 int PMPI_Startall(int count, MPI_Request * requests)
684 if (requests == nullptr) {
685 retval = MPI_ERR_ARG;
687 retval = MPI_SUCCESS;
688 for (int i = 0; i < count; i++) {
689 if(requests[i] == MPI_REQUEST_NULL) {
690 retval = MPI_ERR_REQUEST;
693 if(retval != MPI_ERR_REQUEST) {
694 smpi_mpi_startall(count, requests);
701 int PMPI_Request_free(MPI_Request * request)
706 if (*request == MPI_REQUEST_NULL) {
707 retval = MPI_ERR_ARG;
709 smpi_mpi_request_free(request);
710 retval = MPI_SUCCESS;
716 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
722 if (request == nullptr) {
723 retval = MPI_ERR_ARG;
724 } else if (comm == MPI_COMM_NULL) {
725 retval = MPI_ERR_COMM;
726 } else if (src == MPI_PROC_NULL) {
727 *request = MPI_REQUEST_NULL;
728 retval = MPI_SUCCESS;
729 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->size() || src <0)){
730 retval = MPI_ERR_RANK;
731 } else if ((count < 0) || (buf==nullptr && count > 0)) {
732 retval = MPI_ERR_COUNT;
733 } else if (!is_datatype_valid(datatype)) {
734 retval = MPI_ERR_TYPE;
735 } else if(tag<0 && tag != MPI_ANY_TAG){
736 retval = MPI_ERR_TAG;
739 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
740 int src_traced = smpi_comm_group(comm)->index(src);
742 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
743 extra->type = TRACING_IRECV;
744 extra->src = src_traced;
747 extra->datatype1 = encode_datatype(datatype, &known);
748 int dt_size_send = 1;
750 dt_size_send = smpi_datatype_size(datatype);
751 extra->send_size = count*dt_size_send;
752 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
754 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
755 retval = MPI_SUCCESS;
757 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
758 (*request)->recv = 1;
762 if (retval != MPI_SUCCESS && request != nullptr)
763 *request = MPI_REQUEST_NULL;
768 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
773 if (request == nullptr) {
774 retval = MPI_ERR_ARG;
775 } else if (comm == MPI_COMM_NULL) {
776 retval = MPI_ERR_COMM;
777 } else if (dst == MPI_PROC_NULL) {
778 *request = MPI_REQUEST_NULL;
779 retval = MPI_SUCCESS;
780 } else if (dst >= smpi_comm_group(comm)->size() || dst <0){
781 retval = MPI_ERR_RANK;
782 } else if ((count < 0) || (buf==nullptr && count > 0)) {
783 retval = MPI_ERR_COUNT;
784 } else if (!is_datatype_valid(datatype)) {
785 retval = MPI_ERR_TYPE;
786 } else if(tag<0 && tag != MPI_ANY_TAG){
787 retval = MPI_ERR_TAG;
789 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
790 int dst_traced = smpi_comm_group(comm)->index(dst);
791 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
792 extra->type = TRACING_ISEND;
794 extra->dst = dst_traced;
796 extra->datatype1 = encode_datatype(datatype, &known);
797 int dt_size_send = 1;
799 dt_size_send = smpi_datatype_size(datatype);
800 extra->send_size = count*dt_size_send;
801 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
802 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
804 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
805 retval = MPI_SUCCESS;
807 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
808 (*request)->send = 1;
812 if (retval != MPI_SUCCESS && request!=nullptr)
813 *request = MPI_REQUEST_NULL;
817 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
822 if (request == nullptr) {
823 retval = MPI_ERR_ARG;
824 } else if (comm == MPI_COMM_NULL) {
825 retval = MPI_ERR_COMM;
826 } else if (dst == MPI_PROC_NULL) {
827 *request = MPI_REQUEST_NULL;
828 retval = MPI_SUCCESS;
829 } else if (dst >= smpi_comm_group(comm)->size() || dst <0){
830 retval = MPI_ERR_RANK;
831 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
832 retval = MPI_ERR_COUNT;
833 } else if (!is_datatype_valid(datatype)) {
834 retval = MPI_ERR_TYPE;
835 } else if(tag<0 && tag != MPI_ANY_TAG){
836 retval = MPI_ERR_TAG;
838 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
839 int dst_traced = smpi_comm_group(comm)->index(dst);
840 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
841 extra->type = TRACING_ISSEND;
843 extra->dst = dst_traced;
845 extra->datatype1 = encode_datatype(datatype, &known);
846 int dt_size_send = 1;
848 dt_size_send = smpi_datatype_size(datatype);
849 extra->send_size = count*dt_size_send;
850 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
851 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
853 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
854 retval = MPI_SUCCESS;
856 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
857 (*request)->send = 1;
861 if (retval != MPI_SUCCESS && request!=nullptr)
862 *request = MPI_REQUEST_NULL;
866 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
871 if (comm == MPI_COMM_NULL) {
872 retval = MPI_ERR_COMM;
873 } else if (src == MPI_PROC_NULL) {
874 smpi_empty_status(status);
875 status->MPI_SOURCE = MPI_PROC_NULL;
876 retval = MPI_SUCCESS;
877 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->size() || src <0)){
878 retval = MPI_ERR_RANK;
879 } else if ((count < 0) || (buf==nullptr && count > 0)) {
880 retval = MPI_ERR_COUNT;
881 } else if (!is_datatype_valid(datatype)) {
882 retval = MPI_ERR_TYPE;
883 } else if(tag<0 && tag != MPI_ANY_TAG){
884 retval = MPI_ERR_TAG;
886 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
887 int src_traced = smpi_comm_group(comm)->index(src);
888 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
889 extra->type = TRACING_RECV;
890 extra->src = src_traced;
893 extra->datatype1 = encode_datatype(datatype, &known);
894 int dt_size_send = 1;
896 dt_size_send = smpi_datatype_size(datatype);
897 extra->send_size = count * dt_size_send;
898 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
900 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
901 retval = MPI_SUCCESS;
903 // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
904 if (status != MPI_STATUS_IGNORE) {
905 src_traced = smpi_comm_group(comm)->index(status->MPI_SOURCE);
906 if (!TRACE_smpi_view_internals()) {
907 TRACE_smpi_recv(rank, src_traced, rank, tag);
910 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
917 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
923 if (comm == MPI_COMM_NULL) {
924 retval = MPI_ERR_COMM;
925 } else if (dst == MPI_PROC_NULL) {
926 retval = MPI_SUCCESS;
927 } else if (dst >= smpi_comm_group(comm)->size() || dst <0){
928 retval = MPI_ERR_RANK;
929 } else if ((count < 0) || (buf == nullptr && count > 0)) {
930 retval = MPI_ERR_COUNT;
931 } else if (!is_datatype_valid(datatype)) {
932 retval = MPI_ERR_TYPE;
933 } else if(tag < 0 && tag != MPI_ANY_TAG){
934 retval = MPI_ERR_TAG;
936 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
937 int dst_traced = smpi_comm_group(comm)->index(dst);
938 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
939 extra->type = TRACING_SEND;
941 extra->dst = dst_traced;
943 extra->datatype1 = encode_datatype(datatype, &known);
944 int dt_size_send = 1;
946 dt_size_send = smpi_datatype_size(datatype);
948 extra->send_size = count*dt_size_send;
949 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
950 if (!TRACE_smpi_view_internals()) {
951 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
954 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
955 retval = MPI_SUCCESS;
957 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
964 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
969 if (comm == MPI_COMM_NULL) {
970 retval = MPI_ERR_COMM;
971 } else if (dst == MPI_PROC_NULL) {
972 retval = MPI_SUCCESS;
973 } else if (dst >= smpi_comm_group(comm)->size() || dst <0){
974 retval = MPI_ERR_RANK;
975 } else if ((count < 0) || (buf==nullptr && count > 0)) {
976 retval = MPI_ERR_COUNT;
977 } else if (!is_datatype_valid(datatype)){
978 retval = MPI_ERR_TYPE;
979 } else if(tag<0 && tag != MPI_ANY_TAG){
980 retval = MPI_ERR_TAG;
982 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
983 int dst_traced = smpi_comm_group(comm)->index(dst);
984 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
985 extra->type = TRACING_SSEND;
987 extra->dst = dst_traced;
989 extra->datatype1 = encode_datatype(datatype, &known);
990 int dt_size_send = 1;
992 dt_size_send = smpi_datatype_size(datatype);
994 extra->send_size = count*dt_size_send;
995 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
996 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
998 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
999 retval = MPI_SUCCESS;
1001 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1008 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1009 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1015 if (comm == MPI_COMM_NULL) {
1016 retval = MPI_ERR_COMM;
1017 } else if (!is_datatype_valid(sendtype) || !is_datatype_valid(recvtype)) {
1018 retval = MPI_ERR_TYPE;
1019 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1020 smpi_empty_status(status);
1021 status->MPI_SOURCE = MPI_PROC_NULL;
1022 retval = MPI_SUCCESS;
1023 }else if (dst >= smpi_comm_group(comm)->size() || dst <0 ||
1024 (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->size() || src <0))){
1025 retval = MPI_ERR_RANK;
1026 } else if ((sendcount < 0 || recvcount<0) ||
1027 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1028 retval = MPI_ERR_COUNT;
1029 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1030 retval = MPI_ERR_TAG;
1033 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1034 int dst_traced = smpi_comm_group(comm)->index(dst);
1035 int src_traced = smpi_comm_group(comm)->index(src);
1036 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1037 extra->type = TRACING_SENDRECV;
1038 extra->src = src_traced;
1039 extra->dst = dst_traced;
1041 extra->datatype1 = encode_datatype(sendtype, &known);
1042 int dt_size_send = 1;
1044 dt_size_send = smpi_datatype_size(sendtype);
1045 extra->send_size = sendcount*dt_size_send;
1046 extra->datatype2 = encode_datatype(recvtype, &known);
1047 int dt_size_recv = 1;
1049 dt_size_recv = smpi_datatype_size(recvtype);
1050 extra->recv_size = recvcount*dt_size_recv;
1052 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1053 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1055 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm,
1057 retval = MPI_SUCCESS;
1059 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1060 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1067 int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1068 MPI_Comm comm, MPI_Status* status)
1071 if (!is_datatype_valid(datatype)) {
1072 return MPI_ERR_TYPE;
1073 } else if (count < 0) {
1074 return MPI_ERR_COUNT;
1076 int size = smpi_datatype_get_extent(datatype) * count;
1077 void* recvbuf = xbt_new0(char, size);
1078 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1079 if(retval==MPI_SUCCESS){
1080 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1088 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1092 if (request == nullptr || flag == nullptr) {
1093 retval = MPI_ERR_ARG;
1094 } else if (*request == MPI_REQUEST_NULL) {
1096 smpi_empty_status(status);
1097 retval = MPI_SUCCESS;
1099 int rank = ((*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1101 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1102 extra->type = TRACING_TEST;
1103 TRACE_smpi_testing_in(rank, extra);
1105 *flag = smpi_mpi_test(request, status);
1107 TRACE_smpi_testing_out(rank);
1108 retval = MPI_SUCCESS;
1114 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1119 if (index == nullptr || flag == nullptr) {
1120 retval = MPI_ERR_ARG;
1122 *flag = smpi_mpi_testany(count, requests, index, status);
1123 retval = MPI_SUCCESS;
1129 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1134 if (flag == nullptr) {
1135 retval = MPI_ERR_ARG;
1137 *flag = smpi_mpi_testall(count, requests, statuses);
1138 retval = MPI_SUCCESS;
1144 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1148 if (status == nullptr) {
1149 retval = MPI_ERR_ARG;
1150 } else if (comm == MPI_COMM_NULL) {
1151 retval = MPI_ERR_COMM;
1152 } else if (source == MPI_PROC_NULL) {
1153 smpi_empty_status(status);
1154 status->MPI_SOURCE = MPI_PROC_NULL;
1155 retval = MPI_SUCCESS;
1157 smpi_mpi_probe(source, tag, comm, status);
1158 retval = MPI_SUCCESS;
1164 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1168 if ((flag == nullptr) || (status == nullptr)) {
1169 retval = MPI_ERR_ARG;
1170 } else if (comm == MPI_COMM_NULL) {
1171 retval = MPI_ERR_COMM;
1172 } else if (source == MPI_PROC_NULL) {
1174 smpi_empty_status(status);
1175 status->MPI_SOURCE = MPI_PROC_NULL;
1176 retval = MPI_SUCCESS;
1178 smpi_mpi_iprobe(source, tag, comm, flag, status);
1179 retval = MPI_SUCCESS;
1185 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1191 smpi_empty_status(status);
1193 if (request == nullptr) {
1194 retval = MPI_ERR_ARG;
1195 } else if (*request == MPI_REQUEST_NULL) {
1196 retval = MPI_SUCCESS;
1199 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1201 int src_traced = (*request)->src;
1202 int dst_traced = (*request)->dst;
1203 int tag_traced= (*request)->tag;
1204 MPI_Comm comm = (*request)->comm;
1205 int is_wait_for_receive = (*request)->recv;
1206 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1207 extra->type = TRACING_WAIT;
1208 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1210 smpi_mpi_wait(request, status);
1211 retval = MPI_SUCCESS;
1213 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1214 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1215 if (is_wait_for_receive) {
1216 if(src_traced==MPI_ANY_SOURCE)
1217 src_traced = (status!=MPI_STATUS_IGNORE) ?
1218 smpi_comm_group(comm)->rank(status->MPI_SOURCE) :
1220 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1228 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1230 if (index == nullptr)
1234 //save requests information for tracing
1242 savedvalstype* savedvals=nullptr;
1244 savedvals = xbt_new0(savedvalstype, count);
1246 for (int i = 0; i < count; i++) {
1247 MPI_Request req = requests[i]; //already received requests are no longer valid
1249 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1252 int rank_traced = smpi_process_index();
1253 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1254 extra->type = TRACING_WAITANY;
1255 extra->send_size=count;
1256 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1258 *index = smpi_mpi_waitany(count, requests, status);
1260 if(*index!=MPI_UNDEFINED){
1261 int src_traced = savedvals[*index].src;
1262 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1263 int dst_traced = savedvals[*index].dst;
1264 int is_wait_for_receive = savedvals[*index].recv;
1265 if (is_wait_for_receive) {
1266 if(savedvals[*index].src==MPI_ANY_SOURCE)
1267 src_traced = (status != MPI_STATUSES_IGNORE)
1268 ? smpi_comm_group(savedvals[*index].comm)->rank(status->MPI_SOURCE)
1269 : savedvals[*index].src;
1270 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1272 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1274 xbt_free(savedvals);
1280 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1283 //save information from requests
1292 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1294 for (int i = 0; i < count; i++) {
1295 MPI_Request req = requests[i];
1296 if(req!=MPI_REQUEST_NULL){
1297 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1299 savedvals[i].valid=0;
1302 int rank_traced = smpi_process_index();
1303 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1304 extra->type = TRACING_WAITALL;
1305 extra->send_size=count;
1306 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1308 int retval = smpi_mpi_waitall(count, requests, status);
1310 for (int i = 0; i < count; i++) {
1311 if(savedvals[i].valid){
1312 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1313 int src_traced = savedvals[i].src;
1314 int dst_traced = savedvals[i].dst;
1315 int is_wait_for_receive = savedvals[i].recv;
1316 if (is_wait_for_receive) {
1317 if(src_traced==MPI_ANY_SOURCE)
1318 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1319 smpi_comm_group(savedvals[i].comm)->rank(status[i].MPI_SOURCE) : savedvals[i].src;
1320 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1324 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1325 xbt_free(savedvals);
1331 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1336 if (outcount == nullptr) {
1337 retval = MPI_ERR_ARG;
1339 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1340 retval = MPI_SUCCESS;
1346 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1351 if (outcount == nullptr) {
1352 retval = MPI_ERR_ARG;
1354 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1355 retval = MPI_SUCCESS;
1362 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1368 if (comm == MPI_COMM_NULL) {
1369 retval = MPI_ERR_COMM;
1370 } else if (!is_datatype_valid(datatype)) {
1371 retval = MPI_ERR_ARG;
1373 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1374 int root_traced = smpi_comm_group(comm)->index(root);
1376 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1377 extra->type = TRACING_BCAST;
1378 extra->root = root_traced;
1380 extra->datatype1 = encode_datatype(datatype, &known);
1381 int dt_size_send = 1;
1383 dt_size_send = smpi_datatype_size(datatype);
1384 extra->send_size = count * dt_size_send;
1385 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1386 if (smpi_comm_size(comm) > 1)
1387 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1388 retval = MPI_SUCCESS;
1390 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1396 int PMPI_Barrier(MPI_Comm comm)
1402 if (comm == MPI_COMM_NULL) {
1403 retval = MPI_ERR_COMM;
1405 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1406 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1407 extra->type = TRACING_BARRIER;
1408 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1410 mpi_coll_barrier_fun(comm);
1411 retval = MPI_SUCCESS;
1413 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1420 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1421 int root, MPI_Comm comm)
1427 if (comm == MPI_COMM_NULL) {
1428 retval = MPI_ERR_COMM;
1429 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1430 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1431 retval = MPI_ERR_TYPE;
1432 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1433 retval = MPI_ERR_COUNT;
1436 char* sendtmpbuf = static_cast<char*>(sendbuf);
1437 int sendtmpcount = sendcount;
1438 MPI_Datatype sendtmptype = sendtype;
1439 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1441 sendtmptype=recvtype;
1443 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1444 int root_traced = smpi_comm_group(comm)->index(root);
1445 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1446 extra->type = TRACING_GATHER;
1447 extra->root = root_traced;
1449 extra->datatype1 = encode_datatype(sendtmptype, &known);
1450 int dt_size_send = 1;
1452 dt_size_send = smpi_datatype_size(sendtmptype);
1453 extra->send_size = sendtmpcount * dt_size_send;
1454 extra->datatype2 = encode_datatype(recvtype, &known);
1455 int dt_size_recv = 1;
1456 if ((smpi_comm_rank(comm) == root) && known == 0)
1457 dt_size_recv = smpi_datatype_size(recvtype);
1458 extra->recv_size = recvcount * dt_size_recv;
1460 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1462 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1464 retval = MPI_SUCCESS;
1465 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1472 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1473 MPI_Datatype recvtype, int root, MPI_Comm comm)
1479 if (comm == MPI_COMM_NULL) {
1480 retval = MPI_ERR_COMM;
1481 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1482 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1483 retval = MPI_ERR_TYPE;
1484 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1485 retval = MPI_ERR_COUNT;
1486 } else if (recvcounts == nullptr || displs == nullptr) {
1487 retval = MPI_ERR_ARG;
1489 char* sendtmpbuf = static_cast<char*>(sendbuf);
1490 int sendtmpcount = sendcount;
1491 MPI_Datatype sendtmptype = sendtype;
1492 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1494 sendtmptype=recvtype;
1497 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1498 int root_traced = smpi_comm_group(comm)->index(root);
1500 int size = smpi_comm_size(comm);
1501 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1502 extra->type = TRACING_GATHERV;
1503 extra->num_processes = size;
1504 extra->root = root_traced;
1506 extra->datatype1 = encode_datatype(sendtmptype, &known);
1507 int dt_size_send = 1;
1509 dt_size_send = smpi_datatype_size(sendtype);
1510 extra->send_size = sendtmpcount * dt_size_send;
1511 extra->datatype2 = encode_datatype(recvtype, &known);
1512 int dt_size_recv = 1;
1514 dt_size_recv = smpi_datatype_size(recvtype);
1515 if ((smpi_comm_rank(comm) == root)) {
1516 extra->recvcounts = xbt_new(int, size);
1517 for (i = 0; i < size; i++) // copy data to avoid bad free
1518 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
1520 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1522 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1523 retval = MPI_SUCCESS;
1524 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1531 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1532 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1538 if (comm == MPI_COMM_NULL) {
1539 retval = MPI_ERR_COMM;
1540 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1541 (recvtype == MPI_DATATYPE_NULL)){
1542 retval = MPI_ERR_TYPE;
1543 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1545 retval = MPI_ERR_COUNT;
1547 if(sendbuf == MPI_IN_PLACE) {
1548 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1549 sendcount=recvcount;
1552 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1553 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1554 extra->type = TRACING_ALLGATHER;
1556 extra->datatype1 = encode_datatype(sendtype, &known);
1557 int dt_size_send = 1;
1559 dt_size_send = smpi_datatype_size(sendtype);
1560 extra->send_size = sendcount * dt_size_send;
1561 extra->datatype2 = encode_datatype(recvtype, &known);
1562 int dt_size_recv = 1;
1564 dt_size_recv = smpi_datatype_size(recvtype);
1565 extra->recv_size = recvcount * dt_size_recv;
1567 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1569 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1570 retval = MPI_SUCCESS;
1571 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1577 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1578 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1584 if (comm == MPI_COMM_NULL) {
1585 retval = MPI_ERR_COMM;
1586 } else if (((sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) || (recvtype == MPI_DATATYPE_NULL)) {
1587 retval = MPI_ERR_TYPE;
1588 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1589 retval = MPI_ERR_COUNT;
1590 } else if (recvcounts == nullptr || displs == nullptr) {
1591 retval = MPI_ERR_ARG;
1594 if(sendbuf == MPI_IN_PLACE) {
1595 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1596 sendcount=recvcounts[smpi_comm_rank(comm)];
1599 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1601 int size = smpi_comm_size(comm);
1602 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1603 extra->type = TRACING_ALLGATHERV;
1604 extra->num_processes = size;
1606 extra->datatype1 = encode_datatype(sendtype, &known);
1607 int dt_size_send = 1;
1609 dt_size_send = smpi_datatype_size(sendtype);
1610 extra->send_size = sendcount * dt_size_send;
1611 extra->datatype2 = encode_datatype(recvtype, &known);
1612 int dt_size_recv = 1;
1614 dt_size_recv = smpi_datatype_size(recvtype);
1615 extra->recvcounts = xbt_new(int, size);
1616 for (i = 0; i < size; i++) // copy data to avoid bad free
1617 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
1619 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1621 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1622 retval = MPI_SUCCESS;
1623 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1630 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1631 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1637 if (comm == MPI_COMM_NULL) {
1638 retval = MPI_ERR_COMM;
1639 } else if (((smpi_comm_rank(comm) == root) && (!is_datatype_valid(sendtype))) ||
1640 ((recvbuf != MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))) {
1641 retval = MPI_ERR_TYPE;
1642 } else if ((sendbuf == recvbuf) ||
1643 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1644 retval = MPI_ERR_BUFFER;
1647 if (recvbuf == MPI_IN_PLACE) {
1648 recvtype = sendtype;
1649 recvcount = sendcount;
1651 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1652 int root_traced = smpi_comm_group(comm)->index(root);
1653 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1654 extra->type = TRACING_SCATTER;
1655 extra->root = root_traced;
1657 extra->datatype1 = encode_datatype(sendtype, &known);
1658 int dt_size_send = 1;
1659 if ((smpi_comm_rank(comm) == root) && known == 0)
1660 dt_size_send = smpi_datatype_size(sendtype);
1661 extra->send_size = sendcount * dt_size_send;
1662 extra->datatype2 = encode_datatype(recvtype, &known);
1663 int dt_size_recv = 1;
1665 dt_size_recv = smpi_datatype_size(recvtype);
1666 extra->recv_size = recvcount * dt_size_recv;
1667 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1669 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1670 retval = MPI_SUCCESS;
1671 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1678 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1679 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1685 if (comm == MPI_COMM_NULL) {
1686 retval = MPI_ERR_COMM;
1687 } else if (sendcounts == nullptr || displs == nullptr) {
1688 retval = MPI_ERR_ARG;
1689 } else if (((smpi_comm_rank(comm) == root) && (sendtype == MPI_DATATYPE_NULL)) ||
1690 ((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1691 retval = MPI_ERR_TYPE;
1693 if (recvbuf == MPI_IN_PLACE) {
1694 recvtype = sendtype;
1695 recvcount = sendcounts[smpi_comm_rank(comm)];
1697 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1698 int root_traced = smpi_comm_group(comm)->index(root);
1700 int size = smpi_comm_size(comm);
1701 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1702 extra->type = TRACING_SCATTERV;
1703 extra->num_processes = size;
1704 extra->root = root_traced;
1706 extra->datatype1 = encode_datatype(sendtype, &known);
1707 int dt_size_send = 1;
1709 dt_size_send = smpi_datatype_size(sendtype);
1710 if ((smpi_comm_rank(comm) == root)) {
1711 extra->sendcounts = xbt_new(int, size);
1712 for (i = 0; i < size; i++) // copy data to avoid bad free
1713 extra->sendcounts[i] = sendcounts[i] * dt_size_send;
1715 extra->datatype2 = encode_datatype(recvtype, &known);
1716 int dt_size_recv = 1;
1718 dt_size_recv = smpi_datatype_size(recvtype);
1719 extra->recv_size = recvcount * dt_size_recv;
1720 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1722 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1724 retval = MPI_SUCCESS;
1725 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1732 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1738 if (comm == MPI_COMM_NULL) {
1739 retval = MPI_ERR_COMM;
1740 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1741 retval = MPI_ERR_ARG;
1743 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1744 int root_traced = smpi_comm_group(comm)->index(root);
1745 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1746 extra->type = TRACING_REDUCE;
1748 extra->datatype1 = encode_datatype(datatype, &known);
1749 int dt_size_send = 1;
1751 dt_size_send = smpi_datatype_size(datatype);
1752 extra->send_size = count * dt_size_send;
1753 extra->root = root_traced;
1755 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1757 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
1759 retval = MPI_SUCCESS;
1760 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1767 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
1771 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1772 retval = MPI_ERR_ARG;
1774 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
1775 retval = MPI_SUCCESS;
1781 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1787 if (comm == MPI_COMM_NULL) {
1788 retval = MPI_ERR_COMM;
1789 } else if (!is_datatype_valid(datatype)) {
1790 retval = MPI_ERR_TYPE;
1791 } else if (op == MPI_OP_NULL) {
1792 retval = MPI_ERR_OP;
1795 char* sendtmpbuf = static_cast<char*>(sendbuf);
1796 if( sendbuf == MPI_IN_PLACE ) {
1797 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
1798 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
1800 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1801 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1802 extra->type = TRACING_ALLREDUCE;
1804 extra->datatype1 = encode_datatype(datatype, &known);
1805 int dt_size_send = 1;
1807 dt_size_send = smpi_datatype_size(datatype);
1808 extra->send_size = count * dt_size_send;
1810 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1812 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
1814 if( sendbuf == MPI_IN_PLACE )
1815 xbt_free(sendtmpbuf);
1817 retval = MPI_SUCCESS;
1818 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1825 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1831 if (comm == MPI_COMM_NULL) {
1832 retval = MPI_ERR_COMM;
1833 } else if (!is_datatype_valid(datatype)) {
1834 retval = MPI_ERR_TYPE;
1835 } else if (op == MPI_OP_NULL) {
1836 retval = MPI_ERR_OP;
1838 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1839 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1840 extra->type = TRACING_SCAN;
1842 extra->datatype1 = encode_datatype(datatype, &known);
1843 int dt_size_send = 1;
1845 dt_size_send = smpi_datatype_size(datatype);
1846 extra->send_size = count * dt_size_send;
1848 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1850 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
1852 retval = MPI_SUCCESS;
1853 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1860 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
1865 if (comm == MPI_COMM_NULL) {
1866 retval = MPI_ERR_COMM;
1867 } else if (!is_datatype_valid(datatype)) {
1868 retval = MPI_ERR_TYPE;
1869 } else if (op == MPI_OP_NULL) {
1870 retval = MPI_ERR_OP;
1872 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1873 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1874 extra->type = TRACING_EXSCAN;
1876 extra->datatype1 = encode_datatype(datatype, &known);
1877 int dt_size_send = 1;
1879 dt_size_send = smpi_datatype_size(datatype);
1880 extra->send_size = count * dt_size_send;
1881 void* sendtmpbuf = sendbuf;
1882 if (sendbuf == MPI_IN_PLACE) {
1883 sendtmpbuf = static_cast<void*>(xbt_malloc(count * smpi_datatype_size(datatype)));
1884 memcpy(sendtmpbuf, recvbuf, count * smpi_datatype_size(datatype));
1886 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1888 smpi_mpi_exscan(sendtmpbuf, recvbuf, count, datatype, op, comm);
1889 retval = MPI_SUCCESS;
1890 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1891 if (sendbuf == MPI_IN_PLACE)
1892 xbt_free(sendtmpbuf);
1899 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1904 if (comm == MPI_COMM_NULL) {
1905 retval = MPI_ERR_COMM;
1906 } else if (!is_datatype_valid(datatype)) {
1907 retval = MPI_ERR_TYPE;
1908 } else if (op == MPI_OP_NULL) {
1909 retval = MPI_ERR_OP;
1910 } else if (recvcounts == nullptr) {
1911 retval = MPI_ERR_ARG;
1913 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1915 int size = smpi_comm_size(comm);
1916 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1917 extra->type = TRACING_REDUCE_SCATTER;
1918 extra->num_processes = size;
1920 extra->datatype1 = encode_datatype(datatype, &known);
1921 int dt_size_send = 1;
1923 dt_size_send = smpi_datatype_size(datatype);
1924 extra->send_size = 0;
1925 extra->recvcounts = xbt_new(int, size);
1927 for (i = 0; i < size; i++) { // copy data to avoid bad free
1928 extra->recvcounts[i] = recvcounts[i] * dt_size_send;
1929 totalcount += recvcounts[i];
1931 void* sendtmpbuf = sendbuf;
1932 if (sendbuf == MPI_IN_PLACE) {
1933 sendtmpbuf = static_cast<void*>(xbt_malloc(totalcount * smpi_datatype_size(datatype)));
1934 memcpy(sendtmpbuf, recvbuf, totalcount * smpi_datatype_size(datatype));
1937 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1939 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
1940 retval = MPI_SUCCESS;
1941 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1943 if (sendbuf == MPI_IN_PLACE)
1944 xbt_free(sendtmpbuf);
1951 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
1952 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1957 if (comm == MPI_COMM_NULL) {
1958 retval = MPI_ERR_COMM;
1959 } else if (!is_datatype_valid(datatype)) {
1960 retval = MPI_ERR_TYPE;
1961 } else if (op == MPI_OP_NULL) {
1962 retval = MPI_ERR_OP;
1963 } else if (recvcount < 0) {
1964 retval = MPI_ERR_ARG;
1966 int count = smpi_comm_size(comm);
1968 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1969 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1970 extra->type = TRACING_REDUCE_SCATTER;
1971 extra->num_processes = count;
1973 extra->datatype1 = encode_datatype(datatype, &known);
1974 int dt_size_send = 1;
1976 dt_size_send = smpi_datatype_size(datatype);
1977 extra->send_size = 0;
1978 extra->recvcounts = xbt_new(int, count);
1979 for (int i = 0; i < count; i++) // copy data to avoid bad free
1980 extra->recvcounts[i] = recvcount * dt_size_send;
1981 void* sendtmpbuf = sendbuf;
1982 if (sendbuf == MPI_IN_PLACE) {
1983 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount * count * smpi_datatype_size(datatype)));
1984 memcpy(sendtmpbuf, recvbuf, recvcount * count * smpi_datatype_size(datatype));
1987 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1989 int* recvcounts = static_cast<int*>(xbt_malloc(count * sizeof(int)));
1990 for (int i = 0; i < count; i++)
1991 recvcounts[i] = recvcount;
1992 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
1993 xbt_free(recvcounts);
1994 retval = MPI_SUCCESS;
1996 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1998 if (sendbuf == MPI_IN_PLACE)
1999 xbt_free(sendtmpbuf);
2006 int PMPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
2007 MPI_Datatype recvtype, MPI_Comm comm)
2012 if (comm == MPI_COMM_NULL) {
2013 retval = MPI_ERR_COMM;
2014 } else if ((sendbuf != MPI_IN_PLACE && sendtype == MPI_DATATYPE_NULL) || recvtype == MPI_DATATYPE_NULL) {
2015 retval = MPI_ERR_TYPE;
2017 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2018 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2019 extra->type = TRACING_ALLTOALL;
2021 void* sendtmpbuf = static_cast<char*>(sendbuf);
2022 int sendtmpcount = sendcount;
2023 MPI_Datatype sendtmptype = sendtype;
2024 if (sendbuf == MPI_IN_PLACE) {
2025 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount * smpi_comm_size(comm) * smpi_datatype_size(recvtype)));
2026 memcpy(sendtmpbuf, recvbuf, recvcount * smpi_comm_size(comm) * smpi_datatype_size(recvtype));
2027 sendtmpcount = recvcount;
2028 sendtmptype = recvtype;
2032 extra->datatype1 = encode_datatype(sendtmptype, &known);
2034 extra->send_size = sendtmpcount * smpi_datatype_size(sendtmptype);
2036 extra->send_size = sendtmpcount;
2037 extra->datatype2 = encode_datatype(recvtype, &known);
2039 extra->recv_size = recvcount * smpi_datatype_size(recvtype);
2041 extra->recv_size = recvcount;
2043 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2045 retval = mpi_coll_alltoall_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, comm);
2047 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2049 if (sendbuf == MPI_IN_PLACE)
2050 xbt_free(sendtmpbuf);
2057 int PMPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf,
2058 int* recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2064 if (comm == MPI_COMM_NULL) {
2065 retval = MPI_ERR_COMM;
2066 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2067 retval = MPI_ERR_TYPE;
2068 } else if ((sendbuf != MPI_IN_PLACE && (sendcounts == nullptr || senddisps == nullptr)) || recvcounts == nullptr ||
2069 recvdisps == nullptr) {
2070 retval = MPI_ERR_ARG;
2072 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2074 int size = smpi_comm_size(comm);
2075 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2076 extra->type = TRACING_ALLTOALLV;
2077 extra->send_size = 0;
2078 extra->recv_size = 0;
2079 extra->recvcounts = xbt_new(int, size);
2080 extra->sendcounts = xbt_new(int, size);
2082 int dt_size_recv = 1;
2083 extra->datatype2 = encode_datatype(recvtype, &known);
2084 dt_size_recv = smpi_datatype_size(recvtype);
2086 void* sendtmpbuf = static_cast<char*>(sendbuf);
2087 int* sendtmpcounts = sendcounts;
2088 int* sendtmpdisps = senddisps;
2089 MPI_Datatype sendtmptype = sendtype;
2091 for (i = 0; i < size; i++) { // copy data to avoid bad free
2092 extra->recv_size += recvcounts[i] * dt_size_recv;
2093 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
2094 if (((recvdisps[i] + recvcounts[i]) * dt_size_recv) > maxsize)
2095 maxsize = (recvdisps[i] + recvcounts[i]) * dt_size_recv;
2098 if (sendbuf == MPI_IN_PLACE) {
2099 sendtmpbuf = static_cast<void*>(xbt_malloc(maxsize));
2100 memcpy(sendtmpbuf, recvbuf, maxsize);
2101 sendtmpcounts = static_cast<int*>(xbt_malloc(size * sizeof(int)));
2102 memcpy(sendtmpcounts, recvcounts, size * sizeof(int));
2103 sendtmpdisps = static_cast<int*>(xbt_malloc(size * sizeof(int)));
2104 memcpy(sendtmpdisps, recvdisps, size * sizeof(int));
2105 sendtmptype = recvtype;
2108 extra->datatype1 = encode_datatype(sendtmptype, &known);
2109 int dt_size_send = 1;
2110 dt_size_send = smpi_datatype_size(sendtmptype);
2112 for (i = 0; i < size; i++) { // copy data to avoid bad free
2113 extra->send_size += sendtmpcounts[i] * dt_size_send;
2114 extra->sendcounts[i] = sendtmpcounts[i] * dt_size_send;
2116 extra->num_processes = size;
2117 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2118 retval = mpi_coll_alltoallv_fun(sendtmpbuf, sendtmpcounts, sendtmpdisps, sendtmptype, recvbuf, recvcounts,
2119 recvdisps, recvtype, comm);
2120 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2122 if (sendbuf == MPI_IN_PLACE) {
2123 xbt_free(sendtmpbuf);
2124 xbt_free(sendtmpcounts);
2125 xbt_free(sendtmpdisps);
2134 int PMPI_Get_processor_name(char *name, int *resultlen)
2136 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2137 ? strlen(SIMIX_host_self()->cname()) + 1
2138 : MPI_MAX_PROCESSOR_NAME - 1);
2139 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2144 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2146 if (status == nullptr || count == nullptr) {
2148 } else if (!is_datatype_valid(datatype)) {
2149 return MPI_ERR_TYPE;
2151 size_t size = smpi_datatype_size(datatype);
2155 } else if (status->count % size != 0) {
2156 return MPI_UNDEFINED;
2158 *count = smpi_mpi_get_count(status, datatype);
2164 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2165 if (old_type == MPI_DATATYPE_NULL) {
2166 return MPI_ERR_TYPE;
2167 } else if (count<0){
2168 return MPI_ERR_COUNT;
2170 return smpi_datatype_contiguous(count, old_type, new_type, 0);
2174 int PMPI_Type_commit(MPI_Datatype* datatype) {
2175 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2176 return MPI_ERR_TYPE;
2178 smpi_datatype_commit(datatype);
2183 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2184 if (old_type == MPI_DATATYPE_NULL) {
2185 return MPI_ERR_TYPE;
2186 } else if (count<0 || blocklen<0){
2187 return MPI_ERR_COUNT;
2189 return smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2193 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2194 if (old_type == MPI_DATATYPE_NULL) {
2195 return MPI_ERR_TYPE;
2196 } else if (count<0 || blocklen<0){
2197 return MPI_ERR_COUNT;
2199 return smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2203 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2204 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2207 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2208 if (old_type == MPI_DATATYPE_NULL) {
2209 return MPI_ERR_TYPE;
2210 } else if (count<0){
2211 return MPI_ERR_COUNT;
2213 return smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2217 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2218 if (old_type == MPI_DATATYPE_NULL) {
2219 return MPI_ERR_TYPE;
2220 } else if (count<0){
2221 return MPI_ERR_COUNT;
2223 return smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2227 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2228 MPI_Datatype* new_type)
2230 if (old_type == MPI_DATATYPE_NULL) {
2231 return MPI_ERR_TYPE;
2232 } else if (count<0){
2233 return MPI_ERR_COUNT;
2235 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count*sizeof(int)));
2236 for (int i = 0; i < count; i++)
2237 blocklens[i]=blocklength;
2238 int retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2239 xbt_free(blocklens);
2244 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
2246 if (old_type == MPI_DATATYPE_NULL) {
2247 return MPI_ERR_TYPE;
2248 } else if (count<0){
2249 return MPI_ERR_COUNT;
2251 return smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2255 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2256 MPI_Datatype* new_type) {
2257 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2260 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2261 MPI_Datatype* new_type) {
2262 if (old_type == MPI_DATATYPE_NULL) {
2263 return MPI_ERR_TYPE;
2264 } else if (count<0){
2265 return MPI_ERR_COUNT;
2267 int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int));
2268 for (int i = 0; i < count; i++)
2269 blocklens[i] = blocklength;
2270 int retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2271 xbt_free(blocklens);
2276 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2278 return MPI_ERR_COUNT;
2280 return smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2284 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2285 MPI_Datatype* new_type) {
2286 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2289 int PMPI_Error_class(int errorcode, int* errorclass) {
2290 // assume smpi uses only standard mpi error codes
2291 *errorclass=errorcode;
2295 int PMPI_Initialized(int* flag) {
2296 *flag=smpi_process_initialized();
2300 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2301 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2302 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2304 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2305 if (comm_old == MPI_COMM_NULL){
2306 return MPI_ERR_COMM;
2307 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2310 return smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2314 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2315 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2316 return MPI_ERR_TOPOLOGY;
2318 if (coords == nullptr) {
2321 return smpi_mpi_cart_rank(comm, coords, rank);
2324 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2325 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2326 return MPI_ERR_TOPOLOGY;
2328 if (source == nullptr || dest == nullptr || direction < 0 ) {
2331 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2334 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2335 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2336 return MPI_ERR_TOPOLOGY;
2338 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2339 return MPI_ERR_RANK;
2344 if(coords == nullptr) {
2347 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2350 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2351 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2352 return MPI_ERR_TOPOLOGY;
2354 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2357 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2360 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2361 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2362 return MPI_ERR_TOPOLOGY;
2364 if (ndims == nullptr) {
2367 return smpi_mpi_cartdim_get(comm, ndims);
2370 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2371 if(dims == nullptr) {
2374 if (ndims < 1 || nnodes < 1) {
2375 return MPI_ERR_DIMS;
2378 return smpi_mpi_dims_create(nnodes, ndims, dims);
2381 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2382 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2383 return MPI_ERR_TOPOLOGY;
2385 if (comm_new == nullptr) {
2388 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2391 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2392 if (oldtype == MPI_DATATYPE_NULL) {
2393 return MPI_ERR_TYPE;
2395 int blocks[3] = {1, 1, 1};
2396 MPI_Aint disps[3] = {lb, 0, lb + extent};
2397 MPI_Datatype types[3] = {MPI_LB, oldtype, MPI_UB};
2399 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create(blocks, disps, 3, types);
2400 smpi_datatype_create(newtype, oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t), subtype, DT_FLAG_VECTOR);
2402 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2406 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2409 if (comm == MPI_COMM_NULL) {
2410 retval= MPI_ERR_COMM;
2411 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2412 retval= MPI_ERR_OTHER;
2414 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2415 retval = MPI_SUCCESS;
2421 int PMPI_Win_free( MPI_Win* win){
2424 if (win == nullptr || *win == MPI_WIN_NULL) {
2425 retval = MPI_ERR_WIN;
2427 retval=smpi_mpi_win_free(win);
2433 int PMPI_Win_set_name(MPI_Win win, char * name)
2435 if (win == MPI_WIN_NULL) {
2436 return MPI_ERR_TYPE;
2437 } else if (name == nullptr) {
2440 smpi_mpi_win_set_name(win, name);
2445 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2447 if (win == MPI_WIN_NULL) {
2449 } else if (name == nullptr) {
2452 smpi_mpi_win_get_name(win, name, len);
2457 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2458 if (win == MPI_WIN_NULL) {
2461 smpi_mpi_win_get_group(win, group);
2467 int PMPI_Win_fence( int assert, MPI_Win win){
2470 if (win == MPI_WIN_NULL) {
2471 retval = MPI_ERR_WIN;
2473 int rank = smpi_process_index();
2474 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2475 retval = smpi_mpi_win_fence(assert, win);
2476 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2482 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2483 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2486 if (win == MPI_WIN_NULL) {
2487 retval = MPI_ERR_WIN;
2488 } else if (target_rank == MPI_PROC_NULL) {
2489 retval = MPI_SUCCESS;
2490 } else if (target_rank <0){
2491 retval = MPI_ERR_RANK;
2492 } else if (target_disp <0){
2493 retval = MPI_ERR_ARG;
2494 } else if ((origin_count < 0 || target_count < 0) ||
2495 (origin_addr==nullptr && origin_count > 0)){
2496 retval = MPI_ERR_COUNT;
2497 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2498 retval = MPI_ERR_TYPE;
2500 int rank = smpi_process_index();
2502 smpi_mpi_win_get_group(win, &group);
2503 int src_traced = group->index(target_rank);
2504 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2506 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2507 target_datatype, win);
2509 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2515 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2516 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2519 if (win == MPI_WIN_NULL) {
2520 retval = MPI_ERR_WIN;
2521 } else if (target_rank == MPI_PROC_NULL) {
2522 retval = MPI_SUCCESS;
2523 } else if (target_rank <0){
2524 retval = MPI_ERR_RANK;
2525 } else if (target_disp <0){
2526 retval = MPI_ERR_ARG;
2527 } else if ((origin_count < 0 || target_count < 0) ||
2528 (origin_addr==nullptr && origin_count > 0)){
2529 retval = MPI_ERR_COUNT;
2530 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2531 retval = MPI_ERR_TYPE;
2533 int rank = smpi_process_index();
2535 smpi_mpi_win_get_group(win, &group);
2536 int dst_traced = group->index(target_rank);
2537 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2538 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2540 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2541 target_datatype, win);
2543 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2549 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2550 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2553 if (win == MPI_WIN_NULL) {
2554 retval = MPI_ERR_WIN;
2555 } else if (target_rank == MPI_PROC_NULL) {
2556 retval = MPI_SUCCESS;
2557 } else if (target_rank <0){
2558 retval = MPI_ERR_RANK;
2559 } else if (target_disp <0){
2560 retval = MPI_ERR_ARG;
2561 } else if ((origin_count < 0 || target_count < 0) ||
2562 (origin_addr==nullptr && origin_count > 0)){
2563 retval = MPI_ERR_COUNT;
2564 } else if ((!is_datatype_valid(origin_datatype)) ||
2565 (!is_datatype_valid(target_datatype))) {
2566 retval = MPI_ERR_TYPE;
2567 } else if (op == MPI_OP_NULL) {
2568 retval = MPI_ERR_OP;
2570 int rank = smpi_process_index();
2572 smpi_mpi_win_get_group(win, &group);
2573 int src_traced = group->index(target_rank);
2574 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2576 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2577 target_datatype, op, win);
2579 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2585 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2588 if (win == MPI_WIN_NULL) {
2589 retval = MPI_ERR_WIN;
2590 } else if (group==MPI_GROUP_NULL){
2591 retval = MPI_ERR_GROUP;
2593 int rank = smpi_process_index();
2594 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2595 retval = smpi_mpi_win_post(group,assert,win);
2596 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2602 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2605 if (win == MPI_WIN_NULL) {
2606 retval = MPI_ERR_WIN;
2607 } else if (group==MPI_GROUP_NULL){
2608 retval = MPI_ERR_GROUP;
2610 int rank = smpi_process_index();
2611 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2612 retval = smpi_mpi_win_start(group,assert,win);
2613 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2619 int PMPI_Win_complete(MPI_Win win){
2622 if (win == MPI_WIN_NULL) {
2623 retval = MPI_ERR_WIN;
2625 int rank = smpi_process_index();
2626 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2628 retval = smpi_mpi_win_complete(win);
2630 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2636 int PMPI_Win_wait(MPI_Win win){
2639 if (win == MPI_WIN_NULL) {
2640 retval = MPI_ERR_WIN;
2642 int rank = smpi_process_index();
2643 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2645 retval = smpi_mpi_win_wait(win);
2647 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2653 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2654 void *ptr = xbt_malloc(size);
2656 return MPI_ERR_NO_MEM;
2658 *static_cast<void**>(baseptr) = ptr;
2663 int PMPI_Free_mem(void *baseptr){
2668 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2670 if (datatype == MPI_DATATYPE_NULL) {
2671 return MPI_ERR_TYPE;
2672 } else if (name == nullptr) {
2675 smpi_datatype_set_name(datatype, name);
2680 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2682 if (datatype == MPI_DATATYPE_NULL) {
2683 return MPI_ERR_TYPE;
2684 } else if (name == nullptr) {
2687 smpi_datatype_get_name(datatype, name, len);
2692 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2693 return smpi_type_f2c(datatype);
2696 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2697 return smpi_type_c2f( datatype);
2700 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2701 return smpi_group_f2c( group);
2704 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2705 return smpi_group_c2f(group);
2708 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2709 return smpi_request_f2c(request);
2712 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2713 return smpi_request_c2f(request);
2716 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2717 return smpi_win_f2c(win);
2720 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2721 return smpi_win_c2f(win);
2724 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2725 return smpi_op_f2c(op);
2728 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2729 return smpi_op_c2f(op);
2732 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2733 return smpi_comm_f2c(comm);
2736 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2737 return smpi_comm_c2f(comm);
2740 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2741 return smpi_info_f2c(info);
2744 MPI_Fint PMPI_Info_c2f(MPI_Info info){
2745 return smpi_info_c2f(info);
2748 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2749 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2752 int PMPI_Keyval_free(int* keyval) {
2753 return smpi_comm_keyval_free(keyval);
2756 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2757 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2758 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2760 else if (comm==MPI_COMM_NULL)
2761 return MPI_ERR_COMM;
2763 return smpi_comm_attr_delete(comm, keyval);
2766 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2768 static int zero = 0;
2769 static int tag_ub = 1000000;
2770 static int last_used_code = MPI_ERR_LASTCODE;
2772 if (comm==MPI_COMM_NULL){
2774 return MPI_ERR_COMM;
2782 *static_cast<int**>(attr_value) = &zero;
2784 case MPI_UNIVERSE_SIZE:
2786 *static_cast<int**>(attr_value) = &smpi_universe_size;
2788 case MPI_LASTUSEDCODE:
2790 *static_cast<int**>(attr_value) = &last_used_code;
2794 *static_cast<int**>(attr_value) = &tag_ub;
2796 case MPI_WTIME_IS_GLOBAL:
2798 *static_cast<int**>(attr_value) = &one;
2801 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
2805 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2806 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2807 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2809 else if (comm==MPI_COMM_NULL)
2810 return MPI_ERR_COMM;
2812 return smpi_comm_attr_put(comm, keyval, attr_value);
2815 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2817 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
2820 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
2822 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
2825 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
2827 return PMPI_Attr_delete(comm, comm_keyval);
2830 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
2833 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
2836 int PMPI_Comm_free_keyval(int* keyval) {
2837 return PMPI_Keyval_free(keyval);
2840 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
2842 if (type==MPI_DATATYPE_NULL)
2843 return MPI_ERR_TYPE;
2845 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
2848 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
2850 if (type==MPI_DATATYPE_NULL)
2851 return MPI_ERR_TYPE;
2853 return smpi_type_attr_put(type, type_keyval, attribute_val);
2856 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
2858 if (type==MPI_DATATYPE_NULL)
2859 return MPI_ERR_TYPE;
2861 return smpi_type_attr_delete(type, type_keyval);
2864 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
2867 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2870 int PMPI_Type_free_keyval(int* keyval) {
2871 return smpi_type_keyval_free(keyval);
2874 int PMPI_Info_create( MPI_Info *info){
2875 if (info == nullptr)
2877 *info = xbt_new(s_smpi_mpi_info_t, 1);
2878 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
2879 (*info)->refcount=1;
2883 int PMPI_Info_set( MPI_Info info, char *key, char *value){
2884 if (info == nullptr || key == nullptr || value == nullptr)
2887 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
2891 int PMPI_Info_free( MPI_Info *info){
2892 if (info == nullptr || *info==nullptr)
2894 (*info)->refcount--;
2895 if((*info)->refcount==0){
2896 xbt_dict_free(&((*info)->info_dict));
2899 *info=MPI_INFO_NULL;
2903 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
2905 if (info == nullptr || key == nullptr || valuelen <0)
2907 if (value == nullptr)
2908 return MPI_ERR_INFO_VALUE;
2909 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
2911 memset(value, 0, valuelen);
2912 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
2918 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
2919 if (info == nullptr || newinfo==nullptr)
2921 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
2922 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
2923 (*newinfo)->refcount=1;
2924 xbt_dict_cursor_t cursor = nullptr;
2927 xbt_dict_foreach(info->info_dict,cursor,key,data){
2928 xbt_dict_set((*newinfo)->info_dict, key, xbt_strdup(static_cast<char*>(data)), nullptr);
2933 int PMPI_Info_delete(MPI_Info info, char *key){
2934 if (info == nullptr || key==nullptr)
2937 xbt_dict_remove(info->info_dict, key);
2940 return MPI_ERR_INFO_NOKEY;
2945 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
2946 if (info == nullptr || nkeys==nullptr)
2948 *nkeys=xbt_dict_size(info->info_dict);
2952 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
2953 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
2956 xbt_dict_cursor_t cursor = nullptr;
2960 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
2962 strncpy(key,keyn,strlen(keyn)+1);
2963 xbt_dict_cursor_free(&cursor);
2971 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
2973 if (info == nullptr || key == nullptr || valuelen==nullptr)
2975 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
2977 *valuelen=strlen(tmpvalue);
2983 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2984 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
2986 if(!is_datatype_valid(type))
2987 return MPI_ERR_TYPE;
2988 if(comm==MPI_COMM_NULL)
2989 return MPI_ERR_COMM;
2990 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
2993 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2994 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
2996 if(!is_datatype_valid(type))
2997 return MPI_ERR_TYPE;
2998 if(comm==MPI_COMM_NULL)
2999 return MPI_ERR_COMM;
3000 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3003 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3006 if(!is_datatype_valid(datatype))
3007 return MPI_ERR_TYPE;
3008 if(comm==MPI_COMM_NULL)
3009 return MPI_ERR_COMM;
3011 *size=incount*smpi_datatype_size(datatype);