2 /* Copyright (c) 2007-2015. The SimGrid Team.
3 * All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
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 */
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__);
50 int PMPI_Finalize(void)
53 int rank = smpi_process_index();
54 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
55 extra->type = TRACING_FINALIZE;
56 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
58 smpi_process_finalize();
60 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
61 TRACE_smpi_finalize(smpi_process_index());
62 smpi_process_destroy();
66 int PMPI_Finalized(int* flag)
68 *flag=smpi_process_finalized();
72 int PMPI_Get_version (int *version,int *subversion){
73 *version = MPI_VERSION;
74 *subversion= MPI_SUBVERSION;
78 int PMPI_Get_library_version (char *version,int *len){
79 int retval = MPI_SUCCESS;
81 snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2015",
82 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR);
83 *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
88 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
90 if (provided != nullptr) {
91 *provided = MPI_THREAD_SINGLE;
93 return MPI_Init(argc, argv);
96 int PMPI_Query_thread(int *provided)
100 if (provided == nullptr) {
101 retval = MPI_ERR_ARG;
103 *provided = MPI_THREAD_SINGLE;
104 retval = MPI_SUCCESS;
109 int PMPI_Is_thread_main(int *flag)
113 if (flag == nullptr) {
114 retval = MPI_ERR_ARG;
116 *flag = smpi_process_index() == 0;
117 retval = MPI_SUCCESS;
122 int PMPI_Abort(MPI_Comm comm, int errorcode)
125 smpi_process_destroy();
126 // FIXME: should kill all processes in comm instead
127 simcall_process_kill(SIMIX_process_self());
131 double PMPI_Wtime(void)
133 return smpi_mpi_wtime();
136 extern double sg_maxmin_precision;
137 double PMPI_Wtick(void)
139 return sg_maxmin_precision;
142 int PMPI_Address(void *location, MPI_Aint * address)
146 if (address==nullptr) {
147 retval = MPI_ERR_ARG;
149 *address = reinterpret_cast<MPI_Aint>(location);
150 retval = MPI_SUCCESS;
155 int PMPI_Get_address(void *location, MPI_Aint * address)
157 return PMPI_Address(location, address);
160 int PMPI_Type_free(MPI_Datatype * datatype)
163 /* Free a predefined datatype is an error according to the standard, and should be checked for */
164 if (*datatype == MPI_DATATYPE_NULL) {
165 retval = MPI_ERR_ARG;
167 smpi_datatype_unuse(*datatype);
168 retval = MPI_SUCCESS;
173 int PMPI_Type_size(MPI_Datatype datatype, int *size)
177 if (datatype == MPI_DATATYPE_NULL) {
178 retval = MPI_ERR_TYPE;
179 } else if (size == nullptr) {
180 retval = MPI_ERR_ARG;
182 *size = static_cast<int>(smpi_datatype_size(datatype));
183 retval = MPI_SUCCESS;
188 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
192 if (datatype == MPI_DATATYPE_NULL) {
193 retval = MPI_ERR_TYPE;
194 } else if (lb == nullptr || extent == nullptr) {
195 retval = MPI_ERR_ARG;
197 retval = smpi_datatype_extent(datatype, lb, extent);
202 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
204 return PMPI_Type_get_extent(datatype, lb, extent);
207 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
211 if (datatype == MPI_DATATYPE_NULL) {
212 retval = MPI_ERR_TYPE;
213 } else if (extent == nullptr) {
214 retval = MPI_ERR_ARG;
216 *extent = smpi_datatype_get_extent(datatype);
217 retval = MPI_SUCCESS;
222 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
226 if (datatype == MPI_DATATYPE_NULL) {
227 retval = MPI_ERR_TYPE;
228 } else if (disp == nullptr) {
229 retval = MPI_ERR_ARG;
231 *disp = smpi_datatype_lb(datatype);
232 retval = MPI_SUCCESS;
237 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
241 if (datatype == MPI_DATATYPE_NULL) {
242 retval = MPI_ERR_TYPE;
243 } else if (disp == nullptr) {
244 retval = MPI_ERR_ARG;
246 *disp = smpi_datatype_ub(datatype);
247 retval = MPI_SUCCESS;
252 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
255 if (datatype == MPI_DATATYPE_NULL) {
256 retval = MPI_ERR_TYPE;
258 retval = smpi_datatype_dup(datatype, newtype);
263 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
267 if (function == nullptr || op == nullptr) {
268 retval = MPI_ERR_ARG;
270 *op = smpi_op_new(function, (commute!=0));
271 retval = MPI_SUCCESS;
276 int PMPI_Op_free(MPI_Op * op)
281 retval = MPI_ERR_ARG;
282 } else if (*op == MPI_OP_NULL) {
285 smpi_op_destroy(*op);
287 retval = MPI_SUCCESS;
292 int PMPI_Group_free(MPI_Group * group)
296 if (group == nullptr) {
297 retval = MPI_ERR_ARG;
299 smpi_group_destroy(*group);
300 *group = MPI_GROUP_NULL;
301 retval = MPI_SUCCESS;
306 int PMPI_Group_size(MPI_Group group, int *size)
310 if (group == MPI_GROUP_NULL) {
311 retval = MPI_ERR_GROUP;
312 } else if (size == nullptr) {
313 retval = MPI_ERR_ARG;
315 *size = smpi_group_size(group);
316 retval = MPI_SUCCESS;
321 int PMPI_Group_rank(MPI_Group group, int *rank)
325 if (group == MPI_GROUP_NULL) {
326 retval = MPI_ERR_GROUP;
327 } else if (rank == nullptr) {
328 retval = MPI_ERR_ARG;
330 *rank = smpi_group_rank(group, smpi_process_index());
331 retval = MPI_SUCCESS;
336 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
338 int retval, i, index;
339 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
340 retval = MPI_ERR_GROUP;
342 for (i = 0; i < n; i++) {
343 if(ranks1[i]==MPI_PROC_NULL){
344 ranks2[i]=MPI_PROC_NULL;
346 index = smpi_group_index(group1, ranks1[i]);
347 ranks2[i] = smpi_group_rank(group2, index);
350 retval = MPI_SUCCESS;
355 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
359 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
360 retval = MPI_ERR_GROUP;
361 } else if (result == nullptr) {
362 retval = MPI_ERR_ARG;
364 *result = smpi_group_compare(group1, group2);
365 retval = MPI_SUCCESS;
370 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
372 int retval, i, proc1, proc2, size, size2;
374 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
375 retval = MPI_ERR_GROUP;
376 } else if (newgroup == nullptr) {
377 retval = MPI_ERR_ARG;
379 size = smpi_group_size(group1);
380 size2 = smpi_group_size(group2);
381 for (i = 0; i < size2; i++) {
382 proc2 = smpi_group_index(group2, i);
383 proc1 = smpi_group_rank(group1, proc2);
384 if (proc1 == MPI_UNDEFINED) {
389 *newgroup = MPI_GROUP_EMPTY;
391 *newgroup = smpi_group_new(size);
392 size2 = smpi_group_size(group1);
393 for (i = 0; i < size2; i++) {
394 proc1 = smpi_group_index(group1, i);
395 smpi_group_set_mapping(*newgroup, proc1, i);
397 for (i = size2; i < size; i++) {
398 proc2 = smpi_group_index(group2, i - size2);
399 smpi_group_set_mapping(*newgroup, proc2, i);
402 retval = MPI_SUCCESS;
407 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
409 int retval, i, proc1, proc2, size;
411 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
412 retval = MPI_ERR_GROUP;
413 } else if (newgroup == nullptr) {
414 retval = MPI_ERR_ARG;
416 size = smpi_group_size(group2);
417 for (i = 0; i < size; i++) {
418 proc2 = smpi_group_index(group2, i);
419 proc1 = smpi_group_rank(group1, proc2);
420 if (proc1 == MPI_UNDEFINED) {
425 *newgroup = MPI_GROUP_EMPTY;
427 *newgroup = smpi_group_new(size);
429 for (i = 0; i < smpi_group_size(group2); i++) {
430 proc2 = smpi_group_index(group2, i);
431 proc1 = smpi_group_rank(group1, proc2);
432 if (proc1 != MPI_UNDEFINED) {
433 smpi_group_set_mapping(*newgroup, proc2, j);
438 retval = MPI_SUCCESS;
443 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
445 int retval, i, proc1, proc2, size, size2;
447 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
448 retval = MPI_ERR_GROUP;
449 } else if (newgroup == nullptr) {
450 retval = MPI_ERR_ARG;
452 size = smpi_group_size(group1);
454 for (i = 0; i < size2; i++) {
455 proc1 = smpi_group_index(group1, i);
456 proc2 = smpi_group_rank(group2, proc1);
457 if (proc2 != MPI_UNDEFINED) {
462 *newgroup = MPI_GROUP_EMPTY;
464 *newgroup = smpi_group_new(size);
465 for (i = 0; i < size2; i++) {
466 proc1 = smpi_group_index(group1, i);
467 proc2 = smpi_group_rank(group2, proc1);
468 if (proc2 == MPI_UNDEFINED) {
469 smpi_group_set_mapping(*newgroup, proc1, i);
473 retval = MPI_SUCCESS;
478 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
482 if (group == MPI_GROUP_NULL) {
483 retval = MPI_ERR_GROUP;
484 } else if (newgroup == nullptr) {
485 retval = MPI_ERR_ARG;
487 retval = smpi_group_incl(group, n, ranks, newgroup);
492 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
494 int retval, i, j, newsize, oldsize, index;
496 if (group == MPI_GROUP_NULL) {
497 retval = MPI_ERR_GROUP;
498 } else if (newgroup == nullptr) {
499 retval = MPI_ERR_ARG;
503 if(group!= smpi_comm_group(MPI_COMM_WORLD) && group != MPI_GROUP_NULL
504 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
505 smpi_group_use(group);
506 } else if (n == smpi_group_size(group)) {
507 *newgroup = MPI_GROUP_EMPTY;
509 oldsize=smpi_group_size(group);
510 newsize = oldsize - n;
511 *newgroup = smpi_group_new(newsize);
513 int* to_exclude=xbt_new0(int, smpi_group_size(group));
514 for(i=0; i<oldsize; i++)
517 to_exclude[ranks[i]]=1;
520 for(i=0; i<oldsize; i++){
521 if(to_exclude[i]==0){
522 index = smpi_group_index(group, i);
523 smpi_group_set_mapping(*newgroup, index, j);
528 xbt_free(to_exclude);
530 retval = MPI_SUCCESS;
535 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
537 int retval, i, j, rank, size, index;
539 if (group == MPI_GROUP_NULL) {
540 retval = MPI_ERR_GROUP;
541 } else if (newgroup == nullptr) {
542 retval = MPI_ERR_ARG;
545 *newgroup = MPI_GROUP_EMPTY;
548 for (i = 0; i < n; i++) {
549 for (rank = ranges[i][0]; /* First */
550 rank >= 0 && rank < smpi_group_size(group); /* Last */
553 if(rank == ranges[i][1]){/*already last ?*/
556 rank += ranges[i][2]; /* Stride */
557 if (ranges[i][0]<ranges[i][1]){
558 if(rank > ranges[i][1])
561 if(rank < ranges[i][1])
567 *newgroup = smpi_group_new(size);
569 for (i = 0; i < n; i++) {
570 for (rank = ranges[i][0]; /* First */
571 rank >= 0 && rank < smpi_group_size(group); /* Last */
573 index = smpi_group_index(group, rank);
574 smpi_group_set_mapping(*newgroup, index, j);
576 if(rank == ranges[i][1]){/*already last ?*/
579 rank += ranges[i][2]; /* Stride */
580 if (ranges[i][0]<ranges[i][1]){
581 if(rank > ranges[i][1])
584 if(rank < ranges[i][1])
590 retval = MPI_SUCCESS;
595 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
597 int retval, i, rank, newrank,oldrank, size, index, add;
599 if (group == MPI_GROUP_NULL) {
600 retval = MPI_ERR_GROUP;
601 } else if (newgroup == nullptr) {
602 retval = MPI_ERR_ARG;
606 if(group!= smpi_comm_group(MPI_COMM_WORLD) && group != MPI_GROUP_NULL
607 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
608 smpi_group_use(group);
610 size = smpi_group_size(group);
611 for (i = 0; i < n; i++) {
612 for (rank = ranges[i][0]; /* First */
613 rank >= 0 && rank < smpi_group_size(group); /* Last */
616 if(rank == ranges[i][1]){/*already last ?*/
619 rank += ranges[i][2]; /* Stride */
620 if (ranges[i][0]<ranges[i][1]){
621 if(rank > ranges[i][1])
624 if(rank < ranges[i][1])
630 *newgroup = MPI_GROUP_EMPTY;
632 *newgroup = smpi_group_new(size);
635 while (newrank < size) {
637 for (i = 0; i < n; i++) {
638 for (rank = ranges[i][0];
639 rank >= 0 && rank < smpi_group_size(group);
645 if(rank == ranges[i][1]){/*already last ?*/
648 rank += ranges[i][2]; /* Stride */
649 if (ranges[i][0]<ranges[i][1]){
650 if(rank > ranges[i][1])
653 if(rank < ranges[i][1])
659 index = smpi_group_index(group, oldrank);
660 smpi_group_set_mapping(*newgroup, index, newrank);
668 retval = MPI_SUCCESS;
673 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
676 if (comm == MPI_COMM_NULL) {
677 retval = MPI_ERR_COMM;
678 } else if (rank == nullptr) {
679 retval = MPI_ERR_ARG;
681 *rank = smpi_comm_rank(comm);
682 retval = MPI_SUCCESS;
687 int PMPI_Comm_size(MPI_Comm comm, int *size)
690 if (comm == MPI_COMM_NULL) {
691 retval = MPI_ERR_COMM;
692 } else if (size == nullptr) {
693 retval = MPI_ERR_ARG;
695 *size = smpi_comm_size(comm);
696 retval = MPI_SUCCESS;
701 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
705 if (comm == MPI_COMM_NULL) {
706 retval = MPI_ERR_COMM;
707 } else if (name == nullptr || len == nullptr) {
708 retval = MPI_ERR_ARG;
710 smpi_comm_get_name(comm, name, len);
711 retval = MPI_SUCCESS;
716 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
720 if (comm == MPI_COMM_NULL) {
721 retval = MPI_ERR_COMM;
722 } else if (group == nullptr) {
723 retval = MPI_ERR_ARG;
725 *group = smpi_comm_group(comm);
726 if(*group!= smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL
727 && *group != MPI_GROUP_EMPTY)
728 smpi_group_use(*group);
729 retval = MPI_SUCCESS;
734 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
738 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
739 retval = MPI_ERR_COMM;
740 } else if (result == nullptr) {
741 retval = MPI_ERR_ARG;
743 if (comm1 == comm2) { /* Same communicators means same groups */
746 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
747 if (*result == MPI_IDENT) {
748 *result = MPI_CONGRUENT;
751 retval = MPI_SUCCESS;
756 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
760 if (comm == MPI_COMM_NULL) {
761 retval = MPI_ERR_COMM;
762 } else if (newcomm == nullptr) {
763 retval = MPI_ERR_ARG;
765 retval = smpi_comm_dup(comm, newcomm);
770 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
774 if (comm == MPI_COMM_NULL) {
775 retval = MPI_ERR_COMM;
776 } else if (group == MPI_GROUP_NULL) {
777 retval = MPI_ERR_GROUP;
778 } else if (newcomm == nullptr) {
779 retval = MPI_ERR_ARG;
780 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
781 *newcomm= MPI_COMM_NULL;
782 retval = MPI_SUCCESS;
784 smpi_group_use(group);
785 *newcomm = smpi_comm_new(group, nullptr);
786 retval = MPI_SUCCESS;
791 int PMPI_Comm_free(MPI_Comm * comm)
795 if (comm == nullptr) {
796 retval = MPI_ERR_ARG;
797 } else if (*comm == MPI_COMM_NULL) {
798 retval = MPI_ERR_COMM;
800 smpi_comm_destroy(*comm);
801 *comm = MPI_COMM_NULL;
802 retval = MPI_SUCCESS;
807 int PMPI_Comm_disconnect(MPI_Comm * comm)
809 /* TODO: wait until all communication in comm are done */
812 if (comm == nullptr) {
813 retval = MPI_ERR_ARG;
814 } else if (*comm == MPI_COMM_NULL) {
815 retval = MPI_ERR_COMM;
817 smpi_comm_destroy(*comm);
818 *comm = MPI_COMM_NULL;
819 retval = MPI_SUCCESS;
824 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
829 if (comm_out == nullptr) {
830 retval = MPI_ERR_ARG;
831 } else if (comm == MPI_COMM_NULL) {
832 retval = MPI_ERR_COMM;
834 *comm_out = smpi_comm_split(comm, color, key);
835 retval = MPI_SUCCESS;
842 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
847 if (request == nullptr) {
848 retval = MPI_ERR_ARG;
849 } else if (comm == MPI_COMM_NULL) {
850 retval = MPI_ERR_COMM;
851 } else if (!is_datatype_valid(datatype)) {
852 retval = MPI_ERR_TYPE;
853 } else if (dst == MPI_PROC_NULL) {
854 retval = MPI_SUCCESS;
856 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
857 retval = MPI_SUCCESS;
860 if (retval != MPI_SUCCESS && request != nullptr)
861 *request = MPI_REQUEST_NULL;
865 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
870 if (request == nullptr) {
871 retval = MPI_ERR_ARG;
872 } else if (comm == MPI_COMM_NULL) {
873 retval = MPI_ERR_COMM;
874 } else if (!is_datatype_valid(datatype)) {
875 retval = MPI_ERR_TYPE;
876 } else if (src == MPI_PROC_NULL) {
877 retval = MPI_SUCCESS;
879 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
880 retval = MPI_SUCCESS;
883 if (retval != MPI_SUCCESS && request != nullptr)
884 *request = MPI_REQUEST_NULL;
888 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
893 if (request == nullptr) {
894 retval = MPI_ERR_ARG;
895 } else if (comm == MPI_COMM_NULL) {
896 retval = MPI_ERR_COMM;
897 } else if (!is_datatype_valid(datatype)) {
898 retval = MPI_ERR_TYPE;
899 } else if (dst == MPI_PROC_NULL) {
900 retval = MPI_SUCCESS;
902 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
903 retval = MPI_SUCCESS;
906 if (retval != MPI_SUCCESS && request != nullptr)
907 *request = MPI_REQUEST_NULL;
911 int PMPI_Start(MPI_Request * request)
916 if (request == nullptr || *request == MPI_REQUEST_NULL) {
917 retval = MPI_ERR_REQUEST;
919 smpi_mpi_start(*request);
920 retval = MPI_SUCCESS;
926 int PMPI_Startall(int count, MPI_Request * requests)
931 if (requests == nullptr) {
932 retval = MPI_ERR_ARG;
934 retval = MPI_SUCCESS;
935 for (i = 0 ; i < count ; i++) {
936 if(requests[i] == MPI_REQUEST_NULL) {
937 retval = MPI_ERR_REQUEST;
940 if(retval != MPI_ERR_REQUEST) {
941 smpi_mpi_startall(count, requests);
948 int PMPI_Request_free(MPI_Request * request)
953 if (*request == MPI_REQUEST_NULL) {
954 retval = MPI_ERR_ARG;
956 smpi_mpi_request_free(request);
957 retval = MPI_SUCCESS;
963 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
969 if (request == nullptr) {
970 retval = MPI_ERR_ARG;
971 } else if (comm == MPI_COMM_NULL) {
972 retval = MPI_ERR_COMM;
973 } else if (src == MPI_PROC_NULL) {
974 *request = MPI_REQUEST_NULL;
975 retval = MPI_SUCCESS;
976 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
977 retval = MPI_ERR_RANK;
978 } else if ((count < 0) || (buf==nullptr && count > 0)) {
979 retval = MPI_ERR_COUNT;
980 } else if (!is_datatype_valid(datatype)) {
981 retval = MPI_ERR_TYPE;
982 } else if(tag<0 && tag != MPI_ANY_TAG){
983 retval = MPI_ERR_TAG;
986 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
987 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
989 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
990 extra->type = TRACING_IRECV;
991 extra->src = src_traced;
994 extra->datatype1 = encode_datatype(datatype, &known);
995 int dt_size_send = 1;
997 dt_size_send = smpi_datatype_size(datatype);
998 extra->send_size = count*dt_size_send;
999 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1001 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1002 retval = MPI_SUCCESS;
1004 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1005 (*request)->recv = 1;
1009 if (retval != MPI_SUCCESS && request != nullptr)
1010 *request = MPI_REQUEST_NULL;
1015 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1020 if (request == nullptr) {
1021 retval = MPI_ERR_ARG;
1022 } else if (comm == MPI_COMM_NULL) {
1023 retval = MPI_ERR_COMM;
1024 } else if (dst == MPI_PROC_NULL) {
1025 *request = MPI_REQUEST_NULL;
1026 retval = MPI_SUCCESS;
1027 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1028 retval = MPI_ERR_RANK;
1029 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1030 retval = MPI_ERR_COUNT;
1031 } else if (!is_datatype_valid(datatype)) {
1032 retval = MPI_ERR_TYPE;
1033 } else if(tag<0 && tag != MPI_ANY_TAG){
1034 retval = MPI_ERR_TAG;
1037 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1038 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1039 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1040 extra->type = TRACING_ISEND;
1042 extra->dst = dst_traced;
1044 extra->datatype1 = encode_datatype(datatype, &known);
1045 int dt_size_send = 1;
1047 dt_size_send = smpi_datatype_size(datatype);
1048 extra->send_size = count*dt_size_send;
1049 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1050 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1052 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1053 retval = MPI_SUCCESS;
1055 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1056 (*request)->send = 1;
1060 if (retval != MPI_SUCCESS && request!=nullptr)
1061 *request = MPI_REQUEST_NULL;
1065 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
1070 if (request == nullptr) {
1071 retval = MPI_ERR_ARG;
1072 } else if (comm == MPI_COMM_NULL) {
1073 retval = MPI_ERR_COMM;
1074 } else if (dst == MPI_PROC_NULL) {
1075 *request = MPI_REQUEST_NULL;
1076 retval = MPI_SUCCESS;
1077 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1078 retval = MPI_ERR_RANK;
1079 } else if ((count < 0)|| (buf==nullptr && count > 0)) {
1080 retval = MPI_ERR_COUNT;
1081 } else if (!is_datatype_valid(datatype)) {
1082 retval = MPI_ERR_TYPE;
1083 } else if(tag<0 && tag != MPI_ANY_TAG){
1084 retval = MPI_ERR_TAG;
1087 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1088 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1089 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1090 extra->type = TRACING_ISSEND;
1092 extra->dst = dst_traced;
1094 extra->datatype1 = encode_datatype(datatype, &known);
1095 int dt_size_send = 1;
1097 dt_size_send = smpi_datatype_size(datatype);
1098 extra->send_size = count*dt_size_send;
1099 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1100 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1102 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1103 retval = MPI_SUCCESS;
1105 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1106 (*request)->send = 1;
1110 if (retval != MPI_SUCCESS && request!=nullptr)
1111 *request = MPI_REQUEST_NULL;
1115 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1120 if (comm == MPI_COMM_NULL) {
1121 retval = MPI_ERR_COMM;
1122 } else if (src == MPI_PROC_NULL) {
1123 smpi_empty_status(status);
1124 status->MPI_SOURCE = MPI_PROC_NULL;
1125 retval = MPI_SUCCESS;
1126 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1127 retval = MPI_ERR_RANK;
1128 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1129 retval = MPI_ERR_COUNT;
1130 } else if (!is_datatype_valid(datatype)) {
1131 retval = MPI_ERR_TYPE;
1132 } else if(tag<0 && tag != MPI_ANY_TAG){
1133 retval = MPI_ERR_TAG;
1135 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1136 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1137 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1138 extra->type = TRACING_RECV;
1139 extra->src = src_traced;
1142 extra->datatype1 = encode_datatype(datatype, &known);
1143 int dt_size_send = 1;
1145 dt_size_send = smpi_datatype_size(datatype);
1146 extra->send_size = count*dt_size_send;
1147 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1149 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1150 retval = MPI_SUCCESS;
1152 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1153 if(status!=MPI_STATUS_IGNORE){
1154 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1155 if (!TRACE_smpi_view_internals()) {
1156 TRACE_smpi_recv(rank, src_traced, rank);
1159 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1166 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1172 if (comm == MPI_COMM_NULL) {
1173 retval = MPI_ERR_COMM;
1174 } else if (dst == MPI_PROC_NULL) {
1175 retval = MPI_SUCCESS;
1176 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1177 retval = MPI_ERR_RANK;
1178 } else if ((count < 0) || (buf == nullptr && count > 0)) {
1179 retval = MPI_ERR_COUNT;
1180 } else if (!is_datatype_valid(datatype)) {
1181 retval = MPI_ERR_TYPE;
1182 } else if(tag < 0 && tag != MPI_ANY_TAG){
1183 retval = MPI_ERR_TAG;
1185 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1186 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1187 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1188 extra->type = TRACING_SEND;
1190 extra->dst = dst_traced;
1192 extra->datatype1 = encode_datatype(datatype, &known);
1193 int dt_size_send = 1;
1195 dt_size_send = smpi_datatype_size(datatype);
1197 extra->send_size = count*dt_size_send;
1198 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1199 if (!TRACE_smpi_view_internals()) {
1200 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1203 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1204 retval = MPI_SUCCESS;
1206 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1213 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1218 if (comm == MPI_COMM_NULL) {
1219 retval = MPI_ERR_COMM;
1220 } else if (dst == MPI_PROC_NULL) {
1221 retval = MPI_SUCCESS;
1222 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1223 retval = MPI_ERR_RANK;
1224 } else if ((count < 0) || (buf==nullptr && count > 0)) {
1225 retval = MPI_ERR_COUNT;
1226 } else if (!is_datatype_valid(datatype)){
1227 retval = MPI_ERR_TYPE;
1228 } else if(tag<0 && tag != MPI_ANY_TAG){
1229 retval = MPI_ERR_TAG;
1231 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1232 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1233 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1234 extra->type = TRACING_SSEND;
1236 extra->dst = dst_traced;
1238 extra->datatype1 = encode_datatype(datatype, &known);
1239 int dt_size_send = 1;
1241 dt_size_send = smpi_datatype_size(datatype);
1243 extra->send_size = count*dt_size_send;
1244 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1245 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1247 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1248 retval = MPI_SUCCESS;
1250 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1257 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1258 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1264 if (comm == MPI_COMM_NULL) {
1265 retval = MPI_ERR_COMM;
1266 } else if (!is_datatype_valid(sendtype)
1267 || !is_datatype_valid(recvtype)) {
1268 retval = MPI_ERR_TYPE;
1269 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1270 smpi_empty_status(status);
1271 status->MPI_SOURCE = MPI_PROC_NULL;
1272 retval = MPI_SUCCESS;
1273 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1274 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1275 retval = MPI_ERR_RANK;
1276 } else if ((sendcount < 0 || recvcount<0) ||
1277 (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
1278 retval = MPI_ERR_COUNT;
1279 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1280 retval = MPI_ERR_TAG;
1283 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1284 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1285 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1286 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1287 extra->type = TRACING_SENDRECV;
1288 extra->src = src_traced;
1289 extra->dst = dst_traced;
1291 extra->datatype1 = encode_datatype(sendtype, &known);
1292 int dt_size_send = 1;
1294 dt_size_send = smpi_datatype_size(sendtype);
1295 extra->send_size = sendcount*dt_size_send;
1296 extra->datatype2 = encode_datatype(recvtype, &known);
1297 int dt_size_recv = 1;
1299 dt_size_recv = smpi_datatype_size(recvtype);
1300 extra->recv_size = recvcount*dt_size_recv;
1302 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1303 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1305 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1306 recvcount, recvtype, src, recvtag, comm, status);
1307 retval = MPI_SUCCESS;
1309 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1310 TRACE_smpi_recv(rank, src_traced, rank);
1317 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1318 MPI_Comm comm, MPI_Status * status)
1322 if (!is_datatype_valid(datatype)) {
1323 retval = MPI_ERR_TYPE;
1324 } else if (count < 0) {
1325 retval = MPI_ERR_COUNT;
1327 int size = smpi_datatype_get_extent(datatype) * count;
1328 recvbuf = xbt_new0(char, size);
1329 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1330 if(retval==MPI_SUCCESS){
1331 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1339 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1343 if (request == nullptr || flag == nullptr) {
1344 retval = MPI_ERR_ARG;
1345 } else if (*request == MPI_REQUEST_NULL) {
1347 smpi_empty_status(status);
1348 retval = MPI_SUCCESS;
1350 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1352 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1353 extra->type = TRACING_TEST;
1354 TRACE_smpi_testing_in(rank, extra);
1356 *flag = smpi_mpi_test(request, status);
1358 TRACE_smpi_testing_out(rank);
1359 retval = MPI_SUCCESS;
1365 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1370 if (index == nullptr || flag == nullptr) {
1371 retval = MPI_ERR_ARG;
1373 *flag = smpi_mpi_testany(count, requests, index, status);
1374 retval = MPI_SUCCESS;
1380 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1385 if (flag == nullptr) {
1386 retval = MPI_ERR_ARG;
1388 *flag = smpi_mpi_testall(count, requests, statuses);
1389 retval = MPI_SUCCESS;
1395 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1399 if (status == nullptr) {
1400 retval = MPI_ERR_ARG;
1401 } else if (comm == MPI_COMM_NULL) {
1402 retval = MPI_ERR_COMM;
1403 } else if (source == MPI_PROC_NULL) {
1404 smpi_empty_status(status);
1405 status->MPI_SOURCE = MPI_PROC_NULL;
1406 retval = MPI_SUCCESS;
1408 smpi_mpi_probe(source, tag, comm, status);
1409 retval = MPI_SUCCESS;
1415 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1419 if ((flag == nullptr) || (status == nullptr)) {
1420 retval = MPI_ERR_ARG;
1421 } else if (comm == MPI_COMM_NULL) {
1422 retval = MPI_ERR_COMM;
1423 } else if (source == MPI_PROC_NULL) {
1425 smpi_empty_status(status);
1426 status->MPI_SOURCE = MPI_PROC_NULL;
1427 retval = MPI_SUCCESS;
1429 smpi_mpi_iprobe(source, tag, comm, flag, status);
1430 retval = MPI_SUCCESS;
1436 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1442 smpi_empty_status(status);
1444 if (request == nullptr) {
1445 retval = MPI_ERR_ARG;
1446 } else if (*request == MPI_REQUEST_NULL) {
1447 retval = MPI_SUCCESS;
1450 int rank = (request!=nullptr && (*request)->comm != MPI_COMM_NULL) ? smpi_process_index() : -1;
1452 int src_traced = (*request)->src;
1453 int dst_traced = (*request)->dst;
1454 MPI_Comm comm = (*request)->comm;
1455 int is_wait_for_receive = (*request)->recv;
1456 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1457 extra->type = TRACING_WAIT;
1458 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1460 smpi_mpi_wait(request, status);
1461 retval = MPI_SUCCESS;
1463 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1464 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1465 if (is_wait_for_receive) {
1466 if(src_traced==MPI_ANY_SOURCE)
1467 src_traced = (status!=MPI_STATUS_IGNORE) ?
1468 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1470 TRACE_smpi_recv(rank, src_traced, dst_traced);
1478 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1480 if (index == nullptr)
1484 //save requests information for tracing
1486 int *srcs = nullptr, *dsts = nullptr, *recvs = nullptr;
1487 MPI_Comm* comms = nullptr;
1489 srcs = xbt_new0(int, count);
1490 dsts = xbt_new0(int, count);
1491 recvs = xbt_new0(int, count);
1492 comms = xbt_new0(MPI_Comm, count);
1494 for (i = 0; i < count; i++) {
1495 MPI_Request req = requests[i]; //already received requests are no longer valid
1499 recvs[i] = req->recv;
1500 comms[i] = req->comm;
1503 int rank_traced = smpi_process_index();
1504 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1505 extra->type = TRACING_WAITANY;
1506 extra->send_size=count;
1507 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1509 *index = smpi_mpi_waitany(count, requests, status);
1511 if(*index!=MPI_UNDEFINED){
1512 int src_traced = srcs[*index];
1513 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1514 int dst_traced = dsts[*index];
1515 int is_wait_for_receive = recvs[*index];
1516 if (is_wait_for_receive) {
1517 if(srcs[*index]==MPI_ANY_SOURCE)
1518 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1519 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) : srcs[*index];
1520 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1522 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1533 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1536 //save information from requests
1538 int *srcs = xbt_new0(int, count);
1539 int *dsts = xbt_new0(int, count);
1540 int *recvs = xbt_new0(int, count);
1541 int *valid = xbt_new0(int, count);
1542 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1544 for (i = 0; i < count; i++) {
1545 MPI_Request req = requests[i];
1546 if(req!=MPI_REQUEST_NULL){
1549 recvs[i] = req->recv;
1550 comms[i] = req->comm;
1556 int rank_traced = smpi_process_index();
1557 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1558 extra->type = TRACING_WAITALL;
1559 extra->send_size=count;
1560 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1562 int retval = smpi_mpi_waitall(count, requests, status);
1564 for (i = 0; i < count; i++) {
1566 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1567 int src_traced = srcs[i];
1568 int dst_traced = dsts[i];
1569 int is_wait_for_receive = recvs[i];
1570 if (is_wait_for_receive) {
1571 if(src_traced==MPI_ANY_SOURCE)
1572 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1573 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) : srcs[i];
1574 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1578 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1589 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1594 if (outcount == nullptr) {
1595 retval = MPI_ERR_ARG;
1597 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1598 retval = MPI_SUCCESS;
1604 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1609 if (outcount == nullptr) {
1610 retval = MPI_ERR_ARG;
1612 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1613 retval = MPI_SUCCESS;
1620 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1626 if (comm == MPI_COMM_NULL) {
1627 retval = MPI_ERR_COMM;
1628 } else if (!is_datatype_valid(datatype)) {
1629 retval = MPI_ERR_ARG;
1631 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1632 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1634 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1635 extra->type = TRACING_BCAST;
1636 extra->root = root_traced;
1638 extra->datatype1 = encode_datatype(datatype, &known);
1639 int dt_size_send = 1;
1641 dt_size_send = smpi_datatype_size(datatype);
1642 extra->send_size = count*dt_size_send;
1643 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1644 if(smpi_comm_size(comm)>1)
1645 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1646 retval = MPI_SUCCESS;
1648 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1655 int PMPI_Barrier(MPI_Comm comm)
1661 if (comm == MPI_COMM_NULL) {
1662 retval = MPI_ERR_COMM;
1664 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1665 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1666 extra->type = TRACING_BARRIER;
1667 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1669 mpi_coll_barrier_fun(comm);
1670 retval = MPI_SUCCESS;
1672 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1679 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1680 int root, MPI_Comm comm)
1686 if (comm == MPI_COMM_NULL) {
1687 retval = MPI_ERR_COMM;
1688 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1689 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1690 retval = MPI_ERR_TYPE;
1691 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1692 retval = MPI_ERR_COUNT;
1695 char* sendtmpbuf = static_cast<char*>(sendbuf);
1696 int sendtmpcount = sendcount;
1697 MPI_Datatype sendtmptype = sendtype;
1698 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1700 sendtmptype=recvtype;
1702 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1703 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1704 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1705 extra->type = TRACING_GATHER;
1706 extra->root = root_traced;
1708 extra->datatype1 = encode_datatype(sendtmptype, &known);
1709 int dt_size_send = 1;
1711 dt_size_send = smpi_datatype_size(sendtmptype);
1712 extra->send_size = sendtmpcount*dt_size_send;
1713 extra->datatype2 = encode_datatype(recvtype, &known);
1714 int dt_size_recv = 1;
1715 if((smpi_comm_rank(comm)==root) && known==0)
1716 dt_size_recv = smpi_datatype_size(recvtype);
1717 extra->recv_size = recvcount*dt_size_recv;
1719 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1721 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1723 retval = MPI_SUCCESS;
1724 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1731 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1732 MPI_Datatype recvtype, int root, MPI_Comm comm)
1738 if (comm == MPI_COMM_NULL) {
1739 retval = MPI_ERR_COMM;
1740 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1741 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1742 retval = MPI_ERR_TYPE;
1743 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1744 retval = MPI_ERR_COUNT;
1745 } else if (recvcounts == nullptr || displs == nullptr) {
1746 retval = MPI_ERR_ARG;
1748 char* sendtmpbuf = static_cast<char*>(sendbuf);
1749 int sendtmpcount = sendcount;
1750 MPI_Datatype sendtmptype = sendtype;
1751 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1753 sendtmptype=recvtype;
1756 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1757 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1759 int size = smpi_comm_size(comm);
1760 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1761 extra->type = TRACING_GATHERV;
1762 extra->num_processes = size;
1763 extra->root = root_traced;
1765 extra->datatype1 = encode_datatype(sendtmptype, &known);
1766 int dt_size_send = 1;
1768 dt_size_send = smpi_datatype_size(sendtype);
1769 extra->send_size = sendtmpcount*dt_size_send;
1770 extra->datatype2 = encode_datatype(recvtype, &known);
1771 int dt_size_recv = 1;
1773 dt_size_recv = smpi_datatype_size(recvtype);
1774 if((smpi_comm_rank(comm)==root)){
1775 extra->recvcounts= xbt_new(int,size);
1776 for(i=0; i< size; i++)//copy data to avoid bad free
1777 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1779 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1781 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1782 retval = MPI_SUCCESS;
1783 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1790 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1791 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1797 if (comm == MPI_COMM_NULL) {
1798 retval = MPI_ERR_COMM;
1799 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1800 (recvtype == MPI_DATATYPE_NULL)){
1801 retval = MPI_ERR_TYPE;
1802 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1804 retval = MPI_ERR_COUNT;
1806 if(sendbuf == MPI_IN_PLACE) {
1807 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1808 sendcount=recvcount;
1811 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1812 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1813 extra->type = TRACING_ALLGATHER;
1815 extra->datatype1 = encode_datatype(sendtype, &known);
1816 int dt_size_send = 1;
1818 dt_size_send = smpi_datatype_size(sendtype);
1819 extra->send_size = sendcount*dt_size_send;
1820 extra->datatype2 = encode_datatype(recvtype, &known);
1821 int dt_size_recv = 1;
1823 dt_size_recv = smpi_datatype_size(recvtype);
1824 extra->recv_size = recvcount*dt_size_recv;
1826 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1828 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1829 retval = MPI_SUCCESS;
1830 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1836 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1837 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1843 if (comm == MPI_COMM_NULL) {
1844 retval = MPI_ERR_COMM;
1845 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1846 (recvtype == MPI_DATATYPE_NULL)){
1847 retval = MPI_ERR_TYPE;
1848 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1849 retval = MPI_ERR_COUNT;
1850 } else if (recvcounts == nullptr || displs == nullptr) {
1851 retval = MPI_ERR_ARG;
1854 if(sendbuf == MPI_IN_PLACE) {
1855 sendbuf=static_cast<char*>(recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1856 sendcount=recvcounts[smpi_comm_rank(comm)];
1859 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1861 int size = smpi_comm_size(comm);
1862 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1863 extra->type = TRACING_ALLGATHERV;
1864 extra->num_processes = size;
1866 extra->datatype1 = encode_datatype(sendtype, &known);
1867 int dt_size_send = 1;
1869 dt_size_send = smpi_datatype_size(sendtype);
1870 extra->send_size = sendcount*dt_size_send;
1871 extra->datatype2 = encode_datatype(recvtype, &known);
1872 int dt_size_recv = 1;
1874 dt_size_recv = smpi_datatype_size(recvtype);
1875 extra->recvcounts= xbt_new(int, size);
1876 for(i=0; i< size; i++)//copy data to avoid bad free
1877 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1879 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1881 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1882 retval = MPI_SUCCESS;
1883 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1890 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1891 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1897 if (comm == MPI_COMM_NULL) {
1898 retval = MPI_ERR_COMM;
1899 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1900 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1901 retval = MPI_ERR_TYPE;
1902 } else if ((sendbuf == recvbuf) ||
1903 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == nullptr))){
1904 retval = MPI_ERR_BUFFER;
1907 if (recvbuf == MPI_IN_PLACE) {
1909 recvcount=sendcount;
1911 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1912 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1913 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1914 extra->type = TRACING_SCATTER;
1915 extra->root = root_traced;
1917 extra->datatype1 = encode_datatype(sendtype, &known);
1918 int dt_size_send = 1;
1919 if((smpi_comm_rank(comm)==root) && known==0)
1920 dt_size_send = smpi_datatype_size(sendtype);
1921 extra->send_size = sendcount*dt_size_send;
1922 extra->datatype2 = encode_datatype(recvtype, &known);
1923 int dt_size_recv = 1;
1925 dt_size_recv = smpi_datatype_size(recvtype);
1926 extra->recv_size = recvcount*dt_size_recv;
1927 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1929 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1930 retval = MPI_SUCCESS;
1931 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1938 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1939 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1945 if (comm == MPI_COMM_NULL) {
1946 retval = MPI_ERR_COMM;
1947 } else if (sendcounts == nullptr || displs == nullptr) {
1948 retval = MPI_ERR_ARG;
1949 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1950 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1951 retval = MPI_ERR_TYPE;
1953 if (recvbuf == MPI_IN_PLACE) {
1955 recvcount=sendcounts[smpi_comm_rank(comm)];
1957 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1958 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1960 int size = smpi_comm_size(comm);
1961 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1962 extra->type = TRACING_SCATTERV;
1963 extra->num_processes = size;
1964 extra->root = root_traced;
1966 extra->datatype1 = encode_datatype(sendtype, &known);
1967 int dt_size_send = 1;
1969 dt_size_send = smpi_datatype_size(sendtype);
1970 if((smpi_comm_rank(comm)==root)){
1971 extra->sendcounts= xbt_new(int, size);
1972 for(i=0; i< size; i++)//copy data to avoid bad free
1973 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
1975 extra->datatype2 = encode_datatype(recvtype, &known);
1976 int dt_size_recv = 1;
1978 dt_size_recv = smpi_datatype_size(recvtype);
1979 extra->recv_size = recvcount*dt_size_recv;
1980 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1982 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1984 retval = MPI_SUCCESS;
1985 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1992 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1998 if (comm == MPI_COMM_NULL) {
1999 retval = MPI_ERR_COMM;
2000 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2001 retval = MPI_ERR_ARG;
2003 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2004 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2005 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2006 extra->type = TRACING_REDUCE;
2008 extra->datatype1 = encode_datatype(datatype, &known);
2009 int dt_size_send = 1;
2011 dt_size_send = smpi_datatype_size(datatype);
2012 extra->send_size = count*dt_size_send;
2013 extra->root = root_traced;
2015 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2017 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2019 retval = MPI_SUCCESS;
2020 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2027 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2031 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2032 retval = MPI_ERR_ARG;
2034 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2041 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2047 if (comm == MPI_COMM_NULL) {
2048 retval = MPI_ERR_COMM;
2049 } else if (!is_datatype_valid(datatype)) {
2050 retval = MPI_ERR_TYPE;
2051 } else if (op == MPI_OP_NULL) {
2052 retval = MPI_ERR_OP;
2055 char* sendtmpbuf = static_cast<char*>(sendbuf);
2056 if( sendbuf == MPI_IN_PLACE ) {
2057 sendtmpbuf = static_cast<char*>(xbt_malloc(count*smpi_datatype_get_extent(datatype)));
2058 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2060 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2061 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2062 extra->type = TRACING_ALLREDUCE;
2064 extra->datatype1 = encode_datatype(datatype, &known);
2065 int dt_size_send = 1;
2067 dt_size_send = smpi_datatype_size(datatype);
2068 extra->send_size = count*dt_size_send;
2070 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2072 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2074 if( sendbuf == MPI_IN_PLACE )
2075 xbt_free(sendtmpbuf);
2077 retval = MPI_SUCCESS;
2078 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2085 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2091 if (comm == MPI_COMM_NULL) {
2092 retval = MPI_ERR_COMM;
2093 } else if (!is_datatype_valid(datatype)) {
2094 retval = MPI_ERR_TYPE;
2095 } else if (op == MPI_OP_NULL) {
2096 retval = MPI_ERR_OP;
2098 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2099 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2100 extra->type = TRACING_SCAN;
2102 extra->datatype1 = encode_datatype(datatype, &known);
2103 int dt_size_send = 1;
2105 dt_size_send = smpi_datatype_size(datatype);
2106 extra->send_size = count*dt_size_send;
2108 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2110 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2112 retval = MPI_SUCCESS;
2113 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2120 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2125 if (comm == MPI_COMM_NULL) {
2126 retval = MPI_ERR_COMM;
2127 } else if (!is_datatype_valid(datatype)) {
2128 retval = MPI_ERR_TYPE;
2129 } else if (op == MPI_OP_NULL) {
2130 retval = MPI_ERR_OP;
2132 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2133 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2134 extra->type = TRACING_EXSCAN;
2136 extra->datatype1 = encode_datatype(datatype, &known);
2137 int dt_size_send = 1;
2139 dt_size_send = smpi_datatype_size(datatype);
2140 extra->send_size = count*dt_size_send;
2141 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2143 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2144 retval = MPI_SUCCESS;
2145 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2152 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2157 if (comm == MPI_COMM_NULL) {
2158 retval = MPI_ERR_COMM;
2159 } else if (!is_datatype_valid(datatype)) {
2160 retval = MPI_ERR_TYPE;
2161 } else if (op == MPI_OP_NULL) {
2162 retval = MPI_ERR_OP;
2163 } else if (recvcounts == nullptr) {
2164 retval = MPI_ERR_ARG;
2166 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2168 int size = smpi_comm_size(comm);
2169 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2170 extra->type = TRACING_REDUCE_SCATTER;
2171 extra->num_processes = size;
2173 extra->datatype1 = encode_datatype(datatype, &known);
2174 int dt_size_send = 1;
2176 dt_size_send = smpi_datatype_size(datatype);
2177 extra->send_size = 0;
2178 extra->recvcounts= xbt_new(int, size);
2179 for(i=0; i< size; i++)//copy data to avoid bad free
2180 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2181 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2183 void* sendtmpbuf=sendbuf;
2184 if(sendbuf==MPI_IN_PLACE)
2187 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2188 retval = MPI_SUCCESS;
2189 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2196 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2197 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2202 if (comm == MPI_COMM_NULL) {
2203 retval = MPI_ERR_COMM;
2204 } else if (!is_datatype_valid(datatype)) {
2205 retval = MPI_ERR_TYPE;
2206 } else if (op == MPI_OP_NULL) {
2207 retval = MPI_ERR_OP;
2208 } else if (recvcount < 0) {
2209 retval = MPI_ERR_ARG;
2211 int count=smpi_comm_size(comm);
2213 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2214 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2215 extra->type = TRACING_REDUCE_SCATTER;
2216 extra->num_processes = count;
2218 extra->datatype1 = encode_datatype(datatype, &known);
2219 int dt_size_send = 1;
2221 dt_size_send = smpi_datatype_size(datatype);
2222 extra->send_size = 0;
2223 extra->recvcounts= xbt_new(int, count);
2224 for(i=0; i< count; i++)//copy data to avoid bad free
2225 extra->recvcounts[i] = recvcount*dt_size_send;
2227 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2229 int* recvcounts=static_cast<int*>(xbt_malloc(count));
2230 for (i=0; i<count;i++)
2231 recvcounts[i]=recvcount;
2232 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts, datatype, op, comm);
2233 xbt_free(recvcounts);
2234 retval = MPI_SUCCESS;
2236 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2243 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2244 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2250 if (comm == MPI_COMM_NULL) {
2251 retval = MPI_ERR_COMM;
2252 } else if (sendtype == MPI_DATATYPE_NULL
2253 || recvtype == MPI_DATATYPE_NULL) {
2254 retval = MPI_ERR_TYPE;
2256 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2257 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2258 extra->type = TRACING_ALLTOALL;
2260 extra->datatype1 = encode_datatype(sendtype, &known);
2262 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2264 extra->send_size = sendcount;
2265 extra->datatype2 = encode_datatype(recvtype, &known);
2267 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2269 extra->recv_size = recvcount;
2270 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2272 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2274 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2281 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2282 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2288 if (comm == MPI_COMM_NULL) {
2289 retval = MPI_ERR_COMM;
2290 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2291 retval = MPI_ERR_TYPE;
2292 } else if (sendcounts == nullptr || senddisps == nullptr || recvcounts == nullptr || recvdisps == nullptr) {
2293 retval = MPI_ERR_ARG;
2295 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2297 int size = smpi_comm_size(comm);
2298 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2299 extra->type = TRACING_ALLTOALLV;
2300 extra->send_size = 0;
2301 extra->recv_size = 0;
2302 extra->recvcounts= xbt_new(int, size);
2303 extra->sendcounts= xbt_new(int, size);
2305 extra->datatype1 = encode_datatype(sendtype, &known);
2306 int dt_size_send = 1;
2308 dt_size_send = smpi_datatype_size(sendtype);
2309 int dt_size_recv = 1;
2310 extra->datatype2 = encode_datatype(recvtype, &known);
2312 dt_size_recv = smpi_datatype_size(recvtype);
2313 for(i=0; i< size; i++){//copy data to avoid bad free
2314 extra->send_size += sendcounts[i]*dt_size_send;
2315 extra->recv_size += recvcounts[i]*dt_size_recv;
2317 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2318 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2320 extra->num_processes = size;
2321 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2323 retval = mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype,
2325 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2333 int PMPI_Get_processor_name(char *name, int *resultlen)
2335 int retval = MPI_SUCCESS;
2337 strncpy(name, sg_host_get_name(SIMIX_host_self()),
2338 strlen(sg_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2339 strlen(sg_host_get_name(SIMIX_host_self())) +1 : MPI_MAX_PROCESSOR_NAME - 1 );
2340 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2345 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2347 int retval = MPI_SUCCESS;
2350 if (status == nullptr || count == nullptr) {
2351 retval = MPI_ERR_ARG;
2352 } else if (!is_datatype_valid(datatype)) {
2353 retval = MPI_ERR_TYPE;
2355 size = smpi_datatype_size(datatype);
2358 } else if (status->count % size != 0) {
2359 retval = MPI_UNDEFINED;
2361 *count = smpi_mpi_get_count(status, datatype);
2367 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2370 if (old_type == MPI_DATATYPE_NULL) {
2371 retval = MPI_ERR_TYPE;
2372 } else if (count<0){
2373 retval = MPI_ERR_COUNT;
2375 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2380 int PMPI_Type_commit(MPI_Datatype* datatype) {
2383 if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) {
2384 retval = MPI_ERR_TYPE;
2386 smpi_datatype_commit(datatype);
2387 retval = MPI_SUCCESS;
2392 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2395 if (old_type == MPI_DATATYPE_NULL) {
2396 retval = MPI_ERR_TYPE;
2397 } else if (count<0 || blocklen<0){
2398 retval = MPI_ERR_COUNT;
2400 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2405 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2408 if (old_type == MPI_DATATYPE_NULL) {
2409 retval = MPI_ERR_TYPE;
2410 } else if (count<0 || blocklen<0){
2411 retval = MPI_ERR_COUNT;
2413 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2418 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2419 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2422 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2425 if (old_type == MPI_DATATYPE_NULL) {
2426 retval = MPI_ERR_TYPE;
2427 } else if (count<0){
2428 retval = MPI_ERR_COUNT;
2430 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2435 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2438 if (old_type == MPI_DATATYPE_NULL) {
2439 retval = MPI_ERR_TYPE;
2440 } else if (count<0){
2441 retval = MPI_ERR_COUNT;
2443 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2448 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2449 MPI_Datatype* new_type) {
2452 if (old_type == MPI_DATATYPE_NULL) {
2453 retval = MPI_ERR_TYPE;
2454 } else if (count<0){
2455 retval = MPI_ERR_COUNT;
2457 int* blocklens=static_cast<int*>(xbt_malloc(blocklength*count));
2458 for (i=0; i<count;i++)
2459 blocklens[i]=blocklength;
2460 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2461 xbt_free(blocklens);
2466 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2469 if (old_type == MPI_DATATYPE_NULL) {
2470 retval = MPI_ERR_TYPE;
2471 } else if (count<0){
2472 retval = MPI_ERR_COUNT;
2474 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2479 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2480 MPI_Datatype* new_type) {
2481 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2484 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2485 MPI_Datatype* new_type) {
2488 if (old_type == MPI_DATATYPE_NULL) {
2489 retval = MPI_ERR_TYPE;
2490 } else if (count<0){
2491 retval = MPI_ERR_COUNT;
2493 int* blocklens=(int*)xbt_malloc(blocklength*count);
2494 for (i=0; i<count;i++)blocklens[i]=blocklength;
2495 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2496 xbt_free(blocklens);
2501 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2505 retval = MPI_ERR_COUNT;
2507 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2512 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2513 MPI_Datatype* new_type) {
2514 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2517 int PMPI_Error_class(int errorcode, int* errorclass) {
2518 // assume smpi uses only standard mpi error codes
2519 *errorclass=errorcode;
2523 int PMPI_Initialized(int* flag) {
2524 *flag=smpi_process_initialized();
2528 /* The topo part of MPI_COMM_WORLD should always be nullptr. When other topologies will be implemented, not only should we
2529 * check if the topology is nullptr, but we should check if it is the good topology type (so we have to add a
2530 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2532 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2534 if (comm_old == MPI_COMM_NULL){
2535 retval = MPI_ERR_COMM;
2536 } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) {
2537 retval = MPI_ERR_ARG;
2539 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2544 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2545 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2546 return MPI_ERR_TOPOLOGY;
2548 if (coords == nullptr) {
2551 return smpi_mpi_cart_rank(comm, coords, rank);
2554 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2555 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2556 return MPI_ERR_TOPOLOGY;
2558 if (source == nullptr || dest == nullptr || direction < 0 ) {
2561 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2564 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2565 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2566 return MPI_ERR_TOPOLOGY;
2568 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2569 return MPI_ERR_RANK;
2574 if(coords == nullptr) {
2577 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2580 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2581 if(comm == nullptr || smpi_comm_topo(comm) == nullptr) {
2582 return MPI_ERR_TOPOLOGY;
2584 if(maxdims <= 0 || dims == nullptr || periods == nullptr || coords == nullptr) {
2587 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2590 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2591 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2592 return MPI_ERR_TOPOLOGY;
2594 if (ndims == nullptr) {
2597 return smpi_mpi_cartdim_get(comm, ndims);
2600 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2601 if(dims == nullptr) {
2604 if (ndims < 1 || nnodes < 1) {
2605 return MPI_ERR_DIMS;
2608 return smpi_mpi_dims_create(nnodes, ndims, dims);
2611 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2612 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == nullptr) {
2613 return MPI_ERR_TOPOLOGY;
2615 if (comm_new == nullptr) {
2618 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2621 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2622 if(oldtype == MPI_DATATYPE_NULL) {
2623 return MPI_ERR_TYPE;
2625 int blocks[3] = { 1, 1, 1 };
2626 MPI_Aint disps[3] = { lb, 0, lb+extent };
2627 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2629 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2630 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t) , subtype, DT_FLAG_VECTOR);
2632 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2636 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2639 if (comm == MPI_COMM_NULL) {
2640 retval= MPI_ERR_COMM;
2641 }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){
2642 retval= MPI_ERR_OTHER;
2644 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2645 retval = MPI_SUCCESS;
2651 int PMPI_Win_free( MPI_Win* win){
2654 if (win == nullptr || *win == MPI_WIN_NULL) {
2655 retval = MPI_ERR_WIN;
2657 retval=smpi_mpi_win_free(win);
2663 int PMPI_Win_set_name(MPI_Win win, char * name)
2666 if (win == MPI_WIN_NULL) {
2667 retval = MPI_ERR_TYPE;
2668 } else if (name == nullptr) {
2669 retval = MPI_ERR_ARG;
2671 smpi_mpi_win_set_name(win, name);
2672 retval = MPI_SUCCESS;
2677 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2679 int retval = MPI_SUCCESS;
2681 if (win == MPI_WIN_NULL) {
2682 retval = MPI_ERR_WIN;
2683 } else if (name == nullptr) {
2684 retval = MPI_ERR_ARG;
2686 smpi_mpi_win_get_name(win, name, len);
2691 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2692 int retval = MPI_SUCCESS;
2693 if (win == MPI_WIN_NULL) {
2694 retval = MPI_ERR_WIN;
2696 smpi_mpi_win_get_group(win, group);
2697 smpi_group_use(*group);
2703 int PMPI_Win_fence( int assert, MPI_Win win){
2706 if (win == MPI_WIN_NULL) {
2707 retval = MPI_ERR_WIN;
2709 int rank = smpi_process_index();
2710 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2711 retval = smpi_mpi_win_fence(assert, win);
2712 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2718 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2719 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2722 if (win == MPI_WIN_NULL) {
2723 retval = MPI_ERR_WIN;
2724 } else if (target_rank == MPI_PROC_NULL) {
2725 retval = MPI_SUCCESS;
2726 } else if (target_rank <0){
2727 retval = MPI_ERR_RANK;
2728 } else if (target_disp <0){
2729 retval = MPI_ERR_ARG;
2730 } else if ((origin_count < 0 || target_count < 0) ||
2731 (origin_addr==nullptr && origin_count > 0)){
2732 retval = MPI_ERR_COUNT;
2733 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2734 retval = MPI_ERR_TYPE;
2736 int rank = smpi_process_index();
2738 smpi_mpi_win_get_group(win, &group);
2739 int src_traced = smpi_group_index(group, target_rank);
2740 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2742 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2743 target_datatype, win);
2745 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2751 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2752 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2755 if (win == MPI_WIN_NULL) {
2756 retval = MPI_ERR_WIN;
2757 } else if (target_rank == MPI_PROC_NULL) {
2758 retval = MPI_SUCCESS;
2759 } else if (target_rank <0){
2760 retval = MPI_ERR_RANK;
2761 } else if (target_disp <0){
2762 retval = MPI_ERR_ARG;
2763 } else if ((origin_count < 0 || target_count < 0) ||
2764 (origin_addr==nullptr && origin_count > 0)){
2765 retval = MPI_ERR_COUNT;
2766 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2767 retval = MPI_ERR_TYPE;
2769 int rank = smpi_process_index();
2771 smpi_mpi_win_get_group(win, &group);
2772 int dst_traced = smpi_group_index(group, target_rank);
2773 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
2774 TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2776 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2777 target_datatype, win);
2779 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2785 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2786 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2789 if (win == MPI_WIN_NULL) {
2790 retval = MPI_ERR_WIN;
2791 } else if (target_rank == MPI_PROC_NULL) {
2792 retval = MPI_SUCCESS;
2793 } else if (target_rank <0){
2794 retval = MPI_ERR_RANK;
2795 } else if (target_disp <0){
2796 retval = MPI_ERR_ARG;
2797 } else if ((origin_count < 0 || target_count < 0) ||
2798 (origin_addr==nullptr && origin_count > 0)){
2799 retval = MPI_ERR_COUNT;
2800 } else if ((!is_datatype_valid(origin_datatype)) ||
2801 (!is_datatype_valid(target_datatype))) {
2802 retval = MPI_ERR_TYPE;
2803 } else if (op == MPI_OP_NULL) {
2804 retval = MPI_ERR_OP;
2806 int rank = smpi_process_index();
2808 smpi_mpi_win_get_group(win, &group);
2809 int src_traced = smpi_group_index(group, target_rank);
2810 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
2812 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2813 target_datatype, op, win);
2815 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2821 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2824 if (win == MPI_WIN_NULL) {
2825 retval = MPI_ERR_WIN;
2826 } else if (group==MPI_GROUP_NULL){
2827 retval = MPI_ERR_GROUP;
2830 int rank = smpi_process_index();
2831 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2832 retval = smpi_mpi_win_post(group,assert,win);
2833 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2839 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2842 if (win == MPI_WIN_NULL) {
2843 retval = MPI_ERR_WIN;
2844 } else if (group==MPI_GROUP_NULL){
2845 retval = MPI_ERR_GROUP;
2848 int rank = smpi_process_index();
2849 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2850 retval = smpi_mpi_win_start(group,assert,win);
2851 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2857 int PMPI_Win_complete(MPI_Win win){
2860 if (win == MPI_WIN_NULL) {
2861 retval = MPI_ERR_WIN;
2864 int rank = smpi_process_index();
2865 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2867 retval = smpi_mpi_win_complete(win);
2869 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2875 int PMPI_Win_wait(MPI_Win win){
2878 if (win == MPI_WIN_NULL) {
2879 retval = MPI_ERR_WIN;
2882 int rank = smpi_process_index();
2883 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, nullptr);
2885 retval = smpi_mpi_win_wait(win);
2887 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2893 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2894 void *ptr = xbt_malloc(size);
2896 return MPI_ERR_NO_MEM;
2898 *static_cast<void**>(baseptr) = ptr;
2903 int PMPI_Free_mem(void *baseptr){
2908 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2911 if (datatype == MPI_DATATYPE_NULL) {
2912 retval = MPI_ERR_TYPE;
2913 } else if (name == nullptr) {
2914 retval = MPI_ERR_ARG;
2916 smpi_datatype_set_name(datatype, name);
2917 retval = MPI_SUCCESS;
2922 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2926 if (datatype == MPI_DATATYPE_NULL) {
2927 retval = MPI_ERR_TYPE;
2928 } else if (name == nullptr) {
2929 retval = MPI_ERR_ARG;
2931 smpi_datatype_get_name(datatype, name, len);
2932 retval = MPI_SUCCESS;
2937 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2938 return smpi_type_f2c(datatype);
2941 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2942 return smpi_type_c2f( datatype);
2945 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2946 return smpi_group_f2c( group);
2949 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2950 return smpi_group_c2f(group);
2953 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2954 return smpi_request_f2c(request);
2957 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2958 return smpi_request_c2f(request);
2961 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2962 return smpi_win_f2c(win);
2965 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2966 return smpi_win_c2f(win);
2969 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2970 return smpi_op_f2c(op);
2973 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2974 return smpi_op_c2f(op);
2977 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2978 return smpi_comm_f2c(comm);
2981 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2982 return smpi_comm_c2f(comm);
2985 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2986 return smpi_info_f2c(info);
2989 MPI_Fint PMPI_Info_c2f(MPI_Info info){
2990 return smpi_info_c2f(info);
2993 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2994 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
2997 int PMPI_Keyval_free(int* keyval) {
2998 return smpi_comm_keyval_free(keyval);
3001 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3002 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3003 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3005 else if (comm==MPI_COMM_NULL)
3006 return MPI_ERR_COMM;
3008 return smpi_comm_attr_delete(comm, keyval);
3011 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3013 static int zero = 0;
3014 static int tag_ub = 1000000;
3015 static int last_used_code = MPI_ERR_LASTCODE;
3017 if (comm==MPI_COMM_NULL){
3019 return MPI_ERR_COMM;
3027 *static_cast<int**>(attr_value) = &zero;
3029 case MPI_UNIVERSE_SIZE:
3031 *static_cast<int**>(attr_value) = &smpi_universe_size;
3033 case MPI_LASTUSEDCODE:
3035 *static_cast<int**>(attr_value) = &last_used_code;
3039 *static_cast<int**>(attr_value) = &tag_ub;
3041 case MPI_WTIME_IS_GLOBAL:
3043 *static_cast<int**>(attr_value) = &one;
3046 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3050 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3051 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3052 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3054 else if (comm==MPI_COMM_NULL)
3055 return MPI_ERR_COMM;
3057 return smpi_comm_attr_put(comm, keyval, attr_value);
3060 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3062 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3065 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3067 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3070 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3072 return PMPI_Attr_delete(comm, comm_keyval);
3075 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3078 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3081 int PMPI_Comm_free_keyval(int* keyval) {
3082 return PMPI_Keyval_free(keyval);
3085 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3087 if (type==MPI_DATATYPE_NULL)
3088 return MPI_ERR_TYPE;
3090 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3093 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3095 if (type==MPI_DATATYPE_NULL)
3096 return MPI_ERR_TYPE;
3098 return smpi_type_attr_put(type, type_keyval, attribute_val);
3101 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3103 if (type==MPI_DATATYPE_NULL)
3104 return MPI_ERR_TYPE;
3106 return smpi_type_attr_delete(type, type_keyval);
3109 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3112 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3115 int PMPI_Type_free_keyval(int* keyval) {
3116 return smpi_type_keyval_free(keyval);
3119 int PMPI_Info_create( MPI_Info *info){
3120 if (info == nullptr)
3122 *info = xbt_new(s_smpi_mpi_info_t, 1);
3123 (*info)->info_dict= xbt_dict_new_homogeneous(nullptr);
3124 (*info)->refcount=1;
3128 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3129 if (info == nullptr || key == nullptr || value == nullptr)
3132 xbt_dict_set(info->info_dict, key, (void*)value, nullptr);
3136 int PMPI_Info_free( MPI_Info *info){
3137 if (info == nullptr || *info==nullptr)
3139 (*info)->refcount--;
3140 if((*info)->refcount==0){
3141 xbt_dict_free(&((*info)->info_dict));
3144 *info=MPI_INFO_NULL;
3148 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3150 if (info == nullptr || key == nullptr || valuelen <0)
3152 if (value == nullptr)
3153 return MPI_ERR_INFO_VALUE;
3154 char* tmpvalue=static_cast<char*>(xbt_dict_get_or_null(info->info_dict, key));
3156 memset(value, 0, valuelen);
3157 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3163 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3164 if (info == nullptr || newinfo==nullptr)
3166 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3167 (*newinfo)->info_dict= xbt_dict_new_homogeneous(nullptr);
3168 (*newinfo)->refcount=1;
3169 xbt_dict_cursor_t cursor = nullptr;
3172 xbt_dict_foreach(info->info_dict,cursor,key,data){
3173 xbt_dict_set((*newinfo)->info_dict, reinterpret_cast<char*>(key), data, nullptr);
3178 int PMPI_Info_delete(MPI_Info info, char *key){
3179 if (info == nullptr || key==nullptr)
3182 xbt_dict_remove(info->info_dict, key);
3185 return MPI_ERR_INFO_NOKEY;
3190 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3191 if (info == nullptr || nkeys==nullptr)
3193 *nkeys=xbt_dict_size(info->info_dict);
3197 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3198 if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY)
3201 xbt_dict_cursor_t cursor = nullptr;
3205 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3207 strncpy(key,keyn,strlen(keyn)+1);
3208 xbt_dict_cursor_free(&cursor);
3216 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3218 if (info == nullptr || key == nullptr || valuelen==nullptr)
3220 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3222 *valuelen=strlen(tmpvalue);
3228 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3229 if(incount<0 || outcount < 0 || inbuf==nullptr || outbuf==nullptr)
3231 if(!is_datatype_valid(type))
3232 return MPI_ERR_TYPE;
3233 if(comm==MPI_COMM_NULL)
3234 return MPI_ERR_COMM;
3235 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3238 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3239 if(incount<0 || outcount < 0|| inbuf==nullptr || outbuf==nullptr)
3241 if(!is_datatype_valid(type))
3242 return MPI_ERR_TYPE;
3243 if(comm==MPI_COMM_NULL)
3244 return MPI_ERR_COMM;
3245 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3248 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3251 if(!is_datatype_valid(datatype))
3252 return MPI_ERR_TYPE;
3253 if(comm==MPI_COMM_NULL)
3254 return MPI_ERR_COMM;
3256 *size=incount*smpi_datatype_size(datatype);