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_unuse(*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 != 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);
760 if(retval==MPI_SUCCESS)
761 smpi_group_use(smpi_comm_group(*newcomm));
766 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
770 if (comm == MPI_COMM_NULL) {
771 retval = MPI_ERR_COMM;
772 } else if (group == MPI_GROUP_NULL) {
773 retval = MPI_ERR_GROUP;
774 } else if (newcomm == NULL) {
775 retval = MPI_ERR_ARG;
776 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
777 *newcomm= MPI_COMM_NULL;
778 retval = MPI_SUCCESS;
780 smpi_group_use(group);
781 *newcomm = smpi_comm_new(group, NULL);
782 retval = MPI_SUCCESS;
787 int PMPI_Comm_free(MPI_Comm * comm)
792 retval = MPI_ERR_ARG;
793 } else if (*comm == MPI_COMM_NULL) {
794 retval = MPI_ERR_COMM;
796 smpi_comm_destroy(*comm);
797 *comm = MPI_COMM_NULL;
798 retval = MPI_SUCCESS;
803 int PMPI_Comm_disconnect(MPI_Comm * comm)
805 /* TODO: wait until all communication in comm are done */
809 retval = MPI_ERR_ARG;
810 } else if (*comm == MPI_COMM_NULL) {
811 retval = MPI_ERR_COMM;
813 smpi_comm_destroy(*comm);
814 *comm = MPI_COMM_NULL;
815 retval = MPI_SUCCESS;
820 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
825 if (comm_out == NULL) {
826 retval = MPI_ERR_ARG;
827 } else if (comm == MPI_COMM_NULL) {
828 retval = MPI_ERR_COMM;
830 *comm_out = smpi_comm_split(comm, color, key);
831 retval = MPI_SUCCESS;
838 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
843 if (request == NULL) {
844 retval = MPI_ERR_ARG;
845 } else if (comm == MPI_COMM_NULL) {
846 retval = MPI_ERR_COMM;
847 } else if (!is_datatype_valid(datatype)) {
848 retval = MPI_ERR_TYPE;
849 } else if (dst == MPI_PROC_NULL) {
850 retval = MPI_SUCCESS;
852 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
853 retval = MPI_SUCCESS;
856 if (retval != MPI_SUCCESS && request)
857 *request = MPI_REQUEST_NULL;
861 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
866 if (request == NULL) {
867 retval = MPI_ERR_ARG;
868 } else if (comm == MPI_COMM_NULL) {
869 retval = MPI_ERR_COMM;
870 } else if (!is_datatype_valid(datatype)) {
871 retval = MPI_ERR_TYPE;
872 } else if (src == MPI_PROC_NULL) {
873 retval = MPI_SUCCESS;
875 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
876 retval = MPI_SUCCESS;
879 if (retval != MPI_SUCCESS && request)
880 *request = MPI_REQUEST_NULL;
884 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request)
889 if (request == NULL) {
890 retval = MPI_ERR_ARG;
891 } else if (comm == MPI_COMM_NULL) {
892 retval = MPI_ERR_COMM;
893 } else if (!is_datatype_valid(datatype)) {
894 retval = MPI_ERR_TYPE;
895 } else if (dst == MPI_PROC_NULL) {
896 retval = MPI_SUCCESS;
898 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
899 retval = MPI_SUCCESS;
902 if (retval != MPI_SUCCESS && request)
903 *request = MPI_REQUEST_NULL;
907 int PMPI_Start(MPI_Request * request)
912 if (request == NULL || *request == MPI_REQUEST_NULL) {
913 retval = MPI_ERR_REQUEST;
915 smpi_mpi_start(*request);
916 retval = MPI_SUCCESS;
922 int PMPI_Startall(int count, MPI_Request * requests)
927 if (requests == NULL) {
928 retval = MPI_ERR_ARG;
930 retval = MPI_SUCCESS;
931 for (i = 0 ; i < count ; i++) {
932 if(requests[i] == MPI_REQUEST_NULL) {
933 retval = MPI_ERR_REQUEST;
936 if(retval != MPI_ERR_REQUEST) {
937 smpi_mpi_startall(count, requests);
944 int PMPI_Request_free(MPI_Request * request)
949 if (*request == MPI_REQUEST_NULL) {
950 retval = MPI_ERR_ARG;
952 smpi_mpi_request_free(request);
953 retval = MPI_SUCCESS;
959 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request * request)
965 if (request == NULL) {
966 retval = MPI_ERR_ARG;
967 } else if (comm == MPI_COMM_NULL) {
968 retval = MPI_ERR_COMM;
969 } else if (src == MPI_PROC_NULL) {
970 *request = MPI_REQUEST_NULL;
971 retval = MPI_SUCCESS;
972 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
973 retval = MPI_ERR_RANK;
974 } else if (count < 0) {
975 retval = MPI_ERR_COUNT;
976 } else if (buf==NULL && count > 0) {
977 retval = MPI_ERR_COUNT;
978 } else if (!is_datatype_valid(datatype)) {
979 retval = MPI_ERR_TYPE;
980 } else if(tag<0 && tag != MPI_ANY_TAG){
981 retval = MPI_ERR_TAG;
984 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
985 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
987 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
988 extra->type = TRACING_IRECV;
989 extra->src = src_traced;
992 extra->datatype1 = encode_datatype(datatype, &known);
993 int dt_size_send = 1;
995 dt_size_send = smpi_datatype_size(datatype);
996 extra->send_size = count*dt_size_send;
997 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
999 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1000 retval = MPI_SUCCESS;
1002 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1003 (*request)->recv = 1;
1007 if (retval != MPI_SUCCESS && request)
1008 *request = MPI_REQUEST_NULL;
1013 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request * request)
1018 if (request == NULL) {
1019 retval = MPI_ERR_ARG;
1020 } else if (comm == MPI_COMM_NULL) {
1021 retval = MPI_ERR_COMM;
1022 } else if (dst == MPI_PROC_NULL) {
1023 *request = MPI_REQUEST_NULL;
1024 retval = MPI_SUCCESS;
1025 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1026 retval = MPI_ERR_RANK;
1027 } else if (count < 0) {
1028 retval = MPI_ERR_COUNT;
1029 } else if (buf==NULL && 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)
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 == NULL) {
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) {
1080 retval = MPI_ERR_COUNT;
1081 } else if (buf==NULL && count > 0) {
1082 retval = MPI_ERR_COUNT;
1083 } else if (!is_datatype_valid(datatype)) {
1084 retval = MPI_ERR_TYPE;
1085 } else if(tag<0 && tag != MPI_ANY_TAG){
1086 retval = MPI_ERR_TAG;
1089 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1090 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1091 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1092 extra->type = TRACING_ISSEND;
1094 extra->dst = dst_traced;
1096 extra->datatype1 = encode_datatype(datatype, &known);
1097 int dt_size_send = 1;
1099 dt_size_send = smpi_datatype_size(datatype);
1100 extra->send_size = count*dt_size_send;
1101 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1102 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1104 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1105 retval = MPI_SUCCESS;
1107 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1108 (*request)->send = 1;
1112 if (retval != MPI_SUCCESS && request)
1113 *request = MPI_REQUEST_NULL;
1117 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
1122 if (comm == MPI_COMM_NULL) {
1123 retval = MPI_ERR_COMM;
1124 } else if (src == MPI_PROC_NULL) {
1125 smpi_empty_status(status);
1126 status->MPI_SOURCE = MPI_PROC_NULL;
1127 retval = MPI_SUCCESS;
1128 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1129 retval = MPI_ERR_RANK;
1130 } else if (count < 0) {
1131 retval = MPI_ERR_COUNT;
1132 } else if (buf==NULL && count > 0) {
1133 retval = MPI_ERR_COUNT;
1134 } else if (!is_datatype_valid(datatype)) {
1135 retval = MPI_ERR_TYPE;
1136 } else if(tag<0 && tag != MPI_ANY_TAG){
1137 retval = MPI_ERR_TAG;
1139 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1140 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1141 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1142 extra->type = TRACING_RECV;
1143 extra->src = src_traced;
1146 extra->datatype1 = encode_datatype(datatype, &known);
1147 int dt_size_send = 1;
1149 dt_size_send = smpi_datatype_size(datatype);
1150 extra->send_size = count*dt_size_send;
1151 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1153 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1154 retval = MPI_SUCCESS;
1156 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1157 if(status!=MPI_STATUS_IGNORE){
1158 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1159 if (!TRACE_smpi_view_internals()) {
1160 TRACE_smpi_recv(rank, src_traced, rank);
1163 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1170 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
1176 if (comm == MPI_COMM_NULL) {
1177 retval = MPI_ERR_COMM;
1178 } else if (dst == MPI_PROC_NULL) {
1179 retval = MPI_SUCCESS;
1180 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1181 retval = MPI_ERR_RANK;
1182 } else if (count < 0) {
1183 retval = MPI_ERR_COUNT;
1184 } else if (buf==NULL && count > 0) {
1185 retval = MPI_ERR_COUNT;
1186 } else if (!is_datatype_valid(datatype)) {
1187 retval = MPI_ERR_TYPE;
1188 } else if(tag<0 && tag != MPI_ANY_TAG){
1189 retval = MPI_ERR_TAG;
1192 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1193 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1194 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1195 extra->type = TRACING_SEND;
1197 extra->dst = dst_traced;
1199 extra->datatype1 = encode_datatype(datatype, &known);
1200 int dt_size_send = 1;
1202 dt_size_send = smpi_datatype_size(datatype);
1203 extra->send_size = count*dt_size_send;
1204 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1205 if (!TRACE_smpi_view_internals()) {
1206 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1209 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1210 retval = MPI_SUCCESS;
1212 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1221 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1226 if (comm == MPI_COMM_NULL) {
1227 retval = MPI_ERR_COMM;
1228 } else if (dst == MPI_PROC_NULL) {
1229 retval = MPI_SUCCESS;
1230 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1231 retval = MPI_ERR_RANK;
1232 } else if (count < 0) {
1233 retval = MPI_ERR_COUNT;
1234 } else if (buf==NULL && count > 0) {
1235 retval = MPI_ERR_COUNT;
1236 } else if (!is_datatype_valid(datatype)){
1237 retval = MPI_ERR_TYPE;
1238 } else if(tag<0 && tag != MPI_ANY_TAG){
1239 retval = MPI_ERR_TAG;
1242 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1243 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1244 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1245 extra->type = TRACING_SSEND;
1247 extra->dst = dst_traced;
1249 extra->datatype1 = encode_datatype(datatype, &known);
1250 int dt_size_send = 1;
1252 dt_size_send = smpi_datatype_size(datatype);
1253 extra->send_size = count*dt_size_send;
1254 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1255 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1257 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1258 retval = MPI_SUCCESS;
1260 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1266 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void *recvbuf,
1267 int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status * status)
1273 if (comm == MPI_COMM_NULL) {
1274 retval = MPI_ERR_COMM;
1275 } else if (!is_datatype_valid(sendtype)
1276 || !is_datatype_valid(recvtype)) {
1277 retval = MPI_ERR_TYPE;
1278 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1279 smpi_empty_status(status);
1280 status->MPI_SOURCE = MPI_PROC_NULL;
1281 retval = MPI_SUCCESS;
1282 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1283 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1284 retval = MPI_ERR_RANK;
1285 } else if (sendcount < 0 || recvcount<0) {
1286 retval = MPI_ERR_COUNT;
1287 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1288 retval = MPI_ERR_COUNT;
1289 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1290 retval = MPI_ERR_TAG;
1293 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1294 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1295 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1296 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1297 extra->type = TRACING_SENDRECV;
1298 extra->src = src_traced;
1299 extra->dst = dst_traced;
1301 extra->datatype1 = encode_datatype(sendtype, &known);
1302 int dt_size_send = 1;
1304 dt_size_send = smpi_datatype_size(sendtype);
1305 extra->send_size = sendcount*dt_size_send;
1306 extra->datatype2 = encode_datatype(recvtype, &known);
1307 int dt_size_recv = 1;
1309 dt_size_recv = smpi_datatype_size(recvtype);
1310 extra->recv_size = recvcount*dt_size_recv;
1312 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1313 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1315 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1316 recvcount, recvtype, src, recvtag, comm, status);
1317 retval = MPI_SUCCESS;
1319 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1320 TRACE_smpi_recv(rank, src_traced, rank);
1327 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag,
1328 MPI_Comm comm, MPI_Status * status)
1330 //TODO: suboptimal implementation
1333 if (!is_datatype_valid(datatype)) {
1334 retval = MPI_ERR_TYPE;
1335 } else if (count < 0) {
1336 retval = MPI_ERR_COUNT;
1338 int size = smpi_datatype_get_extent(datatype) * count;
1339 recvbuf = xbt_new0(char, size);
1340 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
1341 if(retval==MPI_SUCCESS){
1342 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1350 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1354 if (request == NULL || flag == NULL) {
1355 retval = MPI_ERR_ARG;
1356 } else if (*request == MPI_REQUEST_NULL) {
1358 smpi_empty_status(status);
1359 retval = MPI_SUCCESS;
1361 int rank = request && (*request)->comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1363 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1364 extra->type = TRACING_TEST;
1365 TRACE_smpi_testing_in(rank, extra);
1367 *flag = smpi_mpi_test(request, status);
1369 TRACE_smpi_testing_out(rank);
1370 retval = MPI_SUCCESS;
1376 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_Status * status)
1381 if (index == NULL || flag == NULL) {
1382 retval = MPI_ERR_ARG;
1384 *flag = smpi_mpi_testany(count, requests, index, status);
1385 retval = MPI_SUCCESS;
1391 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1397 retval = MPI_ERR_ARG;
1399 *flag = smpi_mpi_testall(count, requests, statuses);
1400 retval = MPI_SUCCESS;
1406 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1410 if (status == NULL) {
1411 retval = MPI_ERR_ARG;
1412 } else if (comm == MPI_COMM_NULL) {
1413 retval = MPI_ERR_COMM;
1414 } else if (source == MPI_PROC_NULL) {
1415 smpi_empty_status(status);
1416 status->MPI_SOURCE = MPI_PROC_NULL;
1417 retval = MPI_SUCCESS;
1419 smpi_mpi_probe(source, tag, comm, status);
1420 retval = MPI_SUCCESS;
1426 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1431 retval = MPI_ERR_ARG;
1432 } else if (status == NULL) {
1433 retval = MPI_ERR_ARG;
1434 } else if (comm == MPI_COMM_NULL) {
1435 retval = MPI_ERR_COMM;
1436 } else if (source == MPI_PROC_NULL) {
1438 smpi_empty_status(status);
1439 status->MPI_SOURCE = MPI_PROC_NULL;
1440 retval = MPI_SUCCESS;
1442 smpi_mpi_iprobe(source, tag, comm, flag, status);
1443 retval = MPI_SUCCESS;
1449 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1455 smpi_empty_status(status);
1457 if (request == NULL) {
1458 retval = MPI_ERR_ARG;
1459 } else if (*request == MPI_REQUEST_NULL) {
1460 retval = MPI_SUCCESS;
1463 int rank = request && (*request)->comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1465 int src_traced = (*request)->src;
1466 int dst_traced = (*request)->dst;
1467 MPI_Comm comm = (*request)->comm;
1468 int is_wait_for_receive = (*request)->recv;
1469 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1470 extra->type = TRACING_WAIT;
1471 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1473 smpi_mpi_wait(request, status);
1474 retval = MPI_SUCCESS;
1476 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1477 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1478 if (is_wait_for_receive) {
1479 if(src_traced==MPI_ANY_SOURCE)
1480 src_traced = (status!=MPI_STATUS_IGNORE) ?
1481 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1483 TRACE_smpi_recv(rank, src_traced, dst_traced);
1491 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1497 //save requests information for tracing
1499 int *srcs = xbt_new0(int, count);
1500 int *dsts = xbt_new0(int, count);
1501 int *recvs = xbt_new0(int, count);
1502 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1504 for (i = 0; i < count; i++) {
1505 MPI_Request req = requests[i]; //already received requests are no longer valid
1509 recvs[i] = req->recv;
1510 comms[i] = req->comm;
1513 int rank_traced = smpi_process_index();
1514 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1515 extra->type = TRACING_WAITANY;
1516 extra->send_size=count;
1517 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1519 *index = smpi_mpi_waitany(count, requests, status);
1521 if(*index!=MPI_UNDEFINED){
1522 int src_traced = srcs[*index];
1523 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1524 int dst_traced = dsts[*index];
1525 int is_wait_for_receive = recvs[*index];
1526 if (is_wait_for_receive) {
1527 if(srcs[*index]==MPI_ANY_SOURCE)
1528 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1529 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) : srcs[*index];
1530 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1532 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1543 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1546 //save information from requests
1548 int *srcs = xbt_new0(int, count);
1549 int *dsts = xbt_new0(int, count);
1550 int *recvs = xbt_new0(int, count);
1551 int *valid = xbt_new0(int, count);
1552 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1554 //int valid_count = 0;
1555 for (i = 0; i < count; i++) {
1556 MPI_Request req = requests[i];
1557 if(req!=MPI_REQUEST_NULL){
1560 recvs[i] = req->recv;
1561 comms[i] = req->comm;
1567 int rank_traced = smpi_process_index();
1568 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1569 extra->type = TRACING_WAITALL;
1570 extra->send_size=count;
1571 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1573 int retval = smpi_mpi_waitall(count, requests, status);
1575 for (i = 0; i < count; i++) {
1577 //int src_traced = srcs[*index];
1578 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1579 int src_traced = srcs[i];
1580 int dst_traced = dsts[i];
1581 int is_wait_for_receive = recvs[i];
1582 if (is_wait_for_receive) {
1583 if(src_traced==MPI_ANY_SOURCE)
1584 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1585 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) : srcs[i];
1586 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1590 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1601 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indices, MPI_Status status[])
1606 if (outcount == NULL) {
1607 retval = MPI_ERR_ARG;
1609 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1610 retval = MPI_SUCCESS;
1616 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[])
1621 if (outcount == NULL) {
1622 retval = MPI_ERR_ARG;
1624 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1625 retval = MPI_SUCCESS;
1632 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1638 if (comm == MPI_COMM_NULL) {
1639 retval = MPI_ERR_COMM;
1640 } else if (!is_datatype_valid(datatype)) {
1641 retval = MPI_ERR_ARG;
1643 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1644 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1646 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1647 extra->type = TRACING_BCAST;
1648 extra->root = root_traced;
1650 extra->datatype1 = encode_datatype(datatype, &known);
1651 int dt_size_send = 1;
1653 dt_size_send = smpi_datatype_size(datatype);
1654 extra->send_size = count*dt_size_send;
1655 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1657 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1658 retval = MPI_SUCCESS;
1660 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1667 int PMPI_Barrier(MPI_Comm comm)
1673 if (comm == MPI_COMM_NULL) {
1674 retval = MPI_ERR_COMM;
1676 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1677 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1678 extra->type = TRACING_BARRIER;
1679 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1681 mpi_coll_barrier_fun(comm);
1682 retval = MPI_SUCCESS;
1684 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1691 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,
1692 int root, MPI_Comm comm)
1698 if (comm == MPI_COMM_NULL) {
1699 retval = MPI_ERR_COMM;
1700 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1701 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1702 retval = MPI_ERR_TYPE;
1703 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) || ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1704 retval = MPI_ERR_COUNT;
1707 char* sendtmpbuf = (char*) sendbuf;
1708 int sendtmpcount = sendcount;
1709 MPI_Datatype sendtmptype = sendtype;
1710 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1712 sendtmptype=recvtype;
1714 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1715 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1716 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1717 extra->type = TRACING_GATHER;
1718 extra->root = root_traced;
1720 extra->datatype1 = encode_datatype(sendtmptype, &known);
1721 int dt_size_send = 1;
1723 dt_size_send = smpi_datatype_size(sendtmptype);
1724 extra->send_size = sendtmpcount*dt_size_send;
1725 extra->datatype2 = encode_datatype(recvtype, &known);
1726 int dt_size_recv = 1;
1727 if((smpi_comm_rank(comm)==root) && !known)
1728 dt_size_recv = smpi_datatype_size(recvtype);
1729 extra->recv_size = recvcount*dt_size_recv;
1731 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1733 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount, recvtype, root, comm);
1735 retval = MPI_SUCCESS;
1736 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1743 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs,
1744 MPI_Datatype recvtype, int root, MPI_Comm comm)
1750 if (comm == MPI_COMM_NULL) {
1751 retval = MPI_ERR_COMM;
1752 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1753 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1754 retval = MPI_ERR_TYPE;
1755 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1756 retval = MPI_ERR_COUNT;
1757 } else if (recvcounts == NULL || displs == NULL) {
1758 retval = MPI_ERR_ARG;
1760 char* sendtmpbuf = (char*) sendbuf;
1761 int sendtmpcount = sendcount;
1762 MPI_Datatype sendtmptype = sendtype;
1763 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1765 sendtmptype=recvtype;
1768 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1769 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1771 int size = smpi_comm_size(comm);
1772 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1773 extra->type = TRACING_GATHERV;
1774 extra->num_processes = size;
1775 extra->root = root_traced;
1777 extra->datatype1 = encode_datatype(sendtmptype, &known);
1778 int dt_size_send = 1;
1780 dt_size_send = smpi_datatype_size(sendtype);
1781 extra->send_size = sendtmpcount*dt_size_send;
1782 extra->datatype2 = encode_datatype(recvtype, &known);
1783 int dt_size_recv = 1;
1785 dt_size_recv = smpi_datatype_size(recvtype);
1786 if((smpi_comm_rank(comm)==root)){
1787 extra->recvcounts= xbt_new(int,size);
1788 for(i=0; i< size; i++)//copy data to avoid bad free
1789 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1791 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1793 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts, displs, recvtype, root, comm);
1794 retval = MPI_SUCCESS;
1795 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1802 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1803 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
1809 if (comm == MPI_COMM_NULL) {
1810 retval = MPI_ERR_COMM;
1811 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1812 (recvtype == MPI_DATATYPE_NULL)){
1813 retval = MPI_ERR_TYPE;
1814 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1816 retval = MPI_ERR_COUNT;
1818 if(sendbuf == MPI_IN_PLACE) {
1819 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1820 sendcount=recvcount;
1823 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1824 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1825 extra->type = TRACING_ALLGATHER;
1827 extra->datatype1 = encode_datatype(sendtype, &known);
1828 int dt_size_send = 1;
1830 dt_size_send = smpi_datatype_size(sendtype);
1831 extra->send_size = sendcount*dt_size_send;
1832 extra->datatype2 = encode_datatype(recvtype, &known);
1833 int dt_size_recv = 1;
1835 dt_size_recv = smpi_datatype_size(recvtype);
1836 extra->recv_size = recvcount*dt_size_recv;
1838 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1840 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1841 retval = MPI_SUCCESS;
1842 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1848 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1849 void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm)
1855 if (comm == MPI_COMM_NULL) {
1856 retval = MPI_ERR_COMM;
1857 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1858 (recvtype == MPI_DATATYPE_NULL)){
1859 retval = MPI_ERR_TYPE;
1860 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1861 retval = MPI_ERR_COUNT;
1862 } else if (recvcounts == NULL || displs == NULL) {
1863 retval = MPI_ERR_ARG;
1866 if(sendbuf == MPI_IN_PLACE) {
1867 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1868 sendcount=recvcounts[smpi_comm_rank(comm)];
1871 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1873 int size = smpi_comm_size(comm);
1874 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1875 extra->type = TRACING_ALLGATHERV;
1876 extra->num_processes = size;
1878 extra->datatype1 = encode_datatype(sendtype, &known);
1879 int dt_size_send = 1;
1881 dt_size_send = smpi_datatype_size(sendtype);
1882 extra->send_size = sendcount*dt_size_send;
1883 extra->datatype2 = encode_datatype(recvtype, &known);
1884 int dt_size_recv = 1;
1886 dt_size_recv = smpi_datatype_size(recvtype);
1887 extra->recvcounts= xbt_new(int, size);
1888 for(i=0; i< size; i++)//copy data to avoid bad free
1889 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1891 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1893 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
1894 retval = MPI_SUCCESS;
1895 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1902 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1903 void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1909 if (comm == MPI_COMM_NULL) {
1910 retval = MPI_ERR_COMM;
1911 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1912 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1913 retval = MPI_ERR_TYPE;
1914 } else if ((sendbuf == recvbuf) ||
1915 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
1916 retval = MPI_ERR_BUFFER;
1919 if (recvbuf == MPI_IN_PLACE) {
1921 recvcount=sendcount;
1923 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1924 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1925 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1926 extra->type = TRACING_SCATTER;
1927 extra->root = root_traced;
1929 extra->datatype1 = encode_datatype(sendtype, &known);
1930 int dt_size_send = 1;
1931 if((smpi_comm_rank(comm)==root) && !known)
1932 dt_size_send = smpi_datatype_size(sendtype);
1933 extra->send_size = sendcount*dt_size_send;
1934 extra->datatype2 = encode_datatype(recvtype, &known);
1935 int dt_size_recv = 1;
1937 dt_size_recv = smpi_datatype_size(recvtype);
1938 extra->recv_size = recvcount*dt_size_recv;
1939 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1941 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
1942 retval = MPI_SUCCESS;
1943 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1950 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1951 MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
1957 if (comm == MPI_COMM_NULL) {
1958 retval = MPI_ERR_COMM;
1959 } else if (sendcounts == NULL || displs == NULL) {
1960 retval = MPI_ERR_ARG;
1961 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1962 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1963 retval = MPI_ERR_TYPE;
1965 if (recvbuf == MPI_IN_PLACE) {
1967 recvcount=sendcounts[smpi_comm_rank(comm)];
1969 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1970 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1972 int size = smpi_comm_size(comm);
1973 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1974 extra->type = TRACING_SCATTERV;
1975 extra->num_processes = size;
1976 extra->root = root_traced;
1978 extra->datatype1 = encode_datatype(sendtype, &known);
1979 int dt_size_send = 1;
1981 dt_size_send = smpi_datatype_size(sendtype);
1982 if((smpi_comm_rank(comm)==root)){
1983 extra->sendcounts= xbt_new(int, size);
1984 for(i=0; i< size; i++)//copy data to avoid bad free
1985 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
1987 extra->datatype2 = encode_datatype(recvtype, &known);
1988 int dt_size_recv = 1;
1990 dt_size_recv = smpi_datatype_size(recvtype);
1991 extra->recv_size = recvcount*dt_size_recv;
1992 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1994 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
1996 retval = MPI_SUCCESS;
1997 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2004 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2010 if (comm == MPI_COMM_NULL) {
2011 retval = MPI_ERR_COMM;
2012 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2013 retval = MPI_ERR_ARG;
2015 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2016 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2017 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2018 extra->type = TRACING_REDUCE;
2020 extra->datatype1 = encode_datatype(datatype, &known);
2021 int dt_size_send = 1;
2023 dt_size_send = smpi_datatype_size(datatype);
2024 extra->send_size = count*dt_size_send;
2025 extra->root = root_traced;
2027 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2029 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2031 retval = MPI_SUCCESS;
2032 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2039 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count, MPI_Datatype datatype, MPI_Op op){
2043 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2044 retval = MPI_ERR_ARG;
2046 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2053 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2059 if (comm == MPI_COMM_NULL) {
2060 retval = MPI_ERR_COMM;
2061 } else if (!is_datatype_valid(datatype)) {
2062 retval = MPI_ERR_TYPE;
2063 } else if (op == MPI_OP_NULL) {
2064 retval = MPI_ERR_OP;
2067 char* sendtmpbuf = (char*) sendbuf;
2068 if( sendbuf == MPI_IN_PLACE ) {
2069 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2070 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2072 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2073 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2074 extra->type = TRACING_ALLREDUCE;
2076 extra->datatype1 = encode_datatype(datatype, &known);
2077 int dt_size_send = 1;
2079 dt_size_send = smpi_datatype_size(datatype);
2080 extra->send_size = count*dt_size_send;
2082 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2084 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2086 if( sendbuf == MPI_IN_PLACE )
2087 xbt_free(sendtmpbuf);
2089 retval = MPI_SUCCESS;
2090 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2097 int PMPI_Scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2103 if (comm == MPI_COMM_NULL) {
2104 retval = MPI_ERR_COMM;
2105 } else if (!is_datatype_valid(datatype)) {
2106 retval = MPI_ERR_TYPE;
2107 } else if (op == MPI_OP_NULL) {
2108 retval = MPI_ERR_OP;
2110 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2111 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2112 extra->type = TRACING_SCAN;
2114 extra->datatype1 = encode_datatype(datatype, &known);
2115 int dt_size_send = 1;
2117 dt_size_send = smpi_datatype_size(datatype);
2118 extra->send_size = count*dt_size_send;
2120 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2122 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2124 retval = MPI_SUCCESS;
2125 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2132 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm){
2137 if (comm == MPI_COMM_NULL) {
2138 retval = MPI_ERR_COMM;
2139 } else if (!is_datatype_valid(datatype)) {
2140 retval = MPI_ERR_TYPE;
2141 } else if (op == MPI_OP_NULL) {
2142 retval = MPI_ERR_OP;
2144 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2145 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2146 extra->type = TRACING_EXSCAN;
2148 extra->datatype1 = encode_datatype(datatype, &known);
2149 int dt_size_send = 1;
2151 dt_size_send = smpi_datatype_size(datatype);
2152 extra->send_size = count*dt_size_send;
2153 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2155 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2156 retval = MPI_SUCCESS;
2157 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2164 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2169 if (comm == MPI_COMM_NULL) {
2170 retval = MPI_ERR_COMM;
2171 } else if (!is_datatype_valid(datatype)) {
2172 retval = MPI_ERR_TYPE;
2173 } else if (op == MPI_OP_NULL) {
2174 retval = MPI_ERR_OP;
2175 } else if (recvcounts == NULL) {
2176 retval = MPI_ERR_ARG;
2178 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2180 int size = smpi_comm_size(comm);
2181 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2182 extra->type = TRACING_REDUCE_SCATTER;
2183 extra->num_processes = size;
2185 extra->datatype1 = encode_datatype(datatype, &known);
2186 int dt_size_send = 1;
2188 dt_size_send = smpi_datatype_size(datatype);
2189 extra->send_size = 0;
2190 extra->recvcounts= xbt_new(int, size);
2191 for(i=0; i< size; i++)//copy data to avoid bad free
2192 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2193 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2195 void* sendtmpbuf=sendbuf;
2196 if(sendbuf==MPI_IN_PLACE)
2199 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype, op, comm);
2200 retval = MPI_SUCCESS;
2201 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2208 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2209 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2214 if (comm == MPI_COMM_NULL) {
2215 retval = MPI_ERR_COMM;
2216 } else if (!is_datatype_valid(datatype)) {
2217 retval = MPI_ERR_TYPE;
2218 } else if (op == MPI_OP_NULL) {
2219 retval = MPI_ERR_OP;
2220 } else if (recvcount < 0) {
2221 retval = MPI_ERR_ARG;
2223 int count=smpi_comm_size(comm);
2225 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2226 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2227 extra->type = TRACING_REDUCE_SCATTER;
2228 extra->num_processes = count;
2230 extra->datatype1 = encode_datatype(datatype, &known);
2231 int dt_size_send = 1;
2233 dt_size_send = smpi_datatype_size(datatype);
2234 extra->send_size = 0;
2235 extra->recvcounts= xbt_new(int, count);
2236 for(i=0; i< count; i++)//copy data to avoid bad free
2237 extra->recvcounts[i] = recvcount*dt_size_send;
2239 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2241 int* recvcounts=(int*)xbt_malloc(count);
2242 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2243 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts, datatype, op, comm);
2244 xbt_free(recvcounts);
2245 retval = MPI_SUCCESS;
2247 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2254 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2255 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
2261 if (comm == MPI_COMM_NULL) {
2262 retval = MPI_ERR_COMM;
2263 } else if (sendtype == MPI_DATATYPE_NULL
2264 || recvtype == MPI_DATATYPE_NULL) {
2265 retval = MPI_ERR_TYPE;
2267 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2268 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2269 extra->type = TRACING_ALLTOALL;
2271 extra->datatype1 = encode_datatype(sendtype, &known);
2273 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2275 extra->send_size = sendcount;
2276 extra->datatype2 = encode_datatype(recvtype, &known);
2278 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2280 extra->recv_size = recvcount;
2281 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2283 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2285 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2292 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2293 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2299 if (comm == MPI_COMM_NULL) {
2300 retval = MPI_ERR_COMM;
2301 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
2302 retval = MPI_ERR_TYPE;
2303 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL || recvdisps == NULL) {
2304 retval = MPI_ERR_ARG;
2306 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2308 int size = smpi_comm_size(comm);
2309 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2310 extra->type = TRACING_ALLTOALLV;
2311 extra->send_size = 0;
2312 extra->recv_size = 0;
2313 extra->recvcounts= xbt_new(int, size);
2314 extra->sendcounts= xbt_new(int, size);
2316 extra->datatype1 = encode_datatype(sendtype, &known);
2317 int dt_size_send = 1;
2319 dt_size_send = smpi_datatype_size(sendtype);
2320 int dt_size_recv = 1;
2321 extra->datatype2 = encode_datatype(recvtype, &known);
2323 dt_size_recv = smpi_datatype_size(recvtype);
2324 for(i=0; i< size; i++){//copy data to avoid bad free
2325 extra->send_size += sendcounts[i]*dt_size_send;
2326 extra->recv_size += recvcounts[i]*dt_size_recv;
2328 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2329 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2331 extra->num_processes = size;
2332 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2334 retval = mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype,
2336 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2344 int PMPI_Get_processor_name(char *name, int *resultlen)
2346 int retval = MPI_SUCCESS;
2348 strncpy(name, sg_host_get_name(SIMIX_host_self()),
2349 strlen(sg_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2350 strlen(sg_host_get_name(SIMIX_host_self())) +1 : MPI_MAX_PROCESSOR_NAME - 1 );
2351 *resultlen = strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2356 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2358 int retval = MPI_SUCCESS;
2361 if (status == NULL || count == NULL) {
2362 retval = MPI_ERR_ARG;
2363 } else if (!is_datatype_valid(datatype)) {
2364 retval = MPI_ERR_TYPE;
2366 size = smpi_datatype_size(datatype);
2369 } else if (status->count % size != 0) {
2370 retval = MPI_UNDEFINED;
2372 *count = smpi_mpi_get_count(status, datatype);
2378 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2381 if (old_type == MPI_DATATYPE_NULL) {
2382 retval = MPI_ERR_TYPE;
2383 } else if (count<0){
2384 retval = MPI_ERR_COUNT;
2386 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2391 int PMPI_Type_commit(MPI_Datatype* datatype) {
2394 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2395 retval = MPI_ERR_TYPE;
2397 smpi_datatype_commit(datatype);
2398 retval = MPI_SUCCESS;
2403 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2406 if (old_type == MPI_DATATYPE_NULL) {
2407 retval = MPI_ERR_TYPE;
2408 } else if (count<0 || blocklen<0){
2409 retval = MPI_ERR_COUNT;
2411 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2416 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2419 if (old_type == MPI_DATATYPE_NULL) {
2420 retval = MPI_ERR_TYPE;
2421 } else if (count<0 || blocklen<0){
2422 retval = MPI_ERR_COUNT;
2424 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2429 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2430 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2433 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2436 if (old_type == MPI_DATATYPE_NULL) {
2437 retval = MPI_ERR_TYPE;
2438 } else if (count<0){
2439 retval = MPI_ERR_COUNT;
2441 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2446 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2449 if (old_type == MPI_DATATYPE_NULL) {
2450 retval = MPI_ERR_TYPE;
2451 } else if (count<0){
2452 retval = MPI_ERR_COUNT;
2454 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2459 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type,
2460 MPI_Datatype* new_type) {
2463 if (old_type == MPI_DATATYPE_NULL) {
2464 retval = MPI_ERR_TYPE;
2465 } else if (count<0){
2466 retval = MPI_ERR_COUNT;
2468 int* blocklens=(int*)xbt_malloc(blocklength*count);
2469 for (i=0; i<count;i++)blocklens[i]=blocklength;
2470 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2471 xbt_free(blocklens);
2476 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2479 if (old_type == MPI_DATATYPE_NULL) {
2480 retval = MPI_ERR_TYPE;
2481 } else if (count<0){
2482 retval = MPI_ERR_COUNT;
2484 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2489 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,
2490 MPI_Datatype* new_type) {
2491 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2494 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type,
2495 MPI_Datatype* new_type) {
2498 if (old_type == MPI_DATATYPE_NULL) {
2499 retval = MPI_ERR_TYPE;
2500 } else if (count<0){
2501 retval = MPI_ERR_COUNT;
2503 int* blocklens=(int*)xbt_malloc(blocklength*count);
2504 for (i=0; i<count;i++)blocklens[i]=blocklength;
2505 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2506 xbt_free(blocklens);
2511 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2515 retval = MPI_ERR_COUNT;
2517 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2522 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,
2523 MPI_Datatype* new_type) {
2524 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2527 int PMPI_Error_class(int errorcode, int* errorclass) {
2528 // assume smpi uses only standard mpi error codes
2529 *errorclass=errorcode;
2533 int PMPI_Initialized(int* flag) {
2534 *flag=smpi_process_initialized();
2538 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies will be implemented, not only should we
2539 * check if the topology is NULL, but we should check if it is the good topology type (so we have to add a
2540 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2542 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2544 if (comm_old == MPI_COMM_NULL){
2545 retval = MPI_ERR_COMM;
2546 } else if (ndims < 0 || (ndims > 0 && (dims == NULL || periodic == NULL)) || comm_cart == NULL) {
2547 retval = MPI_ERR_ARG;
2549 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2554 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2555 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2556 return MPI_ERR_TOPOLOGY;
2558 if (coords == NULL) {
2561 return smpi_mpi_cart_rank(comm, coords, rank);
2564 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2565 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2566 return MPI_ERR_TOPOLOGY;
2568 if (source == NULL || dest == NULL || direction < 0 ) {
2571 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2574 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2575 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2576 return MPI_ERR_TOPOLOGY;
2578 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2579 return MPI_ERR_RANK;
2584 if(coords == NULL) {
2587 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2590 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2591 if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2592 return MPI_ERR_TOPOLOGY;
2594 if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2597 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2600 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2601 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2602 return MPI_ERR_TOPOLOGY;
2604 if (ndims == NULL) {
2607 return smpi_mpi_cartdim_get(comm, ndims);
2610 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2614 if (ndims < 1 || nnodes < 1) {
2615 return MPI_ERR_DIMS;
2618 return smpi_mpi_dims_create(nnodes, ndims, dims);
2621 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2622 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2623 return MPI_ERR_TOPOLOGY;
2625 if (comm_new == NULL) {
2628 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2631 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2632 if(oldtype == MPI_DATATYPE_NULL) {
2633 return MPI_ERR_TYPE;
2635 int blocks[3] = { 1, 1, 1 };
2636 MPI_Aint disps[3] = { lb, 0, lb+extent };
2637 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2639 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks, disps, 3, types);
2640 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, sizeof(s_smpi_mpi_struct_t) , subtype, DT_FLAG_VECTOR);
2642 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2646 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2649 if (comm == MPI_COMM_NULL) {
2650 retval= MPI_ERR_COMM;
2651 }else if ((base == NULL && size != 0) || disp_unit <= 0 || size < 0 ){
2652 retval= MPI_ERR_OTHER;
2654 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2655 retval = MPI_SUCCESS;
2661 int PMPI_Win_free( MPI_Win* win){
2664 if (win == NULL || *win == MPI_WIN_NULL) {
2665 retval = MPI_ERR_WIN;
2667 retval=smpi_mpi_win_free(win);
2673 int PMPI_Win_set_name(MPI_Win win, char * name)
2676 if (win == MPI_WIN_NULL) {
2677 retval = MPI_ERR_TYPE;
2678 } else if (name == NULL) {
2679 retval = MPI_ERR_ARG;
2681 smpi_mpi_win_set_name(win, name);
2682 retval = MPI_SUCCESS;
2687 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2689 int retval = MPI_SUCCESS;
2691 if (win == MPI_WIN_NULL) {
2692 retval = MPI_ERR_WIN;
2693 } else if (name == NULL) {
2694 retval = MPI_ERR_ARG;
2696 smpi_mpi_win_get_name(win, name, len);
2701 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2702 int retval = MPI_SUCCESS;
2703 if (win == MPI_WIN_NULL) {
2704 retval = MPI_ERR_WIN;
2706 smpi_mpi_win_get_group(win, group);
2712 int PMPI_Win_fence( int assert, MPI_Win win){
2715 if (win == MPI_WIN_NULL) {
2716 retval = MPI_ERR_WIN;
2718 int rank = smpi_process_index();
2719 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2720 retval = smpi_mpi_win_fence(assert, win);
2721 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2727 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2728 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2731 if (win == MPI_WIN_NULL) {
2732 retval = MPI_ERR_WIN;
2733 } else if (target_rank == MPI_PROC_NULL) {
2734 retval = MPI_SUCCESS;
2735 } else if (target_rank <0){
2736 retval = MPI_ERR_RANK;
2737 } else if (target_disp <0){
2738 retval = MPI_ERR_ARG;
2739 } else if (origin_count < 0 || target_count < 0) {
2740 retval = MPI_ERR_COUNT;
2741 } else if (origin_addr==NULL && origin_count > 0){
2742 retval = MPI_ERR_COUNT;
2743 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2744 retval = MPI_ERR_TYPE;
2746 int rank = smpi_process_index();
2748 smpi_mpi_win_get_group(win, &group);
2749 int src_traced = smpi_group_index(group, target_rank);
2750 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2752 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2753 target_datatype, win);
2755 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2761 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2762 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2765 if (win == MPI_WIN_NULL) {
2766 retval = MPI_ERR_WIN;
2767 } else if (target_rank == MPI_PROC_NULL) {
2768 retval = MPI_SUCCESS;
2769 } else if (target_rank <0){
2770 retval = MPI_ERR_RANK;
2771 } else if (target_disp <0){
2772 retval = MPI_ERR_ARG;
2773 } else if (origin_count < 0 || target_count < 0) {
2774 retval = MPI_ERR_COUNT;
2775 } else if (origin_addr==NULL && origin_count > 0){
2776 retval = MPI_ERR_COUNT;
2777 } else if ((!is_datatype_valid(origin_datatype)) || (!is_datatype_valid(target_datatype))) {
2778 retval = MPI_ERR_TYPE;
2780 int rank = smpi_process_index();
2782 smpi_mpi_win_get_group(win, &group);
2783 int dst_traced = smpi_group_index(group, target_rank);
2784 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, NULL);
2785 TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2787 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2788 target_datatype, win);
2790 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2796 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2797 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2800 if (win == MPI_WIN_NULL) {
2801 retval = MPI_ERR_WIN;
2802 } else if (target_rank == MPI_PROC_NULL) {
2803 retval = MPI_SUCCESS;
2804 } else if (target_rank <0){
2805 retval = MPI_ERR_RANK;
2806 } else if (target_disp <0){
2807 retval = MPI_ERR_ARG;
2808 } else if (origin_count < 0 || target_count < 0) {
2809 retval = MPI_ERR_COUNT;
2810 } else if (origin_addr==NULL && origin_count > 0){
2811 retval = MPI_ERR_COUNT;
2812 } else if ((!is_datatype_valid(origin_datatype)) ||
2813 (!is_datatype_valid(target_datatype))) {
2814 retval = MPI_ERR_TYPE;
2815 } else if (op == MPI_OP_NULL) {
2816 retval = MPI_ERR_OP;
2818 int rank = smpi_process_index();
2820 smpi_mpi_win_get_group(win, &group);
2821 int src_traced = smpi_group_index(group, target_rank);
2822 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2824 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
2825 target_datatype, op, win);
2827 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2833 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2836 if (win == MPI_WIN_NULL) {
2837 retval = MPI_ERR_WIN;
2838 } else if (group==MPI_GROUP_NULL){
2839 retval = MPI_ERR_GROUP;
2842 int rank = smpi_process_index();
2843 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2844 retval = smpi_mpi_win_post(group,assert,win);
2845 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2851 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2854 if (win == MPI_WIN_NULL) {
2855 retval = MPI_ERR_WIN;
2856 } else if (group==MPI_GROUP_NULL){
2857 retval = MPI_ERR_GROUP;
2860 int rank = smpi_process_index();
2861 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2862 retval = smpi_mpi_win_start(group,assert,win);
2863 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2869 int PMPI_Win_complete(MPI_Win win){
2872 if (win == MPI_WIN_NULL) {
2873 retval = MPI_ERR_WIN;
2876 int rank = smpi_process_index();
2877 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2879 retval = smpi_mpi_win_complete(win);
2881 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2887 int PMPI_Win_wait(MPI_Win win){
2890 if (win == MPI_WIN_NULL) {
2891 retval = MPI_ERR_WIN;
2894 int rank = smpi_process_index();
2895 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2897 retval = smpi_mpi_win_wait(win);
2899 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2905 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2906 void *ptr = xbt_malloc(size);
2908 return MPI_ERR_NO_MEM;
2910 *(void **)baseptr = ptr;
2915 int PMPI_Free_mem(void *baseptr){
2920 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2923 if (datatype == MPI_DATATYPE_NULL) {
2924 retval = MPI_ERR_TYPE;
2925 } else if (name == NULL) {
2926 retval = MPI_ERR_ARG;
2928 smpi_datatype_set_name(datatype, name);
2929 retval = MPI_SUCCESS;
2934 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2938 if (datatype == MPI_DATATYPE_NULL) {
2939 retval = MPI_ERR_TYPE;
2940 } else if (name == NULL) {
2941 retval = MPI_ERR_ARG;
2943 smpi_datatype_get_name(datatype, name, len);
2944 retval = MPI_SUCCESS;
2949 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
2950 return smpi_type_f2c(datatype);
2953 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
2954 return smpi_type_c2f( datatype);
2957 MPI_Group PMPI_Group_f2c(MPI_Fint group){
2958 return smpi_group_f2c( group);
2961 MPI_Fint PMPI_Group_c2f(MPI_Group group){
2962 return smpi_group_c2f(group);
2965 MPI_Request PMPI_Request_f2c(MPI_Fint request){
2966 return smpi_request_f2c(request);
2969 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
2970 return smpi_request_c2f(request);
2973 MPI_Win PMPI_Win_f2c(MPI_Fint win){
2974 return smpi_win_f2c(win);
2977 MPI_Fint PMPI_Win_c2f(MPI_Win win){
2978 return smpi_win_c2f(win);
2981 MPI_Op PMPI_Op_f2c(MPI_Fint op){
2982 return smpi_op_f2c(op);
2985 MPI_Fint PMPI_Op_c2f(MPI_Op op){
2986 return smpi_op_c2f(op);
2989 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
2990 return smpi_comm_f2c(comm);
2993 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
2994 return smpi_comm_c2f(comm);
2997 MPI_Info PMPI_Info_f2c(MPI_Fint info){
2998 return smpi_info_f2c(info);
3001 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3002 return smpi_info_c2f(info);
3005 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3006 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3009 int PMPI_Keyval_free(int* keyval) {
3010 return smpi_comm_keyval_free(keyval);
3013 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3014 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3015 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3017 else if (comm==MPI_COMM_NULL)
3018 return MPI_ERR_COMM;
3020 return smpi_comm_attr_delete(comm, keyval);
3023 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3025 static int zero = 0;
3026 static int tag_ub = 1000000;
3027 static int last_used_code = MPI_ERR_LASTCODE;
3029 if (comm==MPI_COMM_NULL){
3031 return MPI_ERR_COMM;
3039 *(int**)attr_value = &zero;
3041 case MPI_UNIVERSE_SIZE:
3043 *(int**)attr_value = &smpi_universe_size;
3045 case MPI_LASTUSEDCODE:
3047 *(int**)attr_value = &last_used_code;
3051 *(int**)attr_value = &tag_ub;
3053 case MPI_WTIME_IS_GLOBAL:
3055 *(int**)attr_value = &one;
3058 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3062 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3063 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3064 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3066 else if (comm==MPI_COMM_NULL)
3067 return MPI_ERR_COMM;
3069 return smpi_comm_attr_put(comm, keyval, attr_value);
3072 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3074 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3077 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3079 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3082 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3084 return PMPI_Attr_delete(comm, comm_keyval);
3087 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
3090 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3093 int PMPI_Comm_free_keyval(int* keyval) {
3094 return PMPI_Keyval_free(keyval);
3097 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3099 if (type==MPI_DATATYPE_NULL)
3100 return MPI_ERR_TYPE;
3102 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3105 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3107 if (type==MPI_DATATYPE_NULL)
3108 return MPI_ERR_TYPE;
3110 return smpi_type_attr_put(type, type_keyval, attribute_val);
3113 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3115 if (type==MPI_DATATYPE_NULL)
3116 return MPI_ERR_TYPE;
3118 return smpi_type_attr_delete(type, type_keyval);
3121 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
3124 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3127 int PMPI_Type_free_keyval(int* keyval) {
3128 return smpi_type_keyval_free(keyval);
3131 int PMPI_Info_create( MPI_Info *info){
3134 *info = xbt_new(s_smpi_mpi_info_t, 1);
3135 (*info)->info_dict= xbt_dict_new_homogeneous(NULL);
3136 (*info)->refcount=1;
3140 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3141 if (info == NULL || key == NULL || value == NULL)
3144 xbt_dict_set(info->info_dict, key, (void*)value, NULL);
3148 int PMPI_Info_free( MPI_Info *info){
3149 if (info == NULL || *info==NULL)
3151 (*info)->refcount--;
3152 if((*info)->refcount==0){
3153 xbt_dict_free(&((*info)->info_dict));
3156 *info=MPI_INFO_NULL;
3160 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3162 if (info == NULL || key == NULL || valuelen <0)
3165 return MPI_ERR_INFO_VALUE;
3166 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3168 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ? strlen(tmpvalue) + 1 : valuelen);
3174 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3175 if (info == NULL || newinfo==NULL)
3177 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3178 (*newinfo)->info_dict= xbt_dict_new_homogeneous(NULL);
3179 xbt_dict_cursor_t cursor = NULL;
3182 xbt_dict_foreach(info->info_dict,cursor,key,data){
3183 xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
3188 int PMPI_Info_delete(MPI_Info info, char *key){
3190 if (info == NULL || key==NULL)
3193 xbt_dict_remove(info->info_dict, key);
3196 return MPI_ERR_INFO_NOKEY;
3201 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3202 if (info == NULL || nkeys==NULL)
3204 *nkeys=xbt_dict_size(info->info_dict);
3208 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3209 if (info == NULL || key==NULL || n<0 || n> MPI_MAX_INFO_KEY)
3212 xbt_dict_cursor_t cursor = NULL;
3216 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3226 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3228 if (info == NULL || key == NULL || valuelen==NULL)
3230 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3232 *valuelen=strlen(tmpvalue);
3238 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3239 if(incount<0 || outcount < 0 || inbuf==NULL || outbuf==NULL)
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_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3248 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3249 if(incount<0 || outcount < 0|| inbuf==NULL || outbuf==NULL)
3251 if(!is_datatype_valid(type))
3252 return MPI_ERR_TYPE;
3253 if(comm==MPI_COMM_NULL)
3254 return MPI_ERR_COMM;
3255 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3258 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3261 if(!is_datatype_valid(datatype))
3262 return MPI_ERR_TYPE;
3263 if(comm==MPI_COMM_NULL)
3264 return MPI_ERR_COMM;
3266 *size=incount*smpi_datatype_size(datatype);