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. */
9 #include "smpi_mpi_dt_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi)");
13 //this function need to be here because of the calls to smpi_bench
14 void TRACE_smpi_set_category(const char *category)
16 //need to end bench otherwise categories for execution tasks are wrong
18 TRACE_internal_smpi_set_category (category);
19 //begin bench after changing process's category
23 /* PMPI User level calls */
25 int PMPI_Init(int *argc, char ***argv)
27 // PMPI_Init is call only one time by only by SMPI process
29 MPI_Initialized(&already_init);
31 smpi_process_init(argc, argv);
32 smpi_process_mark_as_initialized();
33 int rank = smpi_process_index();
34 TRACE_smpi_init(rank);
35 TRACE_smpi_computing_init(rank);
36 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
37 extra->type = TRACING_INIT;
38 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
39 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
45 int PMPI_Finalize(void)
48 int rank = smpi_process_index();
49 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
50 extra->type = TRACING_FINALIZE;
51 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
53 smpi_process_finalize();
55 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
56 TRACE_smpi_finalize(smpi_process_index());
57 smpi_process_destroy();
61 int PMPI_Finalized(int* flag)
63 *flag=smpi_process_finalized();
67 int PMPI_Get_version (int *version,int *subversion){
68 *version = MPI_VERSION;
69 *subversion= MPI_SUBVERSION;
73 int PMPI_Get_library_version (char *version,int *len){
74 int retval = MPI_SUCCESS;
76 snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2015",
77 SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR);
78 *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
83 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
85 if (provided != NULL) {
86 *provided = MPI_THREAD_SINGLE;
88 return MPI_Init(argc, argv);
91 int PMPI_Query_thread(int *provided)
95 if (provided == NULL) {
98 *provided = MPI_THREAD_SINGLE;
104 int PMPI_Is_thread_main(int *flag)
109 retval = MPI_ERR_ARG;
111 *flag = smpi_process_index() == 0;
112 retval = MPI_SUCCESS;
117 int PMPI_Abort(MPI_Comm comm, int errorcode)
120 smpi_process_destroy();
121 // FIXME: should kill all processes in comm instead
122 simcall_process_kill(SIMIX_process_self());
126 double PMPI_Wtime(void)
128 return smpi_mpi_wtime();
131 extern double sg_maxmin_precision;
132 double PMPI_Wtick(void)
134 return sg_maxmin_precision;
137 int PMPI_Address(void *location, MPI_Aint * address)
142 retval = MPI_ERR_ARG;
144 *address = (MPI_Aint) location;
145 retval = MPI_SUCCESS;
150 int PMPI_Get_address(void *location, MPI_Aint * address)
152 return PMPI_Address(location, address);
155 int PMPI_Type_free(MPI_Datatype * datatype)
158 /* Free a predefined datatype is an error according to the standard, and should be checked for */
159 if (*datatype == MPI_DATATYPE_NULL) {
160 retval = MPI_ERR_ARG;
162 smpi_datatype_free(datatype);
163 retval = MPI_SUCCESS;
168 int PMPI_Type_size(MPI_Datatype datatype, int *size)
172 if (datatype == MPI_DATATYPE_NULL) {
173 retval = MPI_ERR_TYPE;
174 } else if (size == NULL) {
175 retval = MPI_ERR_ARG;
177 *size = (int) smpi_datatype_size(datatype);
178 retval = MPI_SUCCESS;
183 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
187 if (datatype == MPI_DATATYPE_NULL) {
188 retval = MPI_ERR_TYPE;
189 } else if (lb == NULL || extent == NULL) {
190 retval = MPI_ERR_ARG;
192 retval = smpi_datatype_extent(datatype, lb, extent);
197 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
199 return PMPI_Type_get_extent(datatype, lb, extent);
202 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
206 if (datatype == MPI_DATATYPE_NULL) {
207 retval = MPI_ERR_TYPE;
208 } else if (extent == NULL) {
209 retval = MPI_ERR_ARG;
211 *extent = smpi_datatype_get_extent(datatype);
212 retval = MPI_SUCCESS;
217 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
221 if (datatype == MPI_DATATYPE_NULL) {
222 retval = MPI_ERR_TYPE;
223 } else if (disp == NULL) {
224 retval = MPI_ERR_ARG;
226 *disp = smpi_datatype_lb(datatype);
227 retval = MPI_SUCCESS;
232 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
236 if (datatype == MPI_DATATYPE_NULL) {
237 retval = MPI_ERR_TYPE;
238 } else if (disp == NULL) {
239 retval = MPI_ERR_ARG;
241 *disp = smpi_datatype_ub(datatype);
242 retval = MPI_SUCCESS;
247 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
250 if (datatype == MPI_DATATYPE_NULL) {
251 retval = MPI_ERR_TYPE;
253 retval = smpi_datatype_dup(datatype, newtype);
258 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
262 if (function == NULL || op == NULL) {
263 retval = MPI_ERR_ARG;
265 *op = smpi_op_new(function, commute);
266 retval = MPI_SUCCESS;
271 int PMPI_Op_free(MPI_Op * op)
276 retval = MPI_ERR_ARG;
277 } else if (*op == MPI_OP_NULL) {
280 smpi_op_destroy(*op);
282 retval = MPI_SUCCESS;
287 int PMPI_Group_free(MPI_Group * group)
292 retval = MPI_ERR_ARG;
294 smpi_group_destroy(*group);
295 *group = MPI_GROUP_NULL;
296 retval = MPI_SUCCESS;
301 int PMPI_Group_size(MPI_Group group, int *size)
305 if (group == MPI_GROUP_NULL) {
306 retval = MPI_ERR_GROUP;
307 } else if (size == NULL) {
308 retval = MPI_ERR_ARG;
310 *size = smpi_group_size(group);
311 retval = MPI_SUCCESS;
316 int PMPI_Group_rank(MPI_Group group, int *rank)
320 if (group == MPI_GROUP_NULL) {
321 retval = MPI_ERR_GROUP;
322 } else if (rank == NULL) {
323 retval = MPI_ERR_ARG;
325 *rank = smpi_group_rank(group, smpi_process_index());
326 retval = MPI_SUCCESS;
331 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group group2, int *ranks2)
333 int retval, i, index;
334 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
335 retval = MPI_ERR_GROUP;
337 for (i = 0; i < n; i++) {
338 if(ranks1[i]==MPI_PROC_NULL){
339 ranks2[i]=MPI_PROC_NULL;
341 index = smpi_group_index(group1, ranks1[i]);
342 ranks2[i] = smpi_group_rank(group2, index);
345 retval = MPI_SUCCESS;
350 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
354 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
355 retval = MPI_ERR_GROUP;
356 } else if (result == NULL) {
357 retval = MPI_ERR_ARG;
359 *result = smpi_group_compare(group1, group2);
360 retval = MPI_SUCCESS;
365 int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
367 int retval, i, proc1, proc2, size, size2;
369 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
370 retval = MPI_ERR_GROUP;
371 } else if (newgroup == NULL) {
372 retval = MPI_ERR_ARG;
374 size = smpi_group_size(group1);
375 size2 = smpi_group_size(group2);
376 for (i = 0; i < size2; i++) {
377 proc2 = smpi_group_index(group2, i);
378 proc1 = smpi_group_rank(group1, proc2);
379 if (proc1 == MPI_UNDEFINED) {
384 *newgroup = MPI_GROUP_EMPTY;
386 *newgroup = smpi_group_new(size);
387 size2 = smpi_group_size(group1);
388 for (i = 0; i < size2; i++) {
389 proc1 = smpi_group_index(group1, i);
390 smpi_group_set_mapping(*newgroup, proc1, i);
392 for (i = size2; i < size; i++) {
393 proc2 = smpi_group_index(group2, i - size2);
394 smpi_group_set_mapping(*newgroup, proc2, i);
397 retval = MPI_SUCCESS;
402 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
404 int retval, i, proc1, proc2, size;
406 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
407 retval = MPI_ERR_GROUP;
408 } else if (newgroup == NULL) {
409 retval = MPI_ERR_ARG;
411 size = smpi_group_size(group2);
412 for (i = 0; i < size; i++) {
413 proc2 = smpi_group_index(group2, i);
414 proc1 = smpi_group_rank(group1, proc2);
415 if (proc1 == MPI_UNDEFINED) {
420 *newgroup = MPI_GROUP_EMPTY;
422 *newgroup = smpi_group_new(size);
424 for (i = 0; i < smpi_group_size(group2); i++) {
425 proc2 = smpi_group_index(group2, i);
426 proc1 = smpi_group_rank(group1, proc2);
427 if (proc1 != MPI_UNDEFINED) {
428 smpi_group_set_mapping(*newgroup, proc2, j);
433 retval = MPI_SUCCESS;
438 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
440 int retval, i, proc1, proc2, size, size2;
442 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
443 retval = MPI_ERR_GROUP;
444 } else if (newgroup == NULL) {
445 retval = MPI_ERR_ARG;
447 size = size2 = smpi_group_size(group1);
448 for (i = 0; i < size2; i++) {
449 proc1 = smpi_group_index(group1, i);
450 proc2 = smpi_group_rank(group2, proc1);
451 if (proc2 != MPI_UNDEFINED) {
456 *newgroup = MPI_GROUP_EMPTY;
458 *newgroup = smpi_group_new(size);
459 for (i = 0; i < size2; i++) {
460 proc1 = smpi_group_index(group1, i);
461 proc2 = smpi_group_rank(group2, proc1);
462 if (proc2 == MPI_UNDEFINED) {
463 smpi_group_set_mapping(*newgroup, proc1, i);
467 retval = MPI_SUCCESS;
472 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
476 if (group == MPI_GROUP_NULL) {
477 retval = MPI_ERR_GROUP;
478 } else if (newgroup == NULL) {
479 retval = MPI_ERR_ARG;
481 retval = smpi_group_incl(group, n, ranks, newgroup);
486 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
488 int retval, i, j, newsize, oldsize, index;
490 if (group == MPI_GROUP_NULL) {
491 retval = MPI_ERR_GROUP;
492 } else if (newgroup == NULL) {
493 retval = MPI_ERR_ARG;
497 if(group!= smpi_comm_group(MPI_COMM_WORLD) && group != MPI_GROUP_NULL
498 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
499 smpi_group_use(group);
500 } else if (n == smpi_group_size(group)) {
501 *newgroup = MPI_GROUP_EMPTY;
503 oldsize=smpi_group_size(group);
504 newsize = oldsize - n;
505 *newgroup = smpi_group_new(newsize);
507 int* to_exclude=xbt_new0(int, smpi_group_size(group));
508 for(i=0; i<oldsize; i++)
511 to_exclude[ranks[i]]=1;
514 for(i=0; i<oldsize; i++){
515 if(to_exclude[i]==0){
516 index = smpi_group_index(group, i);
517 smpi_group_set_mapping(*newgroup, index, j);
522 xbt_free(to_exclude);
524 retval = MPI_SUCCESS;
529 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
531 int retval, i, j, rank, size, index;
533 if (group == MPI_GROUP_NULL) {
534 retval = MPI_ERR_GROUP;
535 } else if (newgroup == NULL) {
536 retval = MPI_ERR_ARG;
539 *newgroup = MPI_GROUP_EMPTY;
542 for (i = 0; i < n; i++) {
543 for (rank = ranges[i][0]; /* First */
544 rank >= 0 && rank < smpi_group_size(group); /* Last */
547 if(rank == ranges[i][1]){/*already last ?*/
550 rank += ranges[i][2]; /* Stride */
551 if (ranges[i][0]<ranges[i][1]){
552 if(rank > ranges[i][1])
555 if(rank < ranges[i][1])
561 *newgroup = smpi_group_new(size);
563 for (i = 0; i < n; i++) {
564 for (rank = ranges[i][0]; /* First */
565 rank >= 0 && rank < smpi_group_size(group); /* Last */
567 index = smpi_group_index(group, rank);
568 smpi_group_set_mapping(*newgroup, index, j);
570 if(rank == ranges[i][1]){/*already last ?*/
573 rank += ranges[i][2]; /* Stride */
574 if (ranges[i][0]<ranges[i][1]){
575 if(rank > ranges[i][1])
578 if(rank < ranges[i][1])
584 retval = MPI_SUCCESS;
589 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup)
591 int retval, i, rank, newrank,oldrank, size, index, add;
593 if (group == MPI_GROUP_NULL) {
594 retval = MPI_ERR_GROUP;
595 } else if (newgroup == NULL) {
596 retval = MPI_ERR_ARG;
600 if(group!= smpi_comm_group(MPI_COMM_WORLD) && group != MPI_GROUP_NULL
601 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
602 smpi_group_use(group);
604 size = smpi_group_size(group);
605 for (i = 0; i < n; i++) {
606 for (rank = ranges[i][0]; /* First */
607 rank >= 0 && rank < smpi_group_size(group); /* Last */
610 if(rank == ranges[i][1]){/*already last ?*/
613 rank += ranges[i][2]; /* Stride */
614 if (ranges[i][0]<ranges[i][1]){
615 if(rank > ranges[i][1])
618 if(rank < ranges[i][1])
624 *newgroup = MPI_GROUP_EMPTY;
626 *newgroup = smpi_group_new(size);
629 while (newrank < size) {
631 for (i = 0; i < n; i++) {
632 for (rank = ranges[i][0];
633 rank >= 0 && rank < smpi_group_size(group);
639 if(rank == ranges[i][1]){/*already last ?*/
642 rank += ranges[i][2]; /* Stride */
643 if (ranges[i][0]<ranges[i][1]){
644 if(rank > ranges[i][1])
647 if(rank < ranges[i][1])
653 index = smpi_group_index(group, oldrank);
654 smpi_group_set_mapping(*newgroup, index, newrank);
662 retval = MPI_SUCCESS;
667 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
670 if (comm == MPI_COMM_NULL) {
671 retval = MPI_ERR_COMM;
672 } else if (rank == NULL) {
673 retval = MPI_ERR_ARG;
675 *rank = smpi_comm_rank(comm);
676 retval = MPI_SUCCESS;
681 int PMPI_Comm_size(MPI_Comm comm, int *size)
684 if (comm == MPI_COMM_NULL) {
685 retval = MPI_ERR_COMM;
686 } else if (size == NULL) {
687 retval = MPI_ERR_ARG;
689 *size = smpi_comm_size(comm);
690 retval = MPI_SUCCESS;
695 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
699 if (comm == MPI_COMM_NULL) {
700 retval = MPI_ERR_COMM;
701 } else if (name == NULL || len == NULL) {
702 retval = MPI_ERR_ARG;
704 smpi_comm_get_name(comm, name, len);
705 retval = MPI_SUCCESS;
710 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
714 if (comm == MPI_COMM_NULL) {
715 retval = MPI_ERR_COMM;
716 } else if (group == NULL) {
717 retval = MPI_ERR_ARG;
719 *group = smpi_comm_group(comm);
720 if(*group!= smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL
721 && *group != smpi_comm_group(MPI_COMM_SELF) && *group != MPI_GROUP_EMPTY)
722 smpi_group_use(*group);
723 retval = MPI_SUCCESS;
728 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
732 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
733 retval = MPI_ERR_COMM;
734 } else if (result == NULL) {
735 retval = MPI_ERR_ARG;
737 if (comm1 == comm2) { /* Same communicators means same groups */
740 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
741 if (*result == MPI_IDENT) {
742 *result = MPI_CONGRUENT;
745 retval = MPI_SUCCESS;
750 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
754 if (comm == MPI_COMM_NULL) {
755 retval = MPI_ERR_COMM;
756 } else if (newcomm == NULL) {
757 retval = MPI_ERR_ARG;
759 retval = smpi_comm_dup(comm, newcomm);
764 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
768 if (comm == MPI_COMM_NULL) {
769 retval = MPI_ERR_COMM;
770 } else if (group == MPI_GROUP_NULL) {
771 retval = MPI_ERR_GROUP;
772 } else if (newcomm == NULL) {
773 retval = MPI_ERR_ARG;
774 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
775 *newcomm= MPI_COMM_NULL;
776 retval = MPI_SUCCESS;
779 *newcomm = smpi_comm_new(group, NULL);
780 retval = MPI_SUCCESS;
785 int PMPI_Comm_free(MPI_Comm * comm)
790 retval = MPI_ERR_ARG;
791 } else if (*comm == MPI_COMM_NULL) {
792 retval = MPI_ERR_COMM;
794 smpi_comm_destroy(*comm);
795 *comm = MPI_COMM_NULL;
796 retval = MPI_SUCCESS;
801 int PMPI_Comm_disconnect(MPI_Comm * comm)
803 /* TODO: wait until all communication in comm are done */
807 retval = MPI_ERR_ARG;
808 } else if (*comm == MPI_COMM_NULL) {
809 retval = MPI_ERR_COMM;
811 smpi_comm_destroy(*comm);
812 *comm = MPI_COMM_NULL;
813 retval = MPI_SUCCESS;
818 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
823 if (comm_out == NULL) {
824 retval = MPI_ERR_ARG;
825 } else if (comm == MPI_COMM_NULL) {
826 retval = MPI_ERR_COMM;
828 *comm_out = smpi_comm_split(comm, color, key);
829 retval = MPI_SUCCESS;
836 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
841 if (request == NULL) {
842 retval = MPI_ERR_ARG;
843 } else if (comm == MPI_COMM_NULL) {
844 retval = MPI_ERR_COMM;
845 } else if (!is_datatype_valid(datatype)) {
846 retval = MPI_ERR_TYPE;
847 } else if (dst == MPI_PROC_NULL) {
848 retval = MPI_SUCCESS;
850 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
851 retval = MPI_SUCCESS;
854 if (retval != MPI_SUCCESS && request)
855 *request = MPI_REQUEST_NULL;
859 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
864 if (request == NULL) {
865 retval = MPI_ERR_ARG;
866 } else if (comm == MPI_COMM_NULL) {
867 retval = MPI_ERR_COMM;
868 } else if (!is_datatype_valid(datatype)) {
869 retval = MPI_ERR_TYPE;
870 } else if (src == MPI_PROC_NULL) {
871 retval = MPI_SUCCESS;
873 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
874 retval = MPI_SUCCESS;
877 if (retval != MPI_SUCCESS && request)
878 *request = MPI_REQUEST_NULL;
882 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
887 if (request == NULL) {
888 retval = MPI_ERR_ARG;
889 } else if (comm == MPI_COMM_NULL) {
890 retval = MPI_ERR_COMM;
891 } else if (!is_datatype_valid(datatype)) {
892 retval = MPI_ERR_TYPE;
893 } else if (dst == MPI_PROC_NULL) {
894 retval = MPI_SUCCESS;
896 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
897 retval = MPI_SUCCESS;
900 if (retval != MPI_SUCCESS && request)
901 *request = MPI_REQUEST_NULL;
905 int PMPI_Start(MPI_Request * request)
910 if (request == NULL || *request == MPI_REQUEST_NULL) {
911 retval = MPI_ERR_REQUEST;
913 smpi_mpi_start(*request);
914 retval = MPI_SUCCESS;
920 int PMPI_Startall(int count, MPI_Request * requests)
925 if (requests == NULL) {
926 retval = MPI_ERR_ARG;
928 retval = MPI_SUCCESS;
929 for (i = 0 ; i < count ; i++) {
930 if(requests[i] == MPI_REQUEST_NULL) {
931 retval = MPI_ERR_REQUEST;
934 if(retval != MPI_ERR_REQUEST) {
935 smpi_mpi_startall(count, requests);
942 int PMPI_Request_free(MPI_Request * request)
947 if (*request == MPI_REQUEST_NULL) {
948 retval = MPI_ERR_ARG;
950 smpi_mpi_request_free(request);
951 retval = MPI_SUCCESS;
957 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
963 if (request == NULL) {
964 retval = MPI_ERR_ARG;
965 } else if (comm == MPI_COMM_NULL) {
966 retval = MPI_ERR_COMM;
967 } else if (src == MPI_PROC_NULL) {
968 *request = MPI_REQUEST_NULL;
969 retval = MPI_SUCCESS;
970 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
971 retval = MPI_ERR_RANK;
972 } else if (count < 0) {
973 retval = MPI_ERR_COUNT;
974 } else if (buf==NULL && 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;
982 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
983 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
985 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
986 extra->type = TRACING_IRECV;
987 extra->src = src_traced;
990 extra->datatype1 = encode_datatype(datatype, &known);
991 int dt_size_send = 1;
993 dt_size_send = smpi_datatype_size(datatype);
994 extra->send_size = count*dt_size_send;
995 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
997 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
998 retval = MPI_SUCCESS;
1000 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1001 (*request)->recv = 1;
1005 if (retval != MPI_SUCCESS && request)
1006 *request = MPI_REQUEST_NULL;
1011 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1016 if (request == NULL) {
1017 retval = MPI_ERR_ARG;
1018 } else if (comm == MPI_COMM_NULL) {
1019 retval = MPI_ERR_COMM;
1020 } else if (dst == MPI_PROC_NULL) {
1021 *request = MPI_REQUEST_NULL;
1022 retval = MPI_SUCCESS;
1023 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1024 retval = MPI_ERR_RANK;
1025 } else if (count < 0) {
1026 retval = MPI_ERR_COUNT;
1027 } else if (buf==NULL && count > 0) {
1028 retval = MPI_ERR_COUNT;
1029 } else if (!is_datatype_valid(datatype)) {
1030 retval = MPI_ERR_TYPE;
1031 } else if(tag<0 && tag != MPI_ANY_TAG){
1032 retval = MPI_ERR_TAG;
1035 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1036 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1037 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1038 extra->type = TRACING_ISEND;
1040 extra->dst = dst_traced;
1042 extra->datatype1 = encode_datatype(datatype, &known);
1043 int dt_size_send = 1;
1045 dt_size_send = smpi_datatype_size(datatype);
1046 extra->send_size = count*dt_size_send;
1047 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1048 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1050 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1051 retval = MPI_SUCCESS;
1053 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1054 (*request)->send = 1;
1058 if (retval != MPI_SUCCESS && request)
1059 *request = MPI_REQUEST_NULL;
1063 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
1068 if (request == NULL) {
1069 retval = MPI_ERR_ARG;
1070 } else if (comm == MPI_COMM_NULL) {
1071 retval = MPI_ERR_COMM;
1072 } else if (dst == MPI_PROC_NULL) {
1073 *request = MPI_REQUEST_NULL;
1074 retval = MPI_SUCCESS;
1075 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1076 retval = MPI_ERR_RANK;
1077 } else if (count < 0) {
1078 retval = MPI_ERR_COUNT;
1079 } else if (buf==NULL && 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)
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) {
1129 retval = MPI_ERR_COUNT;
1130 } else if (buf==NULL && count > 0) {
1131 retval = MPI_ERR_COUNT;
1132 } else if (!is_datatype_valid(datatype)) {
1133 retval = MPI_ERR_TYPE;
1134 } else if(tag<0 && tag != MPI_ANY_TAG){
1135 retval = MPI_ERR_TAG;
1137 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1138 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1139 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1140 extra->type = TRACING_RECV;
1141 extra->src = src_traced;
1144 extra->datatype1 = encode_datatype(datatype, &known);
1145 int dt_size_send = 1;
1147 dt_size_send = smpi_datatype_size(datatype);
1148 extra->send_size = count*dt_size_send;
1149 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1151 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1152 retval = MPI_SUCCESS;
1154 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1155 if(status!=MPI_STATUS_IGNORE){
1156 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1157 if (!TRACE_smpi_view_internals()) {
1158 TRACE_smpi_recv(rank, src_traced, rank);
1161 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1168 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1174 if (comm == MPI_COMM_NULL) {
1175 retval = MPI_ERR_COMM;
1176 } else if (dst == MPI_PROC_NULL) {
1177 retval = MPI_SUCCESS;
1178 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1179 retval = MPI_ERR_RANK;
1180 } else if (count < 0) {
1181 retval = MPI_ERR_COUNT;
1182 } else if (buf==NULL && count > 0) {
1183 retval = MPI_ERR_COUNT;
1184 } else if (!is_datatype_valid(datatype)) {
1185 retval = MPI_ERR_TYPE;
1186 } else if(tag<0 && tag != MPI_ANY_TAG){
1187 retval = MPI_ERR_TAG;
1190 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1191 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1192 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1193 extra->type = TRACING_SEND;
1195 extra->dst = dst_traced;
1197 extra->datatype1 = encode_datatype(datatype, &known);
1198 int dt_size_send = 1;
1200 dt_size_send = smpi_datatype_size(datatype);
1201 extra->send_size = count*dt_size_send;
1202 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1203 if (!TRACE_smpi_view_internals()) {
1204 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1207 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1208 retval = MPI_SUCCESS;
1210 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1219 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1224 if (comm == MPI_COMM_NULL) {
1225 retval = MPI_ERR_COMM;
1226 } else if (dst == MPI_PROC_NULL) {
1227 retval = MPI_SUCCESS;
1228 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1229 retval = MPI_ERR_RANK;
1230 } else if (count < 0) {
1231 retval = MPI_ERR_COUNT;
1232 } else if (buf==NULL && count > 0) {
1233 retval = MPI_ERR_COUNT;
1234 } else if (!is_datatype_valid(datatype)){
1235 retval = MPI_ERR_TYPE;
1236 } else if(tag<0 && tag != MPI_ANY_TAG){
1237 retval = MPI_ERR_TAG;
1240 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1241 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1242 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1243 extra->type = TRACING_SSEND;
1245 extra->dst = dst_traced;
1247 extra->datatype1 = encode_datatype(datatype, &known);
1248 int dt_size_send = 1;
1250 dt_size_send = smpi_datatype_size(datatype);
1251 extra->send_size = count*dt_size_send;
1252 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1253 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1255 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1256 retval = MPI_SUCCESS;
1258 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1264 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1265 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1271 if (comm == MPI_COMM_NULL) {
1272 retval = MPI_ERR_COMM;
1273 } else if (!is_datatype_valid(sendtype)
1274 || !is_datatype_valid(recvtype)) {
1275 retval = MPI_ERR_TYPE;
1276 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1277 smpi_empty_status(status);
1278 status->MPI_SOURCE = MPI_PROC_NULL;
1279 retval = MPI_SUCCESS;
1280 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1281 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1282 retval = MPI_ERR_RANK;
1283 } else if (sendcount < 0 || recvcount<0) {
1284 retval = MPI_ERR_COUNT;
1285 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1286 retval = MPI_ERR_COUNT;
1287 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1288 retval = MPI_ERR_TAG;
1291 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1292 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1293 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1294 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1295 extra->type = TRACING_SENDRECV;
1296 extra->src = src_traced;
1297 extra->dst = dst_traced;
1299 extra->datatype1 = encode_datatype(sendtype, &known);
1300 int dt_size_send = 1;
1302 dt_size_send = smpi_datatype_size(sendtype);
1303 extra->send_size = sendcount*dt_size_send;
1304 extra->datatype2 = encode_datatype(recvtype, &known);
1305 int dt_size_recv = 1;
1307 dt_size_recv = smpi_datatype_size(recvtype);
1308 extra->recv_size = recvcount*dt_size_recv;
1310 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1311 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1313 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1314 recvcount, recvtype, src, recvtag, comm, status);
1315 retval = MPI_SUCCESS;
1317 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1318 TRACE_smpi_recv(rank, src_traced, rank);
1325 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1326 MPI_Comm comm, MPI_Status * status)
1328 //TODO: suboptimal implementation
1331 if (!is_datatype_valid(datatype)) {
1332 retval = MPI_ERR_TYPE;
1333 } else if (count < 0) {
1334 retval = MPI_ERR_COUNT;
1336 int size = smpi_datatype_get_extent(datatype) * count;
1337 recvbuf = xbt_new0(char, size);
1338 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1339 if(retval==MPI_SUCCESS){
1340 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1348 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1352 if (request == NULL || flag == NULL) {
1353 retval = MPI_ERR_ARG;
1354 } else if (*request == MPI_REQUEST_NULL) {
1356 smpi_empty_status(status);
1357 retval = MPI_SUCCESS;
1359 int rank = request && (*request)->comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1361 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1362 extra->type = TRACING_TEST;
1363 TRACE_smpi_testing_in(rank, extra);
1365 *flag = smpi_mpi_test(request, status);
1367 TRACE_smpi_testing_out(rank);
1368 retval = MPI_SUCCESS;
1374 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1379 if (index == NULL || flag == NULL) {
1380 retval = MPI_ERR_ARG;
1382 *flag = smpi_mpi_testany(count, requests, index, status);
1383 retval = MPI_SUCCESS;
1389 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1395 retval = MPI_ERR_ARG;
1397 *flag = smpi_mpi_testall(count, requests, statuses);
1398 retval = MPI_SUCCESS;
1404 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1408 if (status == NULL) {
1409 retval = MPI_ERR_ARG;
1410 } else if (comm == MPI_COMM_NULL) {
1411 retval = MPI_ERR_COMM;
1412 } else if (source == MPI_PROC_NULL) {
1413 smpi_empty_status(status);
1414 status->MPI_SOURCE = MPI_PROC_NULL;
1415 retval = MPI_SUCCESS;
1417 smpi_mpi_probe(source, tag, comm, status);
1418 retval = MPI_SUCCESS;
1424 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1429 retval = MPI_ERR_ARG;
1430 } else if (status == NULL) {
1431 retval = MPI_ERR_ARG;
1432 } else if (comm == MPI_COMM_NULL) {
1433 retval = MPI_ERR_COMM;
1434 } else if (source == MPI_PROC_NULL) {
1436 smpi_empty_status(status);
1437 status->MPI_SOURCE = MPI_PROC_NULL;
1438 retval = MPI_SUCCESS;
1440 smpi_mpi_iprobe(source, tag, comm, flag, status);
1441 retval = MPI_SUCCESS;
1447 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1453 smpi_empty_status(status);
1455 if (request == NULL) {
1456 retval = MPI_ERR_ARG;
1457 } else if (*request == MPI_REQUEST_NULL) {
1458 retval = MPI_SUCCESS;
1461 int rank = request && (*request)->comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1463 int src_traced = (*request)->src;
1464 int dst_traced = (*request)->dst;
1465 MPI_Comm comm = (*request)->comm;
1466 int is_wait_for_receive = (*request)->recv;
1467 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1468 extra->type = TRACING_WAIT;
1469 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1471 smpi_mpi_wait(request, status);
1472 retval = MPI_SUCCESS;
1474 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1475 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1476 if (is_wait_for_receive) {
1477 if(src_traced==MPI_ANY_SOURCE)
1478 src_traced = (status!=MPI_STATUS_IGNORE) ?
1479 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1481 TRACE_smpi_recv(rank, src_traced, dst_traced);
1489 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1495 //save requests information for tracing
1497 int *srcs = xbt_new0(int, count);
1498 int *dsts = xbt_new0(int, count);
1499 int *recvs = xbt_new0(int, count);
1500 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1502 for (i = 0; i < count; i++) {
1503 MPI_Request req = requests[i]; //already received requests are no longer valid
1507 recvs[i] = req->recv;
1508 comms[i] = req->comm;
1511 int rank_traced = smpi_process_index();
1512 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1513 extra->type = TRACING_WAITANY;
1514 extra->send_size=count;
1515 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1517 *index = smpi_mpi_waitany(count, requests, status);
1519 if(*index!=MPI_UNDEFINED){
1520 int src_traced = srcs[*index];
1521 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1522 int dst_traced = dsts[*index];
1523 int is_wait_for_receive = recvs[*index];
1524 if (is_wait_for_receive) {
1525 if(srcs[*index]==MPI_ANY_SOURCE)
1526 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1527 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) : srcs[*index];
1528 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1530 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1541 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1544 //save information from requests
1546 int *srcs = xbt_new0(int, count);
1547 int *dsts = xbt_new0(int, count);
1548 int *recvs = xbt_new0(int, count);
1549 int *valid = xbt_new0(int, count);
1550 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1552 //int valid_count = 0;
1553 for (i = 0; i < count; i++) {
1554 MPI_Request req = requests[i];
1555 if(req!=MPI_REQUEST_NULL){
1558 recvs[i] = req->recv;
1559 comms[i] = req->comm;
1565 int rank_traced = smpi_process_index();
1566 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1567 extra->type = TRACING_WAITALL;
1568 extra->send_size=count;
1569 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1571 int retval = smpi_mpi_waitall(count, requests, status);
1573 for (i = 0; i < count; i++) {
1575 //int src_traced = srcs[*index];
1576 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1577 int src_traced = srcs[i];
1578 int dst_traced = dsts[i];
1579 int is_wait_for_receive = recvs[i];
1580 if (is_wait_for_receive) {
1581 if(src_traced==MPI_ANY_SOURCE)
1582 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1583 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) : srcs[i];
1584 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1588 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1599 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1604 if (outcount == NULL) {
1605 retval = MPI_ERR_ARG;
1607 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1608 retval = MPI_SUCCESS;
1614 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1619 if (outcount == NULL) {
1620 retval = MPI_ERR_ARG;
1622 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1623 retval = MPI_SUCCESS;
1630 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1636 if (comm == MPI_COMM_NULL) {
1637 retval = MPI_ERR_COMM;
1638 } else if (!is_datatype_valid(datatype)) {
1639 retval = MPI_ERR_ARG;
1641 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1642 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1644 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1645 extra->type = TRACING_BCAST;
1646 extra->root = root_traced;
1648 extra->datatype1 = encode_datatype(datatype, &known);
1649 int dt_size_send = 1;
1651 dt_size_send = smpi_datatype_size(datatype);
1652 extra->send_size = count*dt_size_send;
1653 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1655 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1656 retval = MPI_SUCCESS;
1658 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1665 int PMPI_Barrier(MPI_Comm comm)
1671 if (comm == MPI_COMM_NULL) {
1672 retval = MPI_ERR_COMM;
1674 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1675 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1676 extra->type = TRACING_BARRIER;
1677 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1679 mpi_coll_barrier_fun(comm);
1680 retval = MPI_SUCCESS;
1682 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1689 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1690 int root, MPI_Comm comm)
1696 if (comm == MPI_COMM_NULL) {
1697 retval = MPI_ERR_COMM;
1698 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1699 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1700 retval = MPI_ERR_TYPE;
1701 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1702 retval = MPI_ERR_COUNT;
1705 char* sendtmpbuf = (char*) sendbuf;
1706 int sendtmpcount = sendcount;
1707 MPI_Datatype sendtmptype = sendtype;
1708 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1710 sendtmptype=recvtype;
1712 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1713 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1714 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1715 extra->type = TRACING_GATHER;
1716 extra->root = root_traced;
1718 extra->datatype1 = encode_datatype(sendtmptype, &known);
1719 int dt_size_send = 1;
1721 dt_size_send = smpi_datatype_size(sendtmptype);
1722 extra->send_size = sendtmpcount*dt_size_send;
1723 extra->datatype2 = encode_datatype(recvtype, &known);
1724 int dt_size_recv = 1;
1725 if((smpi_comm_rank(comm)==root) && !known)
1726 dt_size_recv = smpi_datatype_size(recvtype);
1727 extra->recv_size = recvcount*dt_size_recv;
1729 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1731 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1733 retval = MPI_SUCCESS;
1734 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1741 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1742 MPI_Datatype recvtype, int root, MPI_Comm comm)
1748 if (comm == MPI_COMM_NULL) {
1749 retval = MPI_ERR_COMM;
1750 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1751 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1752 retval = MPI_ERR_TYPE;
1753 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1754 retval = MPI_ERR_COUNT;
1755 } else if (recvcounts == NULL || displs == NULL) {
1756 retval = MPI_ERR_ARG;
1758 char* sendtmpbuf = (char*) sendbuf;
1759 int sendtmpcount = sendcount;
1760 MPI_Datatype sendtmptype = sendtype;
1761 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1763 sendtmptype=recvtype;
1766 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1767 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1769 int size = smpi_comm_size(comm);
1770 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1771 extra->type = TRACING_GATHERV;
1772 extra->num_processes = size;
1773 extra->root = root_traced;
1775 extra->datatype1 = encode_datatype(sendtmptype, &known);
1776 int dt_size_send = 1;
1778 dt_size_send = smpi_datatype_size(sendtype);
1779 extra->send_size = sendtmpcount*dt_size_send;
1780 extra->datatype2 = encode_datatype(recvtype, &known);
1781 int dt_size_recv = 1;
1783 dt_size_recv = smpi_datatype_size(recvtype);
1784 if((smpi_comm_rank(comm)==root)){
1785 extra->recvcounts= xbt_new(int,size);
1786 for(i=0; i< size; i++)//copy data to avoid bad free
1787 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1789 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1791 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1792 retval = MPI_SUCCESS;
1793 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1800 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1801 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1807 if (comm == MPI_COMM_NULL) {
1808 retval = MPI_ERR_COMM;
1809 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1810 (recvtype == MPI_DATATYPE_NULL)){
1811 retval = MPI_ERR_TYPE;
1812 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1814 retval = MPI_ERR_COUNT;
1816 if(sendbuf == MPI_IN_PLACE) {
1817 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1818 sendcount=recvcount;
1821 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1822 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1823 extra->type = TRACING_ALLGATHER;
1825 extra->datatype1 = encode_datatype(sendtype, &known);
1826 int dt_size_send = 1;
1828 dt_size_send = smpi_datatype_size(sendtype);
1829 extra->send_size = sendcount*dt_size_send;
1830 extra->datatype2 = encode_datatype(recvtype, &known);
1831 int dt_size_recv = 1;
1833 dt_size_recv = smpi_datatype_size(recvtype);
1834 extra->recv_size = recvcount*dt_size_recv;
1836 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1838 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1839 retval = MPI_SUCCESS;
1840 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1846 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1847 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1853 if (comm == MPI_COMM_NULL) {
1854 retval = MPI_ERR_COMM;
1855 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1856 (recvtype == MPI_DATATYPE_NULL)){
1857 retval = MPI_ERR_TYPE;
1858 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1859 retval = MPI_ERR_COUNT;
1860 } else if (recvcounts == NULL || displs == NULL) {
1861 retval = MPI_ERR_ARG;
1864 if(sendbuf == MPI_IN_PLACE) {
1865 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1866 sendcount=recvcounts[smpi_comm_rank(comm)];
1869 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1871 int size = smpi_comm_size(comm);
1872 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1873 extra->type = TRACING_ALLGATHERV;
1874 extra->num_processes = size;
1876 extra->datatype1 = encode_datatype(sendtype, &known);
1877 int dt_size_send = 1;
1879 dt_size_send = smpi_datatype_size(sendtype);
1880 extra->send_size = sendcount*dt_size_send;
1881 extra->datatype2 = encode_datatype(recvtype, &known);
1882 int dt_size_recv = 1;
1884 dt_size_recv = smpi_datatype_size(recvtype);
1885 extra->recvcounts= xbt_new(int, size);
1886 for(i=0; i< size; i++)//copy data to avoid bad free
1887 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1889 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1891 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1892 retval = MPI_SUCCESS;
1893 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1900 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1901 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1907 if (comm == MPI_COMM_NULL) {
1908 retval = MPI_ERR_COMM;
1909 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1910 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1911 retval = MPI_ERR_TYPE;
1912 } else if ((sendbuf == recvbuf) ||
1913 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
1914 retval = MPI_ERR_BUFFER;
1917 if (recvbuf == MPI_IN_PLACE) {
1919 recvcount=sendcount;
1921 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1922 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1923 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1924 extra->type = TRACING_SCATTER;
1925 extra->root = root_traced;
1927 extra->datatype1 = encode_datatype(sendtype, &known);
1928 int dt_size_send = 1;
1929 if((smpi_comm_rank(comm)==root) && !known)
1930 dt_size_send = smpi_datatype_size(sendtype);
1931 extra->send_size = sendcount*dt_size_send;
1932 extra->datatype2 = encode_datatype(recvtype, &known);
1933 int dt_size_recv = 1;
1935 dt_size_recv = smpi_datatype_size(recvtype);
1936 extra->recv_size = recvcount*dt_size_recv;
1937 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1939 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1940 retval = MPI_SUCCESS;
1941 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1948 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1949 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1955 if (comm == MPI_COMM_NULL) {
1956 retval = MPI_ERR_COMM;
1957 } else if (sendcounts == NULL || displs == NULL) {
1958 retval = MPI_ERR_ARG;
1959 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1960 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1961 retval = MPI_ERR_TYPE;
1963 if (recvbuf == MPI_IN_PLACE) {
1965 recvcount=sendcounts[smpi_comm_rank(comm)];
1967 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1968 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1970 int size = smpi_comm_size(comm);
1971 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1972 extra->type = TRACING_SCATTERV;
1973 extra->num_processes = size;
1974 extra->root = root_traced;
1976 extra->datatype1 = encode_datatype(sendtype, &known);
1977 int dt_size_send = 1;
1979 dt_size_send = smpi_datatype_size(sendtype);
1980 if((smpi_comm_rank(comm)==root)){
1981 extra->sendcounts= xbt_new(int, size);
1982 for(i=0; i< size; i++)//copy data to avoid bad free
1983 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
1985 extra->datatype2 = encode_datatype(recvtype, &known);
1986 int dt_size_recv = 1;
1988 dt_size_recv = smpi_datatype_size(recvtype);
1989 extra->recv_size = recvcount*dt_size_recv;
1990 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1992 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1994 retval = MPI_SUCCESS;
1995 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2002 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2008 if (comm == MPI_COMM_NULL) {
2009 retval = MPI_ERR_COMM;
2010 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2011 retval = MPI_ERR_ARG;
2013 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2014 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2015 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2016 extra->type = TRACING_REDUCE;
2018 extra->datatype1 = encode_datatype(datatype, &known);
2019 int dt_size_send = 1;
2021 dt_size_send = smpi_datatype_size(datatype);
2022 extra->send_size = count*dt_size_send;
2023 extra->root = root_traced;
2025 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2027 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2029 retval = MPI_SUCCESS;
2030 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2037 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2041 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2042 retval = MPI_ERR_ARG;
2044 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2051 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2057 if (comm == MPI_COMM_NULL) {
2058 retval = MPI_ERR_COMM;
2059 } else if (!is_datatype_valid(datatype)) {
2060 retval = MPI_ERR_TYPE;
2061 } else if (op == MPI_OP_NULL) {
2062 retval = MPI_ERR_OP;
2065 char* sendtmpbuf = (char*) sendbuf;
2066 if( sendbuf == MPI_IN_PLACE ) {
2067 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2068 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2070 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2071 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2072 extra->type = TRACING_ALLREDUCE;
2074 extra->datatype1 = encode_datatype(datatype, &known);
2075 int dt_size_send = 1;
2077 dt_size_send = smpi_datatype_size(datatype);
2078 extra->send_size = count*dt_size_send;
2080 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2082 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2084 if( sendbuf == MPI_IN_PLACE )
2085 xbt_free(sendtmpbuf);
2087 retval = MPI_SUCCESS;
2088 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2095 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2101 if (comm == MPI_COMM_NULL) {
2102 retval = MPI_ERR_COMM;
2103 } else if (!is_datatype_valid(datatype)) {
2104 retval = MPI_ERR_TYPE;
2105 } else if (op == MPI_OP_NULL) {
2106 retval = MPI_ERR_OP;
2108 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2109 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2110 extra->type = TRACING_SCAN;
2112 extra->datatype1 = encode_datatype(datatype, &known);
2113 int dt_size_send = 1;
2115 dt_size_send = smpi_datatype_size(datatype);
2116 extra->send_size = count*dt_size_send;
2118 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2120 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2122 retval = MPI_SUCCESS;
2123 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2130 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2135 if (comm == MPI_COMM_NULL) {
2136 retval = MPI_ERR_COMM;
2137 } else if (!is_datatype_valid(datatype)) {
2138 retval = MPI_ERR_TYPE;
2139 } else if (op == MPI_OP_NULL) {
2140 retval = MPI_ERR_OP;
2142 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2143 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2144 extra->type = TRACING_EXSCAN;
2146 extra->datatype1 = encode_datatype(datatype, &known);
2147 int dt_size_send = 1;
2149 dt_size_send = smpi_datatype_size(datatype);
2150 extra->send_size = count*dt_size_send;
2151 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2153 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2154 retval = MPI_SUCCESS;
2155 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2162 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2167 if (comm == MPI_COMM_NULL) {
2168 retval = MPI_ERR_COMM;
2169 } else if (!is_datatype_valid(datatype)) {
2170 retval = MPI_ERR_TYPE;
2171 } else if (op == MPI_OP_NULL) {
2172 retval = MPI_ERR_OP;
2173 } else if (recvcounts == NULL) {
2174 retval = MPI_ERR_ARG;
2176 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2178 int size = smpi_comm_size(comm);
2179 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2180 extra->type = TRACING_REDUCE_SCATTER;
2181 extra->num_processes = size;
2183 extra->datatype1 = encode_datatype(datatype, &known);
2184 int dt_size_send = 1;
2186 dt_size_send = smpi_datatype_size(datatype);
2187 extra->send_size = 0;
2188 extra->recvcounts= xbt_new(int, size);
2189 for(i=0; i< size; i++)//copy data to avoid bad free
2190 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2191 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2193 void* sendtmpbuf=sendbuf;
2194 if(sendbuf==MPI_IN_PLACE)
2197 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2198 retval = MPI_SUCCESS;
2199 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2206 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2207 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2212 if (comm == MPI_COMM_NULL) {
2213 retval = MPI_ERR_COMM;
2214 } else if (!is_datatype_valid(datatype)) {
2215 retval = MPI_ERR_TYPE;
2216 } else if (op == MPI_OP_NULL) {
2217 retval = MPI_ERR_OP;
2218 } else if (recvcount < 0) {
2219 retval = MPI_ERR_ARG;
2221 int count=smpi_comm_size(comm);
2223 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2224 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2225 extra->type = TRACING_REDUCE_SCATTER;
2226 extra->num_processes = count;
2228 extra->datatype1 = encode_datatype(datatype, &known);
2229 int dt_size_send = 1;
2231 dt_size_send = smpi_datatype_size(datatype);
2232 extra->send_size = 0;
2233 extra->recvcounts= xbt_new(int, count);
2234 for(i=0; i< count; i++)//copy data to avoid bad free
2235 extra->recvcounts[i] = recvcount*dt_size_send;
2237 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2239 int* recvcounts=(int*)xbt_malloc(count);
2240 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2241 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts, datatype, op, comm);
2242 xbt_free(recvcounts);
2243 retval = MPI_SUCCESS;
2245 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2252 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2253 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2259 if (comm == MPI_COMM_NULL) {
2260 retval = MPI_ERR_COMM;
2261 } else if (sendtype == MPI_DATATYPE_NULL
2262 || recvtype == MPI_DATATYPE_NULL) {
2263 retval = MPI_ERR_TYPE;
2265 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2266 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2267 extra->type = TRACING_ALLTOALL;
2269 extra->datatype1 = encode_datatype(sendtype, &known);
2271 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2273 extra->send_size = sendcount;
2274 extra->datatype2 = encode_datatype(recvtype, &known);
2276 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2278 extra->recv_size = recvcount;
2279 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2281 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2283 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2290 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2291 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2297 if (comm == MPI_COMM_NULL) {
2298 retval = MPI_ERR_COMM;
2299 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2300 retval = MPI_ERR_TYPE;
2301 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL || recvdisps == NULL) {
2302 retval = MPI_ERR_ARG;
2304 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2306 int size = smpi_comm_size(comm);
2307 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2308 extra->type = TRACING_ALLTOALLV;
2309 extra->send_size = 0;
2310 extra->recv_size = 0;
2311 extra->recvcounts= xbt_new(int, size);
2312 extra->sendcounts= xbt_new(int, size);
2314 extra->datatype1 = encode_datatype(sendtype, &known);
2315 int dt_size_send = 1;
2317 dt_size_send = smpi_datatype_size(sendtype);
2318 int dt_size_recv = 1;
2319 extra->datatype2 = encode_datatype(recvtype, &known);
2321 dt_size_recv = smpi_datatype_size(recvtype);
2322 for(i=0; i< size; i++){//copy data to avoid bad free
2323 extra->send_size += sendcounts[i]*dt_size_send;
2324 extra->recv_size += recvcounts[i]*dt_size_recv;
2326 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2327 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2329 extra->num_processes = size;
2330 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2332 retval = mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype,
2334 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2342 int PMPI_Get_processor_name(char *name, int *resultlen)
2344 int retval = MPI_SUCCESS;
2346 strncpy(name, sg_host_get_name(SIMIX_host_self()),
2347 strlen(sg_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2348 strlen(sg_host_get_name(SIMIX_host_self())) +1 : MPI_MAX_PROCESSOR_NAME - 1 );
2349 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2354 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2356 int retval = MPI_SUCCESS;
2359 if (status == NULL || count == NULL) {
2360 retval = MPI_ERR_ARG;
2361 } else if (!is_datatype_valid(datatype)) {
2362 retval = MPI_ERR_TYPE;
2364 size = smpi_datatype_size(datatype);
2367 } else if (status->count % size != 0) {
2368 retval = MPI_UNDEFINED;
2370 *count = smpi_mpi_get_count(status, datatype);
2376 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2379 if (old_type == MPI_DATATYPE_NULL) {
2380 retval = MPI_ERR_TYPE;
2381 } else if (count<0){
2382 retval = MPI_ERR_COUNT;
2384 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2389 int PMPI_Type_commit(MPI_Datatype* datatype) {
2392 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2393 retval = MPI_ERR_TYPE;
2395 smpi_datatype_commit(datatype);
2396 retval = MPI_SUCCESS;
2401 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2404 if (old_type == MPI_DATATYPE_NULL) {
2405 retval = MPI_ERR_TYPE;
2406 } else if (count<0 || blocklen<0){
2407 retval = MPI_ERR_COUNT;
2409 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2414 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2417 if (old_type == MPI_DATATYPE_NULL) {
2418 retval = MPI_ERR_TYPE;
2419 } else if (count<0 || blocklen<0){
2420 retval = MPI_ERR_COUNT;
2422 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2427 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2428 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2431 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2434 if (old_type == MPI_DATATYPE_NULL) {
2435 retval = MPI_ERR_TYPE;
2436 } else if (count<0){
2437 retval = MPI_ERR_COUNT;
2439 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2444 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2447 if (old_type == MPI_DATATYPE_NULL) {
2448 retval = MPI_ERR_TYPE;
2449 } else if (count<0){
2450 retval = MPI_ERR_COUNT;
2452 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2457 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2458 MPI_Datatype* new_type) {
2461 if (old_type == MPI_DATATYPE_NULL) {
2462 retval = MPI_ERR_TYPE;
2463 } else if (count<0){
2464 retval = MPI_ERR_COUNT;
2466 int* blocklens=(int*)xbt_malloc(blocklength*count);
2467 for (i=0; i<count;i++)blocklens[i]=blocklength;
2468 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2469 xbt_free(blocklens);
2474 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2477 if (old_type == MPI_DATATYPE_NULL) {
2478 retval = MPI_ERR_TYPE;
2479 } else if (count<0){
2480 retval = MPI_ERR_COUNT;
2482 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2487 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2488 MPI_Datatype* new_type) {
2489 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2492 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2493 MPI_Datatype* new_type) {
2496 if (old_type == MPI_DATATYPE_NULL) {
2497 retval = MPI_ERR_TYPE;
2498 } else if (count<0){
2499 retval = MPI_ERR_COUNT;
2501 int* blocklens=(int*)xbt_malloc(blocklength*count);
2502 for (i=0; i<count;i++)blocklens[i]=blocklength;
2503 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2504 xbt_free(blocklens);
2509 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2513 retval = MPI_ERR_COUNT;
2515 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2520 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2521 MPI_Datatype* new_type) {
2522 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2525 int PMPI_Error_class(int errorcode, int* errorclass) {
2526 // assume smpi uses only standard mpi error codes
2527 *errorclass=errorcode;
2531 int PMPI_Initialized(int* flag) {
2532 *flag=smpi_process_initialized();
2536 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies will be implemented, not only should we
2537 * check if the topology is NULL, but we should check if it is the good topology type (so we have to add a
2538 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2540 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2542 if (comm_old == MPI_COMM_NULL){
2543 retval = MPI_ERR_COMM;
2544 } else if (ndims < 0 || (ndims > 0 && (dims == NULL || periodic == NULL)) || comm_cart == NULL) {
2545 retval = MPI_ERR_ARG;
2547 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2552 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2553 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2554 return MPI_ERR_TOPOLOGY;
2556 if (coords == NULL) {
2559 return smpi_mpi_cart_rank(comm, coords, rank);
2562 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2563 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2564 return MPI_ERR_TOPOLOGY;
2566 if (source == NULL || dest == NULL || direction < 0 ) {
2569 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2572 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2573 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2574 return MPI_ERR_TOPOLOGY;
2576 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2577 return MPI_ERR_RANK;
2582 if(coords == NULL) {
2585 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2588 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2589 if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2590 return MPI_ERR_TOPOLOGY;
2592 if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2595 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2598 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2599 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2600 return MPI_ERR_TOPOLOGY;
2602 if (ndims == NULL) {
2605 return smpi_mpi_cartdim_get(comm, ndims);
2608 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2612 if (ndims < 1 || nnodes < 1) {
2613 return MPI_ERR_DIMS;
2616 return smpi_mpi_dims_create(nnodes, ndims, dims);
2619 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2620 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2621 return MPI_ERR_TOPOLOGY;
2623 if (comm_new == NULL) {
2626 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2629 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2630 if(oldtype == MPI_DATATYPE_NULL) {
2631 return MPI_ERR_TYPE;
2633 int blocks[3] = { 1, 1, 1 };
2634 MPI_Aint disps[3] = { lb, 0, lb+extent };
2635 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2637 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2638 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2640 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2644 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2647 if (comm == MPI_COMM_NULL) {
2648 retval= MPI_ERR_COMM;
2649 }else if ((base == NULL && size != 0) || disp_unit <= 0 || size < 0 ){
2650 retval= MPI_ERR_OTHER;
2652 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2653 retval = MPI_SUCCESS;
2659 int PMPI_Win_free( MPI_Win* win){
2662 if (win == NULL || *win == MPI_WIN_NULL) {
2663 retval = MPI_ERR_WIN;
2665 retval=smpi_mpi_win_free(win);
2671 int PMPI_Win_set_name(MPI_Win win, char * name)
2674 if (win == MPI_WIN_NULL) {
2675 retval = MPI_ERR_TYPE;
2676 } else if (name == NULL) {
2677 retval = MPI_ERR_ARG;
2679 smpi_mpi_win_set_name(win, name);
2680 retval = MPI_SUCCESS;
2685 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2687 int retval = MPI_SUCCESS;
2689 if (win == MPI_WIN_NULL) {
2690 retval = MPI_ERR_WIN;
2691 } else if (name == NULL) {
2692 retval = MPI_ERR_ARG;
2694 smpi_mpi_win_get_name(win, name, len);
2699 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2700 int retval = MPI_SUCCESS;
2701 if (win == MPI_WIN_NULL) {
2702 retval = MPI_ERR_WIN;
2704 smpi_mpi_win_get_group(win, group);
2710 int PMPI_Win_fence( int assert, MPI_Win win){
2713 if (win == MPI_WIN_NULL) {
2714 retval = MPI_ERR_WIN;
2716 int rank = smpi_process_index();
2717 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2718 retval = smpi_mpi_win_fence(assert, win);
2719 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2725 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2726 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2729 if (win == MPI_WIN_NULL) {
2730 retval = MPI_ERR_WIN;
2731 } else if (target_rank == MPI_PROC_NULL) {
2732 retval = MPI_SUCCESS;
2733 } else if (target_rank <0){
2734 retval = MPI_ERR_RANK;
2735 } else if (target_disp <0){
2736 retval = MPI_ERR_ARG;
2737 } else if (origin_count < 0 || target_count < 0) {
2738 retval = MPI_ERR_COUNT;
2739 } else if (origin_addr==NULL && origin_count > 0){
2740 retval = MPI_ERR_COUNT;
2741 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2742 retval = MPI_ERR_TYPE;
2744 int rank = smpi_process_index();
2746 smpi_mpi_win_get_group(win, &group);
2747 int src_traced = smpi_group_index(group, target_rank);
2748 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2750 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2751 target_datatype, win);
2753 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2759 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2760 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2763 if (win == MPI_WIN_NULL) {
2764 retval = MPI_ERR_WIN;
2765 } else if (target_rank == MPI_PROC_NULL) {
2766 retval = MPI_SUCCESS;
2767 } else if (target_rank <0){
2768 retval = MPI_ERR_RANK;
2769 } else if (target_disp <0){
2770 retval = MPI_ERR_ARG;
2771 } else if (origin_count < 0 || target_count < 0) {
2772 retval = MPI_ERR_COUNT;
2773 } else if (origin_addr==NULL && origin_count > 0){
2774 retval = MPI_ERR_COUNT;
2775 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2776 retval = MPI_ERR_TYPE;
2778 int rank = smpi_process_index();
2780 smpi_mpi_win_get_group(win, &group);
2781 int dst_traced = smpi_group_index(group, target_rank);
2782 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, NULL);
2783 TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2785 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2786 target_datatype, win);
2788 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2794 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2795 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2798 if (win == MPI_WIN_NULL) {
2799 retval = MPI_ERR_WIN;
2800 } else if (target_rank == MPI_PROC_NULL) {
2801 retval = MPI_SUCCESS;
2802 } else if (target_rank <0){
2803 retval = MPI_ERR_RANK;
2804 } else if (target_disp <0){
2805 retval = MPI_ERR_ARG;
2806 } else if (origin_count < 0 || target_count < 0) {
2807 retval = MPI_ERR_COUNT;
2808 } else if (origin_addr==NULL && origin_count > 0){
2809 retval = MPI_ERR_COUNT;
2810 } else if ((!is_datatype_valid(origin_datatype)) ||
2811 (!is_datatype_valid(target_datatype))) {
2812 retval = MPI_ERR_TYPE;
2813 } else if (op == MPI_OP_NULL) {
2814 retval = MPI_ERR_OP;
2816 int rank = smpi_process_index();
2818 smpi_mpi_win_get_group(win, &group);
2819 int src_traced = smpi_group_index(group, target_rank);
2820 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2822 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2823 target_datatype, op, win);
2825 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2831 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2834 if (win == MPI_WIN_NULL) {
2835 retval = MPI_ERR_WIN;
2836 } else if (group==MPI_GROUP_NULL){
2837 retval = MPI_ERR_GROUP;
2840 int rank = smpi_process_index();
2841 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2842 retval = smpi_mpi_win_post(group,assert,win);
2843 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2849 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2852 if (win == MPI_WIN_NULL) {
2853 retval = MPI_ERR_WIN;
2854 } else if (group==MPI_GROUP_NULL){
2855 retval = MPI_ERR_GROUP;
2858 int rank = smpi_process_index();
2859 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2860 retval = smpi_mpi_win_start(group,assert,win);
2861 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2867 int PMPI_Win_complete(MPI_Win win){
2870 if (win == MPI_WIN_NULL) {
2871 retval = MPI_ERR_WIN;
2874 int rank = smpi_process_index();
2875 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2877 retval = smpi_mpi_win_complete(win);
2879 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2885 int PMPI_Win_wait(MPI_Win win){
2888 if (win == MPI_WIN_NULL) {
2889 retval = MPI_ERR_WIN;
2892 int rank = smpi_process_index();
2893 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2895 retval = smpi_mpi_win_wait(win);
2897 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2903 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2904 void *ptr = xbt_malloc(size);
2906 return MPI_ERR_NO_MEM;
2908 *(void **)baseptr = ptr;
2913 int PMPI_Free_mem(void *baseptr){
2918 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2921 if (datatype == MPI_DATATYPE_NULL) {
2922 retval = MPI_ERR_TYPE;
2923 } else if (name == NULL) {
2924 retval = MPI_ERR_ARG;
2926 smpi_datatype_set_name(datatype, name);
2927 retval = MPI_SUCCESS;
2932 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2936 if (datatype == MPI_DATATYPE_NULL) {
2937 retval = MPI_ERR_TYPE;
2938 } else if (name == NULL) {
2939 retval = MPI_ERR_ARG;
2941 smpi_datatype_get_name(datatype, name, len);
2942 retval = MPI_SUCCESS;
2947 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2948 return smpi_type_f2c(datatype);
2951 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2952 return smpi_type_c2f( datatype);
2955 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2956 return smpi_group_f2c( group);
2959 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2960 return smpi_group_c2f(group);
2963 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2964 return smpi_request_f2c(request);
2967 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2968 return smpi_request_c2f(request);
2971 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2972 return smpi_win_f2c(win);
2975 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2976 return smpi_win_c2f(win);
2979 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2980 return smpi_op_f2c(op);
2983 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2984 return smpi_op_c2f(op);
2987 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2988 return smpi_comm_f2c(comm);
2991 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2992 return smpi_comm_c2f(comm);
2995 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2996 return smpi_info_f2c(info);
2999 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3000 return smpi_info_c2f(info);
3003 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3004 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3007 int PMPI_Keyval_free(int* keyval) {
3008 return smpi_comm_keyval_free(keyval);
3011 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3012 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3013 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3015 else if (comm==MPI_COMM_NULL)
3016 return MPI_ERR_COMM;
3018 return smpi_comm_attr_delete(comm, keyval);
3021 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3023 static int zero = 0;
3024 static int tag_ub = 1000000;
3025 static int last_used_code = MPI_ERR_LASTCODE;
3027 if (comm==MPI_COMM_NULL){
3029 return MPI_ERR_COMM;
3037 *(int**)attr_value = &zero;
3039 case MPI_UNIVERSE_SIZE:
3041 *(int**)attr_value = &smpi_universe_size;
3043 case MPI_LASTUSEDCODE:
3045 *(int**)attr_value = &last_used_code;
3049 *(int**)attr_value = &tag_ub;
3051 case MPI_WTIME_IS_GLOBAL:
3053 *(int**)attr_value = &one;
3056 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3060 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3061 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3062 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3064 else if (comm==MPI_COMM_NULL)
3065 return MPI_ERR_COMM;
3067 return smpi_comm_attr_put(comm, keyval, attr_value);
3070 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3072 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3075 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3077 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3080 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3082 return PMPI_Attr_delete(comm, comm_keyval);
3085 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3088 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3091 int PMPI_Comm_free_keyval(int* keyval) {
3092 return PMPI_Keyval_free(keyval);
3095 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3097 if (type==MPI_DATATYPE_NULL)
3098 return MPI_ERR_TYPE;
3100 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3103 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3105 if (type==MPI_DATATYPE_NULL)
3106 return MPI_ERR_TYPE;
3108 return smpi_type_attr_put(type, type_keyval, attribute_val);
3111 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3113 if (type==MPI_DATATYPE_NULL)
3114 return MPI_ERR_TYPE;
3116 return smpi_type_attr_delete(type, type_keyval);
3119 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3122 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3125 int PMPI_Type_free_keyval(int* keyval) {
3126 return smpi_type_keyval_free(keyval);
3129 int PMPI_Info_create( MPI_Info *info){
3132 *info = xbt_new(s_smpi_mpi_info_t, 1);
3133 (*info)->info_dict= xbt_dict_new_homogeneous(NULL);
3134 (*info)->refcount=1;
3138 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3139 if (info == NULL || key == NULL || value == NULL)
3142 xbt_dict_set(info->info_dict, key, (void*)value, NULL);
3146 int PMPI_Info_free( MPI_Info *info){
3147 if (info == NULL || *info==NULL)
3149 (*info)->refcount--;
3150 if((*info)->refcount==0){
3151 xbt_dict_free(&((*info)->info_dict));
3154 *info=MPI_INFO_NULL;
3158 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3160 if (info == NULL || key == NULL || valuelen <0)
3163 return MPI_ERR_INFO_VALUE;
3164 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3166 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3172 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3173 if (info == NULL || newinfo==NULL)
3175 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3176 (*newinfo)->info_dict= xbt_dict_new_homogeneous(NULL);
3177 xbt_dict_cursor_t cursor = NULL;
3180 xbt_dict_foreach(info->info_dict,cursor,key,data){
3181 xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
3186 int PMPI_Info_delete(MPI_Info info, char *key){
3188 if (info == NULL || key==NULL)
3191 xbt_dict_remove(info->info_dict, key);
3194 return MPI_ERR_INFO_NOKEY;
3199 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3200 if (info == NULL || nkeys==NULL)
3202 *nkeys=xbt_dict_size(info->info_dict);
3206 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3207 if (info == NULL || key==NULL || n<0 || n> MPI_MAX_INFO_KEY)
3210 xbt_dict_cursor_t cursor = NULL;
3214 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3224 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3226 if (info == NULL || key == NULL || valuelen==NULL || *valuelen <0)
3228 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3230 *valuelen=strlen(tmpvalue);
3236 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3237 if(incount<0 || outcount < 0 || inbuf==NULL || outbuf==NULL)
3239 if(!is_datatype_valid(type))
3240 return MPI_ERR_TYPE;
3241 if(comm==MPI_COMM_NULL)
3242 return MPI_ERR_COMM;
3243 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3246 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3247 if(incount<0 || outcount < 0|| inbuf==NULL || outbuf==NULL)
3249 if(!is_datatype_valid(type))
3250 return MPI_ERR_TYPE;
3251 if(comm==MPI_COMM_NULL)
3252 return MPI_ERR_COMM;
3253 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3256 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3259 if(!is_datatype_valid(datatype))
3260 return MPI_ERR_TYPE;
3261 if(comm==MPI_COMM_NULL)
3262 return MPI_ERR_COMM;
3264 *size=incount*smpi_datatype_size(datatype);
3270 /* The following calls are not yet implemented and will fail at runtime. */
3271 /* Once implemented, please move them above this notice. */
3273 #define NOT_YET_IMPLEMENTED { \
3274 XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
3275 return MPI_SUCCESS; \
3278 MPI_Errhandler PMPI_Errhandler_f2c(MPI_Fint errhandler){
3282 MPI_Fint PMPI_Errhandler_c2f(MPI_Errhandler errhandler){
3286 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
3290 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
3294 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
3298 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
3302 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
3306 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
3310 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
3314 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
3318 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
3322 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
3326 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
3330 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
3334 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
3338 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
3342 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
3346 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
3350 int PMPI_Cancel(MPI_Request* request) {
3354 int PMPI_Buffer_attach(void* buffer, int size) {
3358 int PMPI_Buffer_detach(void* buffer, int* size) {
3362 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
3366 int PMPI_Pcontrol(const int level )
3371 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag,
3372 MPI_Comm* comm_out) {
3376 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3380 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3384 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm,
3385 MPI_Request* request) {
3389 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3393 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3397 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3401 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3405 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm,
3406 MPI_Request* request) {
3410 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3414 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3418 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3422 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount,
3423 MPI_Aint *position){
3427 int PMPI_Unpack_external(char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount,
3428 MPI_Datatype datatype){
3432 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3436 int PMPI_Type_get_envelope(MPI_Datatype datatype, int *num_integers, int *num_addresses, int *num_datatypes,
3441 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses, int max_datatypes,
3442 int* array_of_integers, MPI_Aint* array_of_addresses, MPI_Datatype* array_of_datatypes){
3446 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes, int* array_of_distribs,
3447 int* array_of_dargs, int* array_of_psizes,int order, MPI_Datatype oldtype,
3448 MPI_Datatype *newtype) {
3452 int PMPI_Type_create_subarray(int ndims,int *array_of_sizes, int *array_of_subsizes, int *array_of_starts, int order,
3453 MPI_Datatype oldtype, MPI_Datatype *newtype){
3457 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3461 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3462 void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes, MPI_Comm comm){
3466 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3470 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3474 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3478 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3482 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3486 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3490 int PMPI_Add_error_class( int *errorclass){
3494 int PMPI_Add_error_code( int errorclass, int *errorcode){
3498 int PMPI_Add_error_string( int errorcode, char *string){
3502 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3506 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3510 int PMPI_Grequest_start(MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn,
3511 MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request){
3515 int PMPI_Grequest_complete( MPI_Request request){
3519 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3523 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3527 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3531 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3535 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3539 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3543 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3547 int PMPI_Open_port( MPI_Info info, char *port_name){
3551 int PMPI_Close_port(char *port_name){
3555 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3559 int PMPI_Comm_spawn(char *command, char **argv, int maxprocs, MPI_Info info, int root, MPI_Comm comm,
3560 MPI_Comm *intercomm, int* array_of_errcodes){
3564 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3565 int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3566 MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3570 int PMPI_Comm_get_parent( MPI_Comm *parent){
3574 int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win) {
3578 int PMPI_Win_test(MPI_Win win, int *flag){
3582 int PMPI_Win_unlock(int rank, MPI_Win win){