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>
10 #include "smpi_mpi_dt_private.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi)");
14 //this function need to be here because of the calls to smpi_bench
15 void TRACE_smpi_set_category(const char *category)
17 //need to end bench otherwise categories for execution tasks are wrong
19 TRACE_internal_smpi_set_category (category);
20 //begin bench after changing process's category
24 /* PMPI User level calls */
25 extern "C" { // Obviously, the C MPI interface should use the C linkage
27 int PMPI_Init(int *argc, char ***argv)
29 // PMPI_Init is call only one time by only by SMPI process
31 MPI_Initialized(&already_init);
32 if(already_init == 0){
33 smpi_process_init(argc, argv);
34 smpi_process_mark_as_initialized();
35 int rank = smpi_process_index();
36 TRACE_smpi_init(rank);
37 TRACE_smpi_computing_init(rank);
38 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
39 extra->type = TRACING_INIT;
40 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
41 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
53 int rank = smpi_process_index();
54 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
55 extra->type = TRACING_FINALIZE;
56 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
58 smpi_process_finalize();
60 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
61 TRACE_smpi_finalize(smpi_process_index());
62 smpi_process_destroy();
66 int PMPI_Finalized(int* flag)
68 *flag=smpi_process_finalized();
72 int PMPI_Get_version (int *version,int *subversion){
73 *version = MPI_VERSION;
74 *subversion= MPI_SUBVERSION;
78 int PMPI_Get_library_version (char *version,int *len){
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)
97 if (provided == nullptr) {
100 *provided = MPI_THREAD_SINGLE;
105 int PMPI_Is_thread_main(int *flag)
107 if (flag == nullptr) {
110 *flag = smpi_process_index() == 0;
115 int PMPI_Abort(MPI_Comm comm, int errorcode)
118 smpi_process_destroy();
119 // FIXME: should kill all processes in comm instead
120 simcall_process_kill(SIMIX_process_self());
126 return smpi_mpi_wtime();
129 extern double sg_maxmin_precision;
132 return sg_maxmin_precision;
135 int PMPI_Address(void *location, MPI_Aint * address)
137 if (address==nullptr) {
140 *address = reinterpret_cast<MPI_Aint>(location);
145 int PMPI_Get_address(void *location, MPI_Aint * address)
147 return PMPI_Address(location, address);
150 int PMPI_Type_free(MPI_Datatype * datatype)
152 /* Free a predefined datatype is an error according to the standard, and should be checked for */
153 if (*datatype == MPI_DATATYPE_NULL) {
156 smpi_datatype_unuse(*datatype);
161 int PMPI_Type_size(MPI_Datatype datatype, int *size)
163 if (datatype == MPI_DATATYPE_NULL) {
165 } else if (size == nullptr) {
168 *size = static_cast<int>(smpi_datatype_size(datatype));
173 int PMPI_Type_size_x(MPI_Datatype datatype, MPI_Count *size)
175 if (datatype == MPI_DATATYPE_NULL) {
177 } else if (size == nullptr) {
180 *size = static_cast<MPI_Count>(smpi_datatype_size(datatype));
185 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
187 if (datatype == MPI_DATATYPE_NULL) {
189 } else if (lb == nullptr || extent == nullptr) {
192 return smpi_datatype_extent(datatype, lb, extent);
196 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
198 return PMPI_Type_get_extent(datatype, lb, extent);
201 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
203 if (datatype == MPI_DATATYPE_NULL) {
205 } else if (extent == nullptr) {
208 *extent = smpi_datatype_get_extent(datatype);
213 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
215 if (datatype == MPI_DATATYPE_NULL) {
217 } else if (disp == nullptr) {
220 *disp = smpi_datatype_lb(datatype);
225 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
227 if (datatype == MPI_DATATYPE_NULL) {
229 } else if (disp == nullptr) {
232 *disp = smpi_datatype_ub(datatype);
237 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
238 if (datatype == MPI_DATATYPE_NULL) {
241 return smpi_datatype_dup(datatype, newtype);
245 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
247 if (function == nullptr || op == nullptr) {
250 *op = smpi_op_new(function, (commute!=0));
255 int PMPI_Op_free(MPI_Op * op)
259 } else if (*op == MPI_OP_NULL) {
262 smpi_op_destroy(*op);
268 int PMPI_Group_free(MPI_Group * group)
270 if (group == nullptr) {
274 *group = MPI_GROUP_NULL;
279 int PMPI_Group_size(MPI_Group group, int *size)
281 if (group == MPI_GROUP_NULL) {
282 return MPI_ERR_GROUP;
283 } else if (size == nullptr) {
286 *size = group->size();
291 int PMPI_Group_rank(MPI_Group group, int *rank)
293 if (group == MPI_GROUP_NULL) {
294 return MPI_ERR_GROUP;
295 } else if (rank == nullptr) {
298 *rank = group->rank(smpi_process_index());
303 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
305 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
306 return MPI_ERR_GROUP;
308 for (int i = 0; i < n; i++) {
309 if(ranks1[i]==MPI_PROC_NULL){
310 ranks2[i]=MPI_PROC_NULL;
312 int index = group1->index(ranks1[i]);
313 ranks2[i] = group2->rank(index);
320 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
322 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
323 return MPI_ERR_GROUP;
324 } else if (result == nullptr) {
327 *result = group1->compare(group2);
332 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
335 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
336 return MPI_ERR_GROUP;
337 } else if (newgroup == nullptr) {
340 return group1->group_union(group2, newgroup);
344 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
347 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
348 return MPI_ERR_GROUP;
349 } else if (newgroup == nullptr) {
352 return group1->intersection(group2,newgroup);
356 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
358 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
359 return MPI_ERR_GROUP;
360 } else if (newgroup == nullptr) {
363 return group1->difference(group2,newgroup);
367 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
369 if (group == MPI_GROUP_NULL) {
370 return MPI_ERR_GROUP;
371 } else if (newgroup == nullptr) {
374 return group->incl(n, ranks, newgroup);
378 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
380 if (group == MPI_GROUP_NULL) {
381 return MPI_ERR_GROUP;
382 } else if (newgroup == nullptr) {
387 if (group != MPI_COMM_WORLD->group()
388 && group != MPI_COMM_SELF->group() && group != MPI_GROUP_EMPTY)
391 } else if (n == group->size()) {
392 *newgroup = MPI_GROUP_EMPTY;
395 return group->excl(n,ranks,newgroup);
400 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
402 if (group == MPI_GROUP_NULL) {
403 return MPI_ERR_GROUP;
404 } else if (newgroup == nullptr) {
408 *newgroup = MPI_GROUP_EMPTY;
411 return group->range_incl(n,ranges,newgroup);
416 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
418 if (group == MPI_GROUP_NULL) {
419 return MPI_ERR_GROUP;
420 } else if (newgroup == nullptr) {
425 if (group != MPI_COMM_WORLD->group() && group != MPI_COMM_SELF->group() &&
426 group != MPI_GROUP_EMPTY)
430 return group->range_excl(n,ranges,newgroup);
435 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
437 if (comm == MPI_COMM_NULL) {
439 } else if (rank == nullptr) {
442 *rank = comm->rank();
447 int PMPI_Comm_size(MPI_Comm comm, int *size)
449 if (comm == MPI_COMM_NULL) {
451 } else if (size == nullptr) {
454 *size = comm->size();
459 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
461 if (comm == MPI_COMM_NULL) {
463 } else if (name == nullptr || len == nullptr) {
466 comm->get_name(name, len);
471 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
473 if (comm == MPI_COMM_NULL) {
475 } else if (group == nullptr) {
478 *group = comm->group();
479 if (*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
485 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
487 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
489 } else if (result == nullptr) {
492 if (comm1 == comm2) { /* Same communicators means same groups */
495 *result = comm1->group()->compare(comm2->group());
496 if (*result == MPI_IDENT) {
497 *result = MPI_CONGRUENT;
504 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
506 if (comm == MPI_COMM_NULL) {
508 } else if (newcomm == nullptr) {
511 return comm->dup(newcomm);
515 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
517 if (comm == MPI_COMM_NULL) {
519 } else if (group == MPI_GROUP_NULL) {
520 return MPI_ERR_GROUP;
521 } else if (newcomm == nullptr) {
523 } else if(group->rank(smpi_process_index())==MPI_UNDEFINED){
524 *newcomm= MPI_COMM_NULL;
528 *newcomm = new simgrid::smpi::Comm(group, nullptr);
533 int PMPI_Comm_free(MPI_Comm * comm)
535 if (comm == nullptr) {
537 } else if (*comm == MPI_COMM_NULL) {
541 *comm = MPI_COMM_NULL;
546 int PMPI_Comm_disconnect(MPI_Comm * comm)
548 /* TODO: wait until all communication in comm are done */
549 if (comm == nullptr) {
551 } else if (*comm == MPI_COMM_NULL) {
555 *comm = MPI_COMM_NULL;
560 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
565 if (comm_out == nullptr) {
566 retval = MPI_ERR_ARG;
567 } else if (comm == MPI_COMM_NULL) {
568 retval = MPI_ERR_COMM;
570 *comm_out = comm->split(color, key);
571 retval = MPI_SUCCESS;
578 int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out)
583 if (comm_out == nullptr) {
584 retval = MPI_ERR_ARG;
585 } else if (comm == MPI_COMM_NULL) {
586 retval = MPI_ERR_COMM;
588 retval = MPI_Comm_create(comm, group, comm_out);
595 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
600 if (request == nullptr) {
601 retval = MPI_ERR_ARG;
602 } else if (comm == MPI_COMM_NULL) {
603 retval = MPI_ERR_COMM;
604 } else if (!is_datatype_valid(datatype)) {
605 retval = MPI_ERR_TYPE;
606 } else if (dst == MPI_PROC_NULL) {
607 retval = MPI_SUCCESS;
609 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
610 retval = MPI_SUCCESS;
613 if (retval != MPI_SUCCESS && request != nullptr)
614 *request = MPI_REQUEST_NULL;
618 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
623 if (request == nullptr) {
624 retval = MPI_ERR_ARG;
625 } else if (comm == MPI_COMM_NULL) {
626 retval = MPI_ERR_COMM;
627 } else if (!is_datatype_valid(datatype)) {
628 retval = MPI_ERR_TYPE;
629 } else if (src == MPI_PROC_NULL) {
630 retval = MPI_SUCCESS;
632 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
633 retval = MPI_SUCCESS;
636 if (retval != MPI_SUCCESS && request != nullptr)
637 *request = MPI_REQUEST_NULL;
641 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
646 if (request == nullptr) {
647 retval = MPI_ERR_ARG;
648 } else if (comm == MPI_COMM_NULL) {
649 retval = MPI_ERR_COMM;
650 } else if (!is_datatype_valid(datatype)) {
651 retval = MPI_ERR_TYPE;
652 } else if (dst == MPI_PROC_NULL) {
653 retval = MPI_SUCCESS;
655 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
656 retval = MPI_SUCCESS;
659 if (retval != MPI_SUCCESS && request != nullptr)
660 *request = MPI_REQUEST_NULL;
664 int PMPI_Start(MPI_Request * request)
669 if (request == nullptr || *request == MPI_REQUEST_NULL) {
670 retval = MPI_ERR_REQUEST;
672 smpi_mpi_start(*request);
673 retval = MPI_SUCCESS;
679 int PMPI_Startall(int count, MPI_Request * requests)
683 if (requests == nullptr) {
684 retval = MPI_ERR_ARG;
686 retval = MPI_SUCCESS;
687 for (int i = 0; i < count; i++) {
688 if(requests[i] == MPI_REQUEST_NULL) {
689 retval = MPI_ERR_REQUEST;
692 if(retval != MPI_ERR_REQUEST) {
693 smpi_mpi_startall(count, requests);
700 int PMPI_Request_free(MPI_Request * request)
705 if (*request == MPI_REQUEST_NULL) {
706 retval = MPI_ERR_ARG;
708 smpi_mpi_request_free(request);
709 retval = MPI_SUCCESS;
715 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
721 if (request == nullptr) {
722 retval = MPI_ERR_ARG;
723 } else if (comm == MPI_COMM_NULL) {
724 retval = MPI_ERR_COMM;
725 } else if (src == MPI_PROC_NULL) {
726 *request = MPI_REQUEST_NULL;
727 retval = MPI_SUCCESS;
728 } else if (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0)){
729 retval = MPI_ERR_RANK;
730 } else if ((count < 0) || (buf==nullptr && count > 0)) {
731 retval = MPI_ERR_COUNT;
732 } else if (!is_datatype_valid(datatype)) {
733 retval = MPI_ERR_TYPE;
734 } else if(tag<0 && tag != MPI_ANY_TAG){
735 retval = MPI_ERR_TAG;
738 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
739 int src_traced = comm->group()->index(src);
741 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
742 extra->type = TRACING_IRECV;
743 extra->src = src_traced;
746 extra->datatype1 = encode_datatype(datatype, &known);
747 int dt_size_send = 1;
749 dt_size_send = smpi_datatype_size(datatype);
750 extra->send_size = count*dt_size_send;
751 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
753 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
754 retval = MPI_SUCCESS;
756 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
757 (*request)->recv = 1;
761 if (retval != MPI_SUCCESS && request != nullptr)
762 *request = MPI_REQUEST_NULL;
767 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
772 if (request == nullptr) {
773 retval = MPI_ERR_ARG;
774 } else if (comm == MPI_COMM_NULL) {
775 retval = MPI_ERR_COMM;
776 } else if (dst == MPI_PROC_NULL) {
777 *request = MPI_REQUEST_NULL;
778 retval = MPI_SUCCESS;
779 } else if (dst >= comm->group()->size() || dst <0){
780 retval = MPI_ERR_RANK;
781 } else if ((count < 0) || (buf==nullptr && count > 0)) {
782 retval = MPI_ERR_COUNT;
783 } else if (!is_datatype_valid(datatype)) {
784 retval = MPI_ERR_TYPE;
785 } else if(tag<0 && tag != MPI_ANY_TAG){
786 retval = MPI_ERR_TAG;
788 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
789 int dst_traced = comm->group()->index(dst);
790 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
791 extra->type = TRACING_ISEND;
793 extra->dst = dst_traced;
795 extra->datatype1 = encode_datatype(datatype, &known);
796 int dt_size_send = 1;
798 dt_size_send = smpi_datatype_size(datatype);
799 extra->send_size = count*dt_size_send;
800 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
801 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
803 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
804 retval = MPI_SUCCESS;
806 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
807 (*request)->send = 1;
811 if (retval != MPI_SUCCESS && request!=nullptr)
812 *request = MPI_REQUEST_NULL;
816 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
821 if (request == nullptr) {
822 retval = MPI_ERR_ARG;
823 } else if (comm == MPI_COMM_NULL) {
824 retval = MPI_ERR_COMM;
825 } else if (dst == MPI_PROC_NULL) {
826 *request = MPI_REQUEST_NULL;
827 retval = MPI_SUCCESS;
828 } else if (dst >= comm->group()->size() || dst <0){
829 retval = MPI_ERR_RANK;
830 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
831 retval = MPI_ERR_COUNT;
832 } else if (!is_datatype_valid(datatype)) {
833 retval = MPI_ERR_TYPE;
834 } else if(tag<0 && tag != MPI_ANY_TAG){
835 retval = MPI_ERR_TAG;
837 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
838 int dst_traced = comm->group()->index(dst);
839 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
840 extra->type = TRACING_ISSEND;
842 extra->dst = dst_traced;
844 extra->datatype1 = encode_datatype(datatype, &known);
845 int dt_size_send = 1;
847 dt_size_send = smpi_datatype_size(datatype);
848 extra->send_size = count*dt_size_send;
849 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
850 TRACE_smpi_send(rank, rank, dst_traced, tag, count*smpi_datatype_size(datatype));
852 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
853 retval = MPI_SUCCESS;
855 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
856 (*request)->send = 1;
860 if (retval != MPI_SUCCESS && request!=nullptr)
861 *request = MPI_REQUEST_NULL;
865 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
870 if (comm == MPI_COMM_NULL) {
871 retval = MPI_ERR_COMM;
872 } else if (src == MPI_PROC_NULL) {
873 smpi_empty_status(status);
874 status->MPI_SOURCE = MPI_PROC_NULL;
875 retval = MPI_SUCCESS;
876 } else if (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0)){
877 retval = MPI_ERR_RANK;
878 } else if ((count < 0) || (buf==nullptr && count > 0)) {
879 retval = MPI_ERR_COUNT;
880 } else if (!is_datatype_valid(datatype)) {
881 retval = MPI_ERR_TYPE;
882 } else if(tag<0 && tag != MPI_ANY_TAG){
883 retval = MPI_ERR_TAG;
885 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
886 int src_traced = comm->group()->index(src);
887 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
888 extra->type = TRACING_RECV;
889 extra->src = src_traced;
892 extra->datatype1 = encode_datatype(datatype, &known);
893 int dt_size_send = 1;
895 dt_size_send = smpi_datatype_size(datatype);
896 extra->send_size = count * dt_size_send;
897 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
899 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
900 retval = MPI_SUCCESS;
902 // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
903 if (status != MPI_STATUS_IGNORE) {
904 src_traced = comm->group()->index(status->MPI_SOURCE);
905 if (!TRACE_smpi_view_internals()) {
906 TRACE_smpi_recv(rank, src_traced, rank, tag);
909 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
916 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
922 if (comm == MPI_COMM_NULL) {
923 retval = MPI_ERR_COMM;
924 } else if (dst == MPI_PROC_NULL) {
925 retval = MPI_SUCCESS;
926 } else if (dst >= comm->group()->size() || dst <0){
927 retval = MPI_ERR_RANK;
928 } else if ((count < 0) || (buf == nullptr && count > 0)) {
929 retval = MPI_ERR_COUNT;
930 } else if (!is_datatype_valid(datatype)) {
931 retval = MPI_ERR_TYPE;
932 } else if(tag < 0 && tag != MPI_ANY_TAG){
933 retval = MPI_ERR_TAG;
935 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
936 int dst_traced = comm->group()->index(dst);
937 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
938 extra->type = TRACING_SEND;
940 extra->dst = dst_traced;
942 extra->datatype1 = encode_datatype(datatype, &known);
943 int dt_size_send = 1;
945 dt_size_send = smpi_datatype_size(datatype);
947 extra->send_size = count*dt_size_send;
948 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
949 if (!TRACE_smpi_view_internals()) {
950 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
953 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
954 retval = MPI_SUCCESS;
956 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
963 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
968 if (comm == MPI_COMM_NULL) {
969 retval = MPI_ERR_COMM;
970 } else if (dst == MPI_PROC_NULL) {
971 retval = MPI_SUCCESS;
972 } else if (dst >= comm->group()->size() || dst <0){
973 retval = MPI_ERR_RANK;
974 } else if ((count < 0) || (buf==nullptr && count > 0)) {
975 retval = MPI_ERR_COUNT;
976 } else if (!is_datatype_valid(datatype)){
977 retval = MPI_ERR_TYPE;
978 } else if(tag<0 && tag != MPI_ANY_TAG){
979 retval = MPI_ERR_TAG;
981 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
982 int dst_traced = comm->group()->index(dst);
983 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
984 extra->type = TRACING_SSEND;
986 extra->dst = dst_traced;
988 extra->datatype1 = encode_datatype(datatype, &known);
989 int dt_size_send = 1;
991 dt_size_send = smpi_datatype_size(datatype);
993 extra->send_size = count*dt_size_send;
994 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
995 TRACE_smpi_send(rank, rank, dst_traced, tag,count*smpi_datatype_size(datatype));
997 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
998 retval = MPI_SUCCESS;
1000 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1007 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1008 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1014 if (comm == MPI_COMM_NULL) {
1015 retval = MPI_ERR_COMM;
1016 } else if (!is_datatype_valid(sendtype) || !is_datatype_valid(recvtype)) {
1017 retval = MPI_ERR_TYPE;
1018 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1019 smpi_empty_status(status);
1020 status->MPI_SOURCE = MPI_PROC_NULL;
1021 retval = MPI_SUCCESS;
1022 }else if (dst >= comm->group()->size() || dst <0 ||
1023 (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0))){
1024 retval = MPI_ERR_RANK;
1025 } else if ((sendcount < 0 || recvcount<0) ||
1026 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1027 retval = MPI_ERR_COUNT;
1028 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1029 retval = MPI_ERR_TAG;
1032 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1033 int dst_traced = comm->group()->index(dst);
1034 int src_traced = comm->group()->index(src);
1035 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1036 extra->type = TRACING_SENDRECV;
1037 extra->src = src_traced;
1038 extra->dst = dst_traced;
1040 extra->datatype1 = encode_datatype(sendtype, &known);
1041 int dt_size_send = 1;
1043 dt_size_send = smpi_datatype_size(sendtype);
1044 extra->send_size = sendcount*dt_size_send;
1045 extra->datatype2 = encode_datatype(recvtype, &known);
1046 int dt_size_recv = 1;
1048 dt_size_recv = smpi_datatype_size(recvtype);
1049 extra->recv_size = recvcount*dt_size_recv;
1051 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1052 TRACE_smpi_send(rank, rank, dst_traced, sendtag,sendcount*smpi_datatype_size(sendtype));
1054 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm,
1056 retval = MPI_SUCCESS;
1058 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1059 TRACE_smpi_recv(rank, src_traced, rank, recvtag);
1066 int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1067 MPI_Comm comm, MPI_Status* status)
1070 if (!is_datatype_valid(datatype)) {
1071 return MPI_ERR_TYPE;
1072 } else if (count < 0) {
1073 return MPI_ERR_COUNT;
1075 int size = smpi_datatype_get_extent(datatype) * count;
1076 void* recvbuf = xbt_new0(char, size);
1077 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1078 if(retval==MPI_SUCCESS){
1079 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1087 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1091 if (request == nullptr || flag == nullptr) {
1092 retval = MPI_ERR_ARG;
1093 } else if (*request == MPI_REQUEST_NULL) {
1095 smpi_empty_status(status);
1096 retval = MPI_SUCCESS;
1098 int rank = ((*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1100 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1101 extra->type = TRACING_TEST;
1102 TRACE_smpi_testing_in(rank, extra);
1104 *flag = smpi_mpi_test(request, status);
1106 TRACE_smpi_testing_out(rank);
1107 retval = MPI_SUCCESS;
1113 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1118 if (index == nullptr || flag == nullptr) {
1119 retval = MPI_ERR_ARG;
1121 *flag = smpi_mpi_testany(count, requests, index, status);
1122 retval = MPI_SUCCESS;
1128 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1133 if (flag == nullptr) {
1134 retval = MPI_ERR_ARG;
1136 *flag = smpi_mpi_testall(count, requests, statuses);
1137 retval = MPI_SUCCESS;
1143 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1147 if (status == nullptr) {
1148 retval = MPI_ERR_ARG;
1149 } else if (comm == MPI_COMM_NULL) {
1150 retval = MPI_ERR_COMM;
1151 } else if (source == MPI_PROC_NULL) {
1152 smpi_empty_status(status);
1153 status->MPI_SOURCE = MPI_PROC_NULL;
1154 retval = MPI_SUCCESS;
1156 smpi_mpi_probe(source, tag, comm, status);
1157 retval = MPI_SUCCESS;
1163 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1167 if ((flag == nullptr) || (status == nullptr)) {
1168 retval = MPI_ERR_ARG;
1169 } else if (comm == MPI_COMM_NULL) {
1170 retval = MPI_ERR_COMM;
1171 } else if (source == MPI_PROC_NULL) {
1173 smpi_empty_status(status);
1174 status->MPI_SOURCE = MPI_PROC_NULL;
1175 retval = MPI_SUCCESS;
1177 smpi_mpi_iprobe(source, tag, comm, flag, status);
1178 retval = MPI_SUCCESS;
1184 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1190 smpi_empty_status(status);
1192 if (request == nullptr) {
1193 retval = MPI_ERR_ARG;
1194 } else if (*request == MPI_REQUEST_NULL) {
1195 retval = MPI_SUCCESS;
1198 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1200 int src_traced = (*request)->src;
1201 int dst_traced = (*request)->dst;
1202 int tag_traced= (*request)->tag;
1203 MPI_Comm comm = (*request)->comm;
1204 int is_wait_for_receive = (*request)->recv;
1205 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1206 extra->type = TRACING_WAIT;
1207 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1209 smpi_mpi_wait(request, status);
1210 retval = MPI_SUCCESS;
1212 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1213 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1214 if (is_wait_for_receive) {
1215 if(src_traced==MPI_ANY_SOURCE)
1216 src_traced = (status!=MPI_STATUS_IGNORE) ?
1217 comm->group()->rank(status->MPI_SOURCE) :
1219 TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
1227 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1229 if (index == nullptr)
1233 //save requests information for tracing
1241 savedvalstype* savedvals=nullptr;
1243 savedvals = xbt_new0(savedvalstype, count);
1245 for (int i = 0; i < count; i++) {
1246 MPI_Request req = requests[i]; //already received requests are no longer valid
1248 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, req->comm};
1251 int rank_traced = smpi_process_index();
1252 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1253 extra->type = TRACING_WAITANY;
1254 extra->send_size=count;
1255 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1257 *index = smpi_mpi_waitany(count, requests, status);
1259 if(*index!=MPI_UNDEFINED){
1260 int src_traced = savedvals[*index].src;
1261 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1262 int dst_traced = savedvals[*index].dst;
1263 int is_wait_for_receive = savedvals[*index].recv;
1264 if (is_wait_for_receive) {
1265 if(savedvals[*index].src==MPI_ANY_SOURCE)
1266 src_traced = (status != MPI_STATUSES_IGNORE)
1267 ? savedvals[*index].comm->group()->rank(status->MPI_SOURCE)
1268 : savedvals[*index].src;
1269 TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
1271 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1273 xbt_free(savedvals);
1279 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1282 //save information from requests
1291 savedvalstype* savedvals=xbt_new0(savedvalstype, count);
1293 for (int i = 0; i < count; i++) {
1294 MPI_Request req = requests[i];
1295 if(req!=MPI_REQUEST_NULL){
1296 savedvals[i]=(savedvalstype){req->src, req->dst, req->recv, req->tag, 1, req->comm};
1298 savedvals[i].valid=0;
1301 int rank_traced = smpi_process_index();
1302 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1303 extra->type = TRACING_WAITALL;
1304 extra->send_size=count;
1305 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1307 int retval = smpi_mpi_waitall(count, requests, status);
1309 for (int i = 0; i < count; i++) {
1310 if(savedvals[i].valid){
1311 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1312 int src_traced = savedvals[i].src;
1313 int dst_traced = savedvals[i].dst;
1314 int is_wait_for_receive = savedvals[i].recv;
1315 if (is_wait_for_receive) {
1316 if(src_traced==MPI_ANY_SOURCE)
1317 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1318 savedvals[i].comm->group()->rank(status[i].MPI_SOURCE) : savedvals[i].src;
1319 TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
1323 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1324 xbt_free(savedvals);
1330 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1335 if (outcount == nullptr) {
1336 retval = MPI_ERR_ARG;
1338 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1339 retval = MPI_SUCCESS;
1345 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1350 if (outcount == nullptr) {
1351 retval = MPI_ERR_ARG;
1353 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1354 retval = MPI_SUCCESS;
1361 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1367 if (comm == MPI_COMM_NULL) {
1368 retval = MPI_ERR_COMM;
1369 } else if (!is_datatype_valid(datatype)) {
1370 retval = MPI_ERR_ARG;
1372 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1373 int root_traced = comm->group()->index(root);
1375 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1376 extra->type = TRACING_BCAST;
1377 extra->root = root_traced;
1379 extra->datatype1 = encode_datatype(datatype, &known);
1380 int dt_size_send = 1;
1382 dt_size_send = smpi_datatype_size(datatype);
1383 extra->send_size = count * dt_size_send;
1384 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1385 if (comm->size() > 1)
1386 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1387 retval = MPI_SUCCESS;
1389 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1395 int PMPI_Barrier(MPI_Comm comm)
1401 if (comm == MPI_COMM_NULL) {
1402 retval = MPI_ERR_COMM;
1404 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1405 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1406 extra->type = TRACING_BARRIER;
1407 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1409 mpi_coll_barrier_fun(comm);
1410 retval = MPI_SUCCESS;
1412 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1419 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1420 int root, MPI_Comm comm)
1426 if (comm == MPI_COMM_NULL) {
1427 retval = MPI_ERR_COMM;
1428 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1429 ((comm->rank() == root) && (recvtype == MPI_DATATYPE_NULL))){
1430 retval = MPI_ERR_TYPE;
1431 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((comm->rank() == root) && (recvcount <0))){
1432 retval = MPI_ERR_COUNT;
1435 char* sendtmpbuf = static_cast<char*>(sendbuf);
1436 int sendtmpcount = sendcount;
1437 MPI_Datatype sendtmptype = sendtype;
1438 if( (comm->rank() == root) && (sendbuf == MPI_IN_PLACE )) {
1440 sendtmptype=recvtype;
1442 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1443 int root_traced = comm->group()->index(root);
1444 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1445 extra->type = TRACING_GATHER;
1446 extra->root = root_traced;
1448 extra->datatype1 = encode_datatype(sendtmptype, &known);
1449 int dt_size_send = 1;
1451 dt_size_send = smpi_datatype_size(sendtmptype);
1452 extra->send_size = sendtmpcount * dt_size_send;
1453 extra->datatype2 = encode_datatype(recvtype, &known);
1454 int dt_size_recv = 1;
1455 if ((comm->rank() == root) && known == 0)
1456 dt_size_recv = smpi_datatype_size(recvtype);
1457 extra->recv_size = recvcount * dt_size_recv;
1459 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1461 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1463 retval = MPI_SUCCESS;
1464 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1471 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1472 MPI_Datatype recvtype, int root, MPI_Comm comm)
1478 if (comm == MPI_COMM_NULL) {
1479 retval = MPI_ERR_COMM;
1480 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1481 ((comm->rank() == root) && (recvtype == MPI_DATATYPE_NULL))){
1482 retval = MPI_ERR_TYPE;
1483 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1484 retval = MPI_ERR_COUNT;
1485 } else if (recvcounts == nullptr || displs == nullptr) {
1486 retval = MPI_ERR_ARG;
1488 char* sendtmpbuf = static_cast<char*>(sendbuf);
1489 int sendtmpcount = sendcount;
1490 MPI_Datatype sendtmptype = sendtype;
1491 if( (comm->rank() == root) && (sendbuf == MPI_IN_PLACE )) {
1493 sendtmptype=recvtype;
1496 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1497 int root_traced = comm->group()->index(root);
1499 int size = comm->size();
1500 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1501 extra->type = TRACING_GATHERV;
1502 extra->num_processes = size;
1503 extra->root = root_traced;
1505 extra->datatype1 = encode_datatype(sendtmptype, &known);
1506 int dt_size_send = 1;
1508 dt_size_send = smpi_datatype_size(sendtype);
1509 extra->send_size = sendtmpcount * dt_size_send;
1510 extra->datatype2 = encode_datatype(recvtype, &known);
1511 int dt_size_recv = 1;
1513 dt_size_recv = smpi_datatype_size(recvtype);
1514 if ((comm->rank() == root)) {
1515 extra->recvcounts = xbt_new(int, size);
1516 for (i = 0; i < size; i++) // copy data to avoid bad free
1517 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
1519 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1521 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1522 retval = MPI_SUCCESS;
1523 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1530 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1531 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1537 if (comm == MPI_COMM_NULL) {
1538 retval = MPI_ERR_COMM;
1539 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1540 (recvtype == MPI_DATATYPE_NULL)){
1541 retval = MPI_ERR_TYPE;
1542 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1544 retval = MPI_ERR_COUNT;
1546 if(sendbuf == MPI_IN_PLACE) {
1547 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*comm->rank();
1548 sendcount=recvcount;
1551 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1552 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1553 extra->type = TRACING_ALLGATHER;
1555 extra->datatype1 = encode_datatype(sendtype, &known);
1556 int dt_size_send = 1;
1558 dt_size_send = smpi_datatype_size(sendtype);
1559 extra->send_size = sendcount * dt_size_send;
1560 extra->datatype2 = encode_datatype(recvtype, &known);
1561 int dt_size_recv = 1;
1563 dt_size_recv = smpi_datatype_size(recvtype);
1564 extra->recv_size = recvcount * dt_size_recv;
1566 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1568 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1569 retval = MPI_SUCCESS;
1570 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1576 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1577 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1583 if (comm == MPI_COMM_NULL) {
1584 retval = MPI_ERR_COMM;
1585 } else if (((sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) || (recvtype == MPI_DATATYPE_NULL)) {
1586 retval = MPI_ERR_TYPE;
1587 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1588 retval = MPI_ERR_COUNT;
1589 } else if (recvcounts == nullptr || displs == nullptr) {
1590 retval = MPI_ERR_ARG;
1593 if(sendbuf == MPI_IN_PLACE) {
1594 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[comm->rank()];
1595 sendcount=recvcounts[comm->rank()];
1598 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1600 int size = comm->size();
1601 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1602 extra->type = TRACING_ALLGATHERV;
1603 extra->num_processes = size;
1605 extra->datatype1 = encode_datatype(sendtype, &known);
1606 int dt_size_send = 1;
1608 dt_size_send = smpi_datatype_size(sendtype);
1609 extra->send_size = sendcount * dt_size_send;
1610 extra->datatype2 = encode_datatype(recvtype, &known);
1611 int dt_size_recv = 1;
1613 dt_size_recv = smpi_datatype_size(recvtype);
1614 extra->recvcounts = xbt_new(int, size);
1615 for (i = 0; i < size; i++) // copy data to avoid bad free
1616 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
1618 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1620 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1621 retval = MPI_SUCCESS;
1622 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1629 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1630 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1636 if (comm == MPI_COMM_NULL) {
1637 retval = MPI_ERR_COMM;
1638 } else if (((comm->rank() == root) && (!is_datatype_valid(sendtype))) ||
1639 ((recvbuf != MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))) {
1640 retval = MPI_ERR_TYPE;
1641 } else if ((sendbuf == recvbuf) ||
1642 ((comm->rank()==root) && sendcount>0 && (sendbuf == nullptr))){
1643 retval = MPI_ERR_BUFFER;
1646 if (recvbuf == MPI_IN_PLACE) {
1647 recvtype = sendtype;
1648 recvcount = sendcount;
1650 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1651 int root_traced = comm->group()->index(root);
1652 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1653 extra->type = TRACING_SCATTER;
1654 extra->root = root_traced;
1656 extra->datatype1 = encode_datatype(sendtype, &known);
1657 int dt_size_send = 1;
1658 if ((comm->rank() == root) && known == 0)
1659 dt_size_send = smpi_datatype_size(sendtype);
1660 extra->send_size = sendcount * dt_size_send;
1661 extra->datatype2 = encode_datatype(recvtype, &known);
1662 int dt_size_recv = 1;
1664 dt_size_recv = smpi_datatype_size(recvtype);
1665 extra->recv_size = recvcount * dt_size_recv;
1666 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1668 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1669 retval = MPI_SUCCESS;
1670 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1677 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1678 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1684 if (comm == MPI_COMM_NULL) {
1685 retval = MPI_ERR_COMM;
1686 } else if (sendcounts == nullptr || displs == nullptr) {
1687 retval = MPI_ERR_ARG;
1688 } else if (((comm->rank() == root) && (sendtype == MPI_DATATYPE_NULL)) ||
1689 ((recvbuf != MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1690 retval = MPI_ERR_TYPE;
1692 if (recvbuf == MPI_IN_PLACE) {
1693 recvtype = sendtype;
1694 recvcount = sendcounts[comm->rank()];
1696 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1697 int root_traced = comm->group()->index(root);
1699 int size = comm->size();
1700 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1701 extra->type = TRACING_SCATTERV;
1702 extra->num_processes = size;
1703 extra->root = root_traced;
1705 extra->datatype1 = encode_datatype(sendtype, &known);
1706 int dt_size_send = 1;
1708 dt_size_send = smpi_datatype_size(sendtype);
1709 if ((comm->rank() == root)) {
1710 extra->sendcounts = xbt_new(int, size);
1711 for (i = 0; i < size; i++) // copy data to avoid bad free
1712 extra->sendcounts[i] = sendcounts[i] * dt_size_send;
1714 extra->datatype2 = encode_datatype(recvtype, &known);
1715 int dt_size_recv = 1;
1717 dt_size_recv = smpi_datatype_size(recvtype);
1718 extra->recv_size = recvcount * dt_size_recv;
1719 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1721 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1723 retval = MPI_SUCCESS;
1724 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1731 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1737 if (comm == MPI_COMM_NULL) {
1738 retval = MPI_ERR_COMM;
1739 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1740 retval = MPI_ERR_ARG;
1742 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1743 int root_traced = comm->group()->index(root);
1744 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1745 extra->type = TRACING_REDUCE;
1747 extra->datatype1 = encode_datatype(datatype, &known);
1748 int dt_size_send = 1;
1750 dt_size_send = smpi_datatype_size(datatype);
1751 extra->send_size = count * dt_size_send;
1752 extra->root = root_traced;
1754 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1756 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
1758 retval = MPI_SUCCESS;
1759 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1766 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
1770 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
1771 retval = MPI_ERR_ARG;
1773 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
1774 retval = MPI_SUCCESS;
1780 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1786 if (comm == MPI_COMM_NULL) {
1787 retval = MPI_ERR_COMM;
1788 } else if (!is_datatype_valid(datatype)) {
1789 retval = MPI_ERR_TYPE;
1790 } else if (op == MPI_OP_NULL) {
1791 retval = MPI_ERR_OP;
1794 char* sendtmpbuf = static_cast<char*>(sendbuf);
1795 if( sendbuf == MPI_IN_PLACE ) {
1796 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
1797 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
1799 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1800 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1801 extra->type = TRACING_ALLREDUCE;
1803 extra->datatype1 = encode_datatype(datatype, &known);
1804 int dt_size_send = 1;
1806 dt_size_send = smpi_datatype_size(datatype);
1807 extra->send_size = count * dt_size_send;
1809 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1811 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
1813 if( sendbuf == MPI_IN_PLACE )
1814 xbt_free(sendtmpbuf);
1816 retval = MPI_SUCCESS;
1817 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1824 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1830 if (comm == MPI_COMM_NULL) {
1831 retval = MPI_ERR_COMM;
1832 } else if (!is_datatype_valid(datatype)) {
1833 retval = MPI_ERR_TYPE;
1834 } else if (op == MPI_OP_NULL) {
1835 retval = MPI_ERR_OP;
1837 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1838 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1839 extra->type = TRACING_SCAN;
1841 extra->datatype1 = encode_datatype(datatype, &known);
1842 int dt_size_send = 1;
1844 dt_size_send = smpi_datatype_size(datatype);
1845 extra->send_size = count * dt_size_send;
1847 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1849 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
1851 retval = MPI_SUCCESS;
1852 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1859 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
1864 if (comm == MPI_COMM_NULL) {
1865 retval = MPI_ERR_COMM;
1866 } else if (!is_datatype_valid(datatype)) {
1867 retval = MPI_ERR_TYPE;
1868 } else if (op == MPI_OP_NULL) {
1869 retval = MPI_ERR_OP;
1871 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1872 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1873 extra->type = TRACING_EXSCAN;
1875 extra->datatype1 = encode_datatype(datatype, &known);
1876 int dt_size_send = 1;
1878 dt_size_send = smpi_datatype_size(datatype);
1879 extra->send_size = count * dt_size_send;
1880 void* sendtmpbuf = sendbuf;
1881 if (sendbuf == MPI_IN_PLACE) {
1882 sendtmpbuf = static_cast<void*>(xbt_malloc(count * smpi_datatype_size(datatype)));
1883 memcpy(sendtmpbuf, recvbuf, count * smpi_datatype_size(datatype));
1885 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1887 smpi_mpi_exscan(sendtmpbuf, recvbuf, count, datatype, op, comm);
1888 retval = MPI_SUCCESS;
1889 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1890 if (sendbuf == MPI_IN_PLACE)
1891 xbt_free(sendtmpbuf);
1898 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1903 if (comm == MPI_COMM_NULL) {
1904 retval = MPI_ERR_COMM;
1905 } else if (!is_datatype_valid(datatype)) {
1906 retval = MPI_ERR_TYPE;
1907 } else if (op == MPI_OP_NULL) {
1908 retval = MPI_ERR_OP;
1909 } else if (recvcounts == nullptr) {
1910 retval = MPI_ERR_ARG;
1912 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1914 int size = comm->size();
1915 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1916 extra->type = TRACING_REDUCE_SCATTER;
1917 extra->num_processes = size;
1919 extra->datatype1 = encode_datatype(datatype, &known);
1920 int dt_size_send = 1;
1922 dt_size_send = smpi_datatype_size(datatype);
1923 extra->send_size = 0;
1924 extra->recvcounts = xbt_new(int, size);
1926 for (i = 0; i < size; i++) { // copy data to avoid bad free
1927 extra->recvcounts[i] = recvcounts[i] * dt_size_send;
1928 totalcount += recvcounts[i];
1930 void* sendtmpbuf = sendbuf;
1931 if (sendbuf == MPI_IN_PLACE) {
1932 sendtmpbuf = static_cast<void*>(xbt_malloc(totalcount * smpi_datatype_size(datatype)));
1933 memcpy(sendtmpbuf, recvbuf, totalcount * smpi_datatype_size(datatype));
1936 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1938 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
1939 retval = MPI_SUCCESS;
1940 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1942 if (sendbuf == MPI_IN_PLACE)
1943 xbt_free(sendtmpbuf);
1950 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
1951 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1956 if (comm == MPI_COMM_NULL) {
1957 retval = MPI_ERR_COMM;
1958 } else if (!is_datatype_valid(datatype)) {
1959 retval = MPI_ERR_TYPE;
1960 } else if (op == MPI_OP_NULL) {
1961 retval = MPI_ERR_OP;
1962 } else if (recvcount < 0) {
1963 retval = MPI_ERR_ARG;
1965 int count = comm->size();
1967 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1968 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
1969 extra->type = TRACING_REDUCE_SCATTER;
1970 extra->num_processes = count;
1972 extra->datatype1 = encode_datatype(datatype, &known);
1973 int dt_size_send = 1;
1975 dt_size_send = smpi_datatype_size(datatype);
1976 extra->send_size = 0;
1977 extra->recvcounts = xbt_new(int, count);
1978 for (int i = 0; i < count; i++) // copy data to avoid bad free
1979 extra->recvcounts[i] = recvcount * dt_size_send;
1980 void* sendtmpbuf = sendbuf;
1981 if (sendbuf == MPI_IN_PLACE) {
1982 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount * count * smpi_datatype_size(datatype)));
1983 memcpy(sendtmpbuf, recvbuf, recvcount * count * smpi_datatype_size(datatype));
1986 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1988 int* recvcounts = static_cast<int*>(xbt_malloc(count * sizeof(int)));
1989 for (int i = 0; i < count; i++)
1990 recvcounts[i] = recvcount;
1991 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
1992 xbt_free(recvcounts);
1993 retval = MPI_SUCCESS;
1995 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1997 if (sendbuf == MPI_IN_PLACE)
1998 xbt_free(sendtmpbuf);
2005 int PMPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
2006 MPI_Datatype recvtype, MPI_Comm comm)
2011 if (comm == MPI_COMM_NULL) {
2012 retval = MPI_ERR_COMM;
2013 } else if ((sendbuf != MPI_IN_PLACE && sendtype == MPI_DATATYPE_NULL) || recvtype == MPI_DATATYPE_NULL) {
2014 retval = MPI_ERR_TYPE;
2016 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2017 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2018 extra->type = TRACING_ALLTOALL;
2020 void* sendtmpbuf = static_cast<char*>(sendbuf);
2021 int sendtmpcount = sendcount;
2022 MPI_Datatype sendtmptype = sendtype;
2023 if (sendbuf == MPI_IN_PLACE) {
2024 sendtmpbuf = static_cast<void*>(xbt_malloc(recvcount * comm->size() * smpi_datatype_size(recvtype)));
2025 memcpy(sendtmpbuf, recvbuf, recvcount * comm->size() * smpi_datatype_size(recvtype));
2026 sendtmpcount = recvcount;
2027 sendtmptype = recvtype;
2031 extra->datatype1 = encode_datatype(sendtmptype, &known);
2033 extra->send_size = sendtmpcount * smpi_datatype_size(sendtmptype);
2035 extra->send_size = sendtmpcount;
2036 extra->datatype2 = encode_datatype(recvtype, &known);
2038 extra->recv_size = recvcount * smpi_datatype_size(recvtype);
2040 extra->recv_size = recvcount;
2042 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2044 retval = mpi_coll_alltoall_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, comm);
2046 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2048 if (sendbuf == MPI_IN_PLACE)
2049 xbt_free(sendtmpbuf);
2056 int PMPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf,
2057 int* recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2063 if (comm == MPI_COMM_NULL) {
2064 retval = MPI_ERR_COMM;
2065 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2066 retval = MPI_ERR_TYPE;
2067 } else if ((sendbuf != MPI_IN_PLACE && (sendcounts == nullptr || senddisps == nullptr)) || recvcounts == nullptr ||
2068 recvdisps == nullptr) {
2069 retval = MPI_ERR_ARG;
2071 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2073 int size = comm->size();
2074 instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
2075 extra->type = TRACING_ALLTOALLV;
2076 extra->send_size = 0;
2077 extra->recv_size = 0;
2078 extra->recvcounts = xbt_new(int, size);
2079 extra->sendcounts = xbt_new(int, size);
2081 int dt_size_recv = 1;
2082 extra->datatype2 = encode_datatype(recvtype, &known);
2083 dt_size_recv = smpi_datatype_size(recvtype);
2085 void* sendtmpbuf = static_cast<char*>(sendbuf);
2086 int* sendtmpcounts = sendcounts;
2087 int* sendtmpdisps = senddisps;
2088 MPI_Datatype sendtmptype = sendtype;
2090 for (i = 0; i < size; i++) { // copy data to avoid bad free
2091 extra->recv_size += recvcounts[i] * dt_size_recv;
2092 extra->recvcounts[i] = recvcounts[i] * dt_size_recv;
2093 if (((recvdisps[i] + recvcounts[i]) * dt_size_recv) > maxsize)
2094 maxsize = (recvdisps[i] + recvcounts[i]) * dt_size_recv;
2097 if (sendbuf == MPI_IN_PLACE) {
2098 sendtmpbuf = static_cast<void*>(xbt_malloc(maxsize));
2099 memcpy(sendtmpbuf, recvbuf, maxsize);
2100 sendtmpcounts = static_cast<int*>(xbt_malloc(size * sizeof(int)));
2101 memcpy(sendtmpcounts, recvcounts, size * sizeof(int));
2102 sendtmpdisps = static_cast<int*>(xbt_malloc(size * sizeof(int)));
2103 memcpy(sendtmpdisps, recvdisps, size * sizeof(int));
2104 sendtmptype = recvtype;
2107 extra->datatype1 = encode_datatype(sendtmptype, &known);
2108 int dt_size_send = 1;
2109 dt_size_send = smpi_datatype_size(sendtmptype);
2111 for (i = 0; i < size; i++) { // copy data to avoid bad free
2112 extra->send_size += sendtmpcounts[i] * dt_size_send;
2113 extra->sendcounts[i] = sendtmpcounts[i] * dt_size_send;
2115 extra->num_processes = size;
2116 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
2117 retval = mpi_coll_alltoallv_fun(sendtmpbuf, sendtmpcounts, sendtmpdisps, sendtmptype, recvbuf, recvcounts,
2118 recvdisps, recvtype, comm);
2119 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2121 if (sendbuf == MPI_IN_PLACE) {
2122 xbt_free(sendtmpbuf);
2123 xbt_free(sendtmpcounts);
2124 xbt_free(sendtmpdisps);
2133 int PMPI_Get_processor_name(char *name, int *resultlen)
2135 strncpy(name, SIMIX_host_self()->cname(), strlen(SIMIX_host_self()->cname()) < MPI_MAX_PROCESSOR_NAME - 1
2136 ? strlen(SIMIX_host_self()->cname()) + 1
2137 : MPI_MAX_PROCESSOR_NAME - 1);
2138 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2143 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2145 if (status == nullptr || count == nullptr) {
2147 } else if (!is_datatype_valid(datatype)) {
2148 return MPI_ERR_TYPE;
2150 size_t size = smpi_datatype_size(datatype);
2154 } else if (status->count % size != 0) {
2155 return MPI_UNDEFINED;
2157 *count = smpi_mpi_get_count(status, datatype);
2163 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2164 if (old_type == MPI_DATATYPE_NULL) {
2165 return MPI_ERR_TYPE;
2166 } else if (count<0){
2167 return MPI_ERR_COUNT;
2169 return smpi_datatype_contiguous(count, old_type, new_type, 0);
2173 int PMPI_Type_commit(MPI_Datatype* datatype) {
2174 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2175 return MPI_ERR_TYPE;
2177 smpi_datatype_commit(datatype);
2182 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2183 if (old_type == MPI_DATATYPE_NULL) {
2184 return MPI_ERR_TYPE;
2185 } else if (count<0 || blocklen<0){
2186 return MPI_ERR_COUNT;
2188 return smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2192 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2193 if (old_type == MPI_DATATYPE_NULL) {
2194 return MPI_ERR_TYPE;
2195 } else if (count<0 || blocklen<0){
2196 return MPI_ERR_COUNT;
2198 return smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2202 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2203 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2206 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2207 if (old_type == MPI_DATATYPE_NULL) {
2208 return MPI_ERR_TYPE;
2209 } else if (count<0){
2210 return MPI_ERR_COUNT;
2212 return smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2216 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2217 if (old_type == MPI_DATATYPE_NULL) {
2218 return MPI_ERR_TYPE;
2219 } else if (count<0){
2220 return MPI_ERR_COUNT;
2222 return smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2226 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2227 MPI_Datatype* new_type)
2229 if (old_type == MPI_DATATYPE_NULL) {
2230 return MPI_ERR_TYPE;
2231 } else if (count<0){
2232 return MPI_ERR_COUNT;
2234 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count*sizeof(int)));
2235 for (int i = 0; i < count; i++)
2236 blocklens[i]=blocklength;
2237 int retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2238 xbt_free(blocklens);
2243 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
2245 if (old_type == MPI_DATATYPE_NULL) {
2246 return MPI_ERR_TYPE;
2247 } else if (count<0){
2248 return MPI_ERR_COUNT;
2250 return smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2254 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2255 MPI_Datatype* new_type) {
2256 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2259 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2260 MPI_Datatype* new_type) {
2261 if (old_type == MPI_DATATYPE_NULL) {
2262 return MPI_ERR_TYPE;
2263 } else if (count<0){
2264 return MPI_ERR_COUNT;
2266 int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int));
2267 for (int i = 0; i < count; i++)
2268 blocklens[i] = blocklength;
2269 int retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2270 xbt_free(blocklens);
2275 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2277 return MPI_ERR_COUNT;
2279 return smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2283 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2284 MPI_Datatype* new_type) {
2285 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2288 int PMPI_Error_class(int errorcode, int* errorclass) {
2289 // assume smpi uses only standard mpi error codes
2290 *errorclass=errorcode;
2294 int PMPI_Initialized(int* flag) {
2295 *flag=smpi_process_initialized();
2299 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2300 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2301 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2303 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2304 if (comm_old == MPI_COMM_NULL){
2305 return MPI_ERR_COMM;
2306 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2309 new simgrid::smpi::Cart(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 || comm->topo() == nullptr) {
2316 return MPI_ERR_TOPOLOGY;
2318 if (coords == nullptr) {
2321 simgrid::smpi::Cart* topo = static_cast<simgrid::smpi::Cart*>(comm->topo());
2322 if (topo==nullptr) {
2325 return topo->rank(coords, rank);
2328 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2329 if(comm == MPI_COMM_NULL || comm->topo() == nullptr) {
2330 return MPI_ERR_TOPOLOGY;
2332 if (source == nullptr || dest == nullptr || direction < 0 ) {
2335 simgrid::smpi::Cart* topo = static_cast<simgrid::smpi::Cart*>(comm->topo());
2336 if (topo==nullptr) {
2339 return topo->shift(direction, displ, source, dest);
2342 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2343 if(comm == MPI_COMM_NULL || comm->topo() == nullptr) {
2344 return MPI_ERR_TOPOLOGY;
2346 if (rank < 0 || rank >= comm->size()) {
2347 return MPI_ERR_RANK;
2352 if(coords == nullptr) {
2355 simgrid::smpi::Cart* topo = static_cast<simgrid::smpi::Cart*>(comm->topo());
2356 if (topo==nullptr) {
2359 return topo->coords(rank, maxdims, coords);
2362 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2363 if(comm == nullptr || comm->topo() == nullptr) {
2364 return MPI_ERR_TOPOLOGY;
2366 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2369 simgrid::smpi::Cart* topo = static_cast<simgrid::smpi::Cart*>(comm->topo());
2370 if (topo==nullptr) {
2373 return topo->get(maxdims, dims, periods, coords);
2376 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2377 if (comm == MPI_COMM_NULL || comm->topo() == nullptr) {
2378 return MPI_ERR_TOPOLOGY;
2380 if (ndims == nullptr) {
2383 simgrid::smpi::Cart* topo = static_cast<simgrid::smpi::Cart*>(comm->topo());
2384 if (topo==nullptr) {
2387 return topo->dim_get(ndims);
2390 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2391 if(dims == nullptr) {
2394 if (ndims < 1 || nnodes < 1) {
2395 return MPI_ERR_DIMS;
2397 return simgrid::smpi::Dims_create(nnodes, ndims, dims);
2400 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2401 if(comm == MPI_COMM_NULL || comm->topo() == nullptr) {
2402 return MPI_ERR_TOPOLOGY;
2404 if (comm_new == nullptr) {
2407 simgrid::smpi::Cart* topo = static_cast<simgrid::smpi::Cart*>(comm->topo());
2408 if (topo==nullptr) {
2411 simgrid::smpi::Cart* cart = topo->sub(remain_dims, comm_new);
2417 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2418 if (oldtype == MPI_DATATYPE_NULL) {
2419 return MPI_ERR_TYPE;
2421 int blocks[3] = {1, 1, 1};
2422 MPI_Aint disps[3] = {lb, 0, lb + extent};
2423 MPI_Datatype types[3] = {MPI_LB, oldtype, MPI_UB};
2425 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create(blocks, disps, 3, types);
2426 smpi_datatype_create(newtype, oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t), subtype, DT_FLAG_VECTOR);
2428 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2432 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2435 if (comm == MPI_COMM_NULL) {
2436 retval= MPI_ERR_COMM;
2437 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2438 retval= MPI_ERR_OTHER;
2440 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2441 retval = MPI_SUCCESS;
2447 int PMPI_Win_free( MPI_Win* win){
2450 if (win == nullptr || *win == MPI_WIN_NULL) {
2451 retval = MPI_ERR_WIN;
2453 retval=smpi_mpi_win_free(win);
2459 int PMPI_Win_set_name(MPI_Win win, char * name)
2461 if (win == MPI_WIN_NULL) {
2462 return MPI_ERR_TYPE;
2463 } else if (name == nullptr) {
2466 smpi_mpi_win_set_name(win, name);
2471 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2473 if (win == MPI_WIN_NULL) {
2475 } else if (name == nullptr) {
2478 smpi_mpi_win_get_name(win, name, len);
2483 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2484 if (win == MPI_WIN_NULL) {
2487 smpi_mpi_win_get_group(win, group);
2493 int PMPI_Win_fence( int assert, MPI_Win win){
2496 if (win == MPI_WIN_NULL) {
2497 retval = MPI_ERR_WIN;
2499 int rank = smpi_process_index();
2500 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2501 retval = smpi_mpi_win_fence(assert, win);
2502 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2508 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2509 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2512 if (win == MPI_WIN_NULL) {
2513 retval = MPI_ERR_WIN;
2514 } else if (target_rank == MPI_PROC_NULL) {
2515 retval = MPI_SUCCESS;
2516 } else if (target_rank <0){
2517 retval = MPI_ERR_RANK;
2518 } else if (target_disp <0){
2519 retval = MPI_ERR_ARG;
2520 } else if ((origin_count < 0 || target_count < 0) ||
2521 (origin_addr==nullptr && origin_count > 0)){
2522 retval = MPI_ERR_COUNT;
2523 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2524 retval = MPI_ERR_TYPE;
2526 int rank = smpi_process_index();
2528 smpi_mpi_win_get_group(win, &group);
2529 int src_traced = group->index(target_rank);
2530 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2532 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2533 target_datatype, win);
2535 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2541 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2542 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2545 if (win == MPI_WIN_NULL) {
2546 retval = MPI_ERR_WIN;
2547 } else if (target_rank == MPI_PROC_NULL) {
2548 retval = MPI_SUCCESS;
2549 } else if (target_rank <0){
2550 retval = MPI_ERR_RANK;
2551 } else if (target_disp <0){
2552 retval = MPI_ERR_ARG;
2553 } else if ((origin_count < 0 || target_count < 0) ||
2554 (origin_addr==nullptr && origin_count > 0)){
2555 retval = MPI_ERR_COUNT;
2556 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2557 retval = MPI_ERR_TYPE;
2559 int rank = smpi_process_index();
2561 smpi_mpi_win_get_group(win, &group);
2562 int dst_traced = group->index(target_rank);
2563 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2564 TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
2566 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2567 target_datatype, win);
2569 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2575 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2576 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2579 if (win == MPI_WIN_NULL) {
2580 retval = MPI_ERR_WIN;
2581 } else if (target_rank == MPI_PROC_NULL) {
2582 retval = MPI_SUCCESS;
2583 } else if (target_rank <0){
2584 retval = MPI_ERR_RANK;
2585 } else if (target_disp <0){
2586 retval = MPI_ERR_ARG;
2587 } else if ((origin_count < 0 || target_count < 0) ||
2588 (origin_addr==nullptr && origin_count > 0)){
2589 retval = MPI_ERR_COUNT;
2590 } else if ((!is_datatype_valid(origin_datatype)) ||
2591 (!is_datatype_valid(target_datatype))) {
2592 retval = MPI_ERR_TYPE;
2593 } else if (op == MPI_OP_NULL) {
2594 retval = MPI_ERR_OP;
2596 int rank = smpi_process_index();
2598 smpi_mpi_win_get_group(win, &group);
2599 int src_traced = group->index(target_rank);
2600 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2602 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2603 target_datatype, op, win);
2605 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2611 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2614 if (win == MPI_WIN_NULL) {
2615 retval = MPI_ERR_WIN;
2616 } else if (group==MPI_GROUP_NULL){
2617 retval = MPI_ERR_GROUP;
2619 int rank = smpi_process_index();
2620 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2621 retval = smpi_mpi_win_post(group,assert,win);
2622 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2628 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2631 if (win == MPI_WIN_NULL) {
2632 retval = MPI_ERR_WIN;
2633 } else if (group==MPI_GROUP_NULL){
2634 retval = MPI_ERR_GROUP;
2636 int rank = smpi_process_index();
2637 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2638 retval = smpi_mpi_win_start(group,assert,win);
2639 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2645 int PMPI_Win_complete(MPI_Win win){
2648 if (win == MPI_WIN_NULL) {
2649 retval = MPI_ERR_WIN;
2651 int rank = smpi_process_index();
2652 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2654 retval = smpi_mpi_win_complete(win);
2656 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2662 int PMPI_Win_wait(MPI_Win win){
2665 if (win == MPI_WIN_NULL) {
2666 retval = MPI_ERR_WIN;
2668 int rank = smpi_process_index();
2669 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2671 retval = smpi_mpi_win_wait(win);
2673 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2679 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2680 void *ptr = xbt_malloc(size);
2682 return MPI_ERR_NO_MEM;
2684 *static_cast<void**>(baseptr) = ptr;
2689 int PMPI_Free_mem(void *baseptr){
2694 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2696 if (datatype == MPI_DATATYPE_NULL) {
2697 return MPI_ERR_TYPE;
2698 } else if (name == nullptr) {
2701 smpi_datatype_set_name(datatype, name);
2706 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2708 if (datatype == MPI_DATATYPE_NULL) {
2709 return MPI_ERR_TYPE;
2710 } else if (name == nullptr) {
2713 smpi_datatype_get_name(datatype, name, len);
2718 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2719 return smpi_type_f2c(datatype);
2722 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2723 return smpi_type_c2f( datatype);
2726 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2727 return smpi_group_f2c( group);
2730 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2731 return smpi_group_c2f(group);
2734 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2735 return smpi_request_f2c(request);
2738 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2739 return smpi_request_c2f(request);
2742 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2743 return smpi_win_f2c(win);
2746 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2747 return smpi_win_c2f(win);
2750 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2751 return smpi_op_f2c(op);
2754 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2755 return smpi_op_c2f(op);
2758 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2759 return smpi_comm_f2c(comm);
2762 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2763 return smpi_comm_c2f(comm);
2766 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2767 return smpi_info_f2c(info);
2770 MPI_Fint PMPI_Info_c2f(MPI_Info info){
2771 return smpi_info_c2f(info);
2774 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2775 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2778 int PMPI_Keyval_free(int* keyval) {
2779 return smpi_comm_keyval_free(keyval);
2782 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2783 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2784 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2786 else if (comm==MPI_COMM_NULL)
2787 return MPI_ERR_COMM;
2789 return comm->attr_delete(keyval);
2792 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2794 static int zero = 0;
2795 static int tag_ub = 1000000;
2796 static int last_used_code = MPI_ERR_LASTCODE;
2798 if (comm==MPI_COMM_NULL){
2800 return MPI_ERR_COMM;
2808 *static_cast<int**>(attr_value) = &zero;
2810 case MPI_UNIVERSE_SIZE:
2812 *static_cast<int**>(attr_value) = &smpi_universe_size;
2814 case MPI_LASTUSEDCODE:
2816 *static_cast<int**>(attr_value) = &last_used_code;
2820 *static_cast<int**>(attr_value) = &tag_ub;
2822 case MPI_WTIME_IS_GLOBAL:
2824 *static_cast<int**>(attr_value) = &one;
2827 return comm->attr_get(keyval, attr_value, flag);
2831 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2832 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
2833 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
2835 else if (comm==MPI_COMM_NULL)
2836 return MPI_ERR_COMM;
2838 return comm->attr_put(keyval, attr_value);
2841 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2843 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
2846 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
2848 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
2851 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
2853 return PMPI_Attr_delete(comm, comm_keyval);
2856 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
2859 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
2862 int PMPI_Comm_free_keyval(int* keyval) {
2863 return PMPI_Keyval_free(keyval);
2866 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
2868 if (type==MPI_DATATYPE_NULL)
2869 return MPI_ERR_TYPE;
2871 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
2874 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
2876 if (type==MPI_DATATYPE_NULL)
2877 return MPI_ERR_TYPE;
2879 return smpi_type_attr_put(type, type_keyval, attribute_val);
2882 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
2884 if (type==MPI_DATATYPE_NULL)
2885 return MPI_ERR_TYPE;
2887 return smpi_type_attr_delete(type, type_keyval);
2890 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
2893 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2896 int PMPI_Type_free_keyval(int* keyval) {
2897 return smpi_type_keyval_free(keyval);
2900 int PMPI_Info_create( MPI_Info *info){
2901 if (info == nullptr)
2903 *info = xbt_new(s_smpi_mpi_info_t, 1);
2904 (*info)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
2905 (*info)->refcount=1;
2909 int PMPI_Info_set( MPI_Info info, char *key, char *value){
2910 if (info == nullptr || key == nullptr || value == nullptr)
2913 xbt_dict_set(info->info_dict, key, xbt_strdup(value), nullptr);
2917 int PMPI_Info_free( MPI_Info *info){
2918 if (info == nullptr || *info==nullptr)
2920 (*info)->refcount--;
2921 if((*info)->refcount==0){
2922 xbt_dict_free(&((*info)->info_dict));
2925 *info=MPI_INFO_NULL;
2929 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
2931 if (info == nullptr || key == nullptr || valuelen <0)
2933 if (value == nullptr)
2934 return MPI_ERR_INFO_VALUE;
2935 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
2937 memset(value, 0, valuelen);
2938 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
2944 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
2945 if (info == nullptr || newinfo==nullptr)
2947 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
2948 (*newinfo)->info_dict= xbt_dict_new_homogeneous(xbt_free_f);
2949 (*newinfo)->refcount=1;
2950 xbt_dict_cursor_t cursor = nullptr;
2953 xbt_dict_foreach(info->info_dict,cursor,key,data){
2954 xbt_dict_set((*newinfo)->info_dict, key, xbt_strdup(static_cast<char*>(data)), nullptr);
2959 int PMPI_Info_delete(MPI_Info info, char *key){
2960 if (info == nullptr || key==nullptr)
2963 xbt_dict_remove(info->info_dict, key);
2966 return MPI_ERR_INFO_NOKEY;
2971 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
2972 if (info == nullptr || nkeys==nullptr)
2974 *nkeys=xbt_dict_size(info->info_dict);
2978 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
2979 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
2982 xbt_dict_cursor_t cursor = nullptr;
2986 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
2988 strncpy(key,keyn,strlen(keyn)+1);
2989 xbt_dict_cursor_free(&cursor);
2997 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
2999 if (info == nullptr || key == nullptr || valuelen==nullptr)
3001 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3003 *valuelen=strlen(tmpvalue);
3009 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3010 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3012 if(!is_datatype_valid(type))
3013 return MPI_ERR_TYPE;
3014 if(comm==MPI_COMM_NULL)
3015 return MPI_ERR_COMM;
3016 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3019 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3020 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3022 if(!is_datatype_valid(type))
3023 return MPI_ERR_TYPE;
3024 if(comm==MPI_COMM_NULL)
3025 return MPI_ERR_COMM;
3026 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3029 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3032 if(!is_datatype_valid(datatype))
3033 return MPI_ERR_TYPE;
3034 if(comm==MPI_COMM_NULL)
3035 return MPI_ERR_COMM;
3037 *size=incount*smpi_datatype_size(datatype);