1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "smpi_mpi_dt_private.h"
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
11 "Logging specific to SMPI (pmpi)");
14 //this function need to be here because of the calls to smpi_bench
15 void TRACE_smpi_set_category(const char *category)
17 //need to end bench otherwise categories for execution tasks are wrong
19 TRACE_internal_smpi_set_category (category);
20 //begin bench after changing process's category
25 /* PMPI User level calls */
27 int PMPI_Init(int *argc, char ***argv)
29 smpi_process_init(argc, argv);
31 int rank = smpi_process_index();
32 TRACE_smpi_init(rank);
34 TRACE_smpi_computing_init(rank);
40 int PMPI_Finalize(void)
42 smpi_process_finalize();
45 int rank = smpi_process_index();
46 TRACE_smpi_computing_out(rank);
47 TRACE_smpi_finalize(smpi_process_index());
49 smpi_process_destroy();
53 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
55 if (provided != NULL) {
56 *provided = MPI_THREAD_MULTIPLE;
58 return MPI_Init(argc, argv);
61 int PMPI_Query_thread(int *provided)
66 if (provided == NULL) {
69 *provided = MPI_THREAD_MULTIPLE;
76 int PMPI_Is_thread_main(int *flag)
84 *flag = smpi_process_index() == 0;
91 int PMPI_Abort(MPI_Comm comm, int errorcode)
94 smpi_process_destroy();
96 int rank = smpi_process_index();
97 TRACE_smpi_computing_out(rank);
99 // FIXME: should kill all processes in comm instead
100 simcall_process_kill(SIMIX_process_self());
104 double PMPI_Wtime(void)
109 time = SIMIX_get_clock();
113 extern double sg_maxmin_precision;
114 double PMPI_Wtick(void)
116 return sg_maxmin_precision;
119 int PMPI_Address(void *location, MPI_Aint * address)
125 retval = MPI_ERR_ARG;
127 *address = (MPI_Aint) location;
128 retval = MPI_SUCCESS;
134 int PMPI_Type_free(MPI_Datatype * datatype)
140 retval = MPI_ERR_ARG;
142 smpi_datatype_free(datatype);
143 retval = MPI_SUCCESS;
149 int PMPI_Type_size(MPI_Datatype datatype, int *size)
154 if (datatype == MPI_DATATYPE_NULL) {
155 retval = MPI_ERR_TYPE;
156 } else if (size == NULL) {
157 retval = MPI_ERR_ARG;
159 *size = (int) smpi_datatype_size(datatype);
160 retval = MPI_SUCCESS;
166 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
171 if (datatype == MPI_DATATYPE_NULL) {
172 retval = MPI_ERR_TYPE;
173 } else if (lb == NULL || extent == NULL) {
174 retval = MPI_ERR_ARG;
176 retval = smpi_datatype_extent(datatype, lb, extent);
182 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
188 if (datatype == MPI_DATATYPE_NULL) {
189 retval = MPI_ERR_TYPE;
190 } else if (extent == NULL) {
191 retval = MPI_ERR_ARG;
193 retval = smpi_datatype_extent(datatype, &dummy, extent);
199 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
204 if (datatype == MPI_DATATYPE_NULL) {
205 retval = MPI_ERR_TYPE;
206 } else if (disp == NULL) {
207 retval = MPI_ERR_ARG;
209 *disp = smpi_datatype_lb(datatype);
210 retval = MPI_SUCCESS;
216 int PMPI_Type_ub(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_ub(datatype);
227 retval = MPI_SUCCESS;
233 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
238 if (function == NULL || op == NULL) {
239 retval = MPI_ERR_ARG;
241 *op = smpi_op_new(function, commute);
242 retval = MPI_SUCCESS;
248 int PMPI_Op_free(MPI_Op * op)
254 retval = MPI_ERR_ARG;
255 } else if (*op == MPI_OP_NULL) {
258 smpi_op_destroy(*op);
260 retval = MPI_SUCCESS;
266 int PMPI_Group_free(MPI_Group * group)
272 retval = MPI_ERR_ARG;
274 smpi_group_destroy(*group);
275 *group = MPI_GROUP_NULL;
276 retval = MPI_SUCCESS;
282 int PMPI_Group_size(MPI_Group group, int *size)
287 if (group == MPI_GROUP_NULL) {
288 retval = MPI_ERR_GROUP;
289 } else if (size == NULL) {
290 retval = MPI_ERR_ARG;
292 *size = smpi_group_size(group);
293 retval = MPI_SUCCESS;
299 int PMPI_Group_rank(MPI_Group group, int *rank)
304 if (group == MPI_GROUP_NULL) {
305 retval = MPI_ERR_GROUP;
306 } else if (rank == NULL) {
307 retval = MPI_ERR_ARG;
309 *rank = smpi_group_rank(group, smpi_process_index());
310 retval = MPI_SUCCESS;
316 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
317 MPI_Group group2, int *ranks2)
319 int retval, i, index;
322 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
323 retval = MPI_ERR_GROUP;
325 for (i = 0; i < n; i++) {
326 index = smpi_group_index(group1, ranks1[i]);
327 ranks2[i] = smpi_group_rank(group2, index);
329 retval = MPI_SUCCESS;
335 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
340 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
341 retval = MPI_ERR_GROUP;
342 } else if (result == NULL) {
343 retval = MPI_ERR_ARG;
345 *result = smpi_group_compare(group1, group2);
346 retval = MPI_SUCCESS;
352 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
353 MPI_Group * newgroup)
355 int retval, i, proc1, proc2, size, size2;
358 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
359 retval = MPI_ERR_GROUP;
360 } else if (newgroup == NULL) {
361 retval = MPI_ERR_ARG;
363 size = smpi_group_size(group1);
364 size2 = smpi_group_size(group2);
365 for (i = 0; i < size2; i++) {
366 proc2 = smpi_group_index(group2, i);
367 proc1 = smpi_group_rank(group1, proc2);
368 if (proc1 == MPI_UNDEFINED) {
373 *newgroup = MPI_GROUP_EMPTY;
375 *newgroup = smpi_group_new(size);
376 size2 = smpi_group_size(group1);
377 for (i = 0; i < size2; i++) {
378 proc1 = smpi_group_index(group1, i);
379 smpi_group_set_mapping(*newgroup, proc1, i);
381 for (i = size2; i < size; i++) {
382 proc2 = smpi_group_index(group2, i - size2);
383 smpi_group_set_mapping(*newgroup, proc2, i);
386 smpi_group_use(*newgroup);
387 retval = MPI_SUCCESS;
393 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
394 MPI_Group * newgroup)
396 int retval, i, proc1, proc2, size, size2;
399 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
400 retval = MPI_ERR_GROUP;
401 } else if (newgroup == NULL) {
402 retval = MPI_ERR_ARG;
404 size = smpi_group_size(group1);
405 size2 = smpi_group_size(group2);
406 for (i = 0; i < size2; i++) {
407 proc2 = smpi_group_index(group2, i);
408 proc1 = smpi_group_rank(group1, proc2);
409 if (proc1 == MPI_UNDEFINED) {
414 *newgroup = MPI_GROUP_EMPTY;
416 *newgroup = smpi_group_new(size);
417 size2 = smpi_group_size(group1);
418 for (i = 0; i < size2; i++) {
419 proc1 = smpi_group_index(group1, i);
420 proc2 = smpi_group_rank(group2, proc1);
421 if (proc2 != MPI_UNDEFINED) {
422 smpi_group_set_mapping(*newgroup, proc1, i);
426 smpi_group_use(*newgroup);
427 retval = MPI_SUCCESS;
433 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
435 int retval, i, proc1, proc2, size, size2;
438 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
439 retval = MPI_ERR_GROUP;
440 } else if (newgroup == NULL) {
441 retval = MPI_ERR_ARG;
443 size = size2 = smpi_group_size(group1);
444 for (i = 0; i < size2; i++) {
445 proc1 = smpi_group_index(group1, i);
446 proc2 = smpi_group_rank(group2, proc1);
447 if (proc2 != MPI_UNDEFINED) {
452 *newgroup = MPI_GROUP_EMPTY;
454 *newgroup = smpi_group_new(size);
455 for (i = 0; i < size2; i++) {
456 proc1 = smpi_group_index(group1, i);
457 proc2 = smpi_group_rank(group2, proc1);
458 if (proc2 == MPI_UNDEFINED) {
459 smpi_group_set_mapping(*newgroup, proc1, i);
463 smpi_group_use(*newgroup);
464 retval = MPI_SUCCESS;
470 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
472 int retval, i, index;
475 if (group == MPI_GROUP_NULL) {
476 retval = MPI_ERR_GROUP;
477 } else if (newgroup == NULL) {
478 retval = MPI_ERR_ARG;
481 *newgroup = MPI_GROUP_EMPTY;
482 } else if (n == smpi_group_size(group)) {
485 *newgroup = smpi_group_new(n);
486 for (i = 0; i < n; i++) {
487 index = smpi_group_index(group, ranks[i]);
488 smpi_group_set_mapping(*newgroup, index, i);
491 smpi_group_use(*newgroup);
492 retval = MPI_SUCCESS;
498 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
500 int retval, i, size, rank, index;
503 if (group == MPI_GROUP_NULL) {
504 retval = MPI_ERR_GROUP;
505 } else if (newgroup == NULL) {
506 retval = MPI_ERR_ARG;
510 } else if (n == smpi_group_size(group)) {
511 *newgroup = MPI_GROUP_EMPTY;
513 size = smpi_group_size(group) - n;
514 *newgroup = smpi_group_new(size);
516 while (rank < size) {
517 for (i = 0; i < n; i++) {
518 if (ranks[i] == rank) {
523 index = smpi_group_index(group, rank);
524 smpi_group_set_mapping(*newgroup, index, rank);
529 smpi_group_use(*newgroup);
530 retval = MPI_SUCCESS;
536 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
537 MPI_Group * newgroup)
539 int retval, i, j, rank, size, index;
542 if (group == MPI_GROUP_NULL) {
543 retval = MPI_ERR_GROUP;
544 } else if (newgroup == NULL) {
545 retval = MPI_ERR_ARG;
548 *newgroup = MPI_GROUP_EMPTY;
551 for (i = 0; i < n; i++) {
552 for (rank = ranges[i][0]; /* First */
553 rank >= 0 && rank <= ranges[i][1]; /* Last */
554 rank += ranges[i][2] /* Stride */ ) {
558 if (size == smpi_group_size(group)) {
561 *newgroup = smpi_group_new(size);
563 for (i = 0; i < n; i++) {
564 for (rank = ranges[i][0]; /* First */
565 rank >= 0 && rank <= ranges[i][1]; /* Last */
566 rank += ranges[i][2] /* Stride */ ) {
567 index = smpi_group_index(group, rank);
568 smpi_group_set_mapping(*newgroup, index, j);
574 smpi_group_use(*newgroup);
575 retval = MPI_SUCCESS;
581 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
582 MPI_Group * newgroup)
584 int retval, i, newrank, rank, size, index, add;
587 if (group == MPI_GROUP_NULL) {
588 retval = MPI_ERR_GROUP;
589 } else if (newgroup == NULL) {
590 retval = MPI_ERR_ARG;
595 size = smpi_group_size(group);
596 for (i = 0; i < n; i++) {
597 for (rank = ranges[i][0]; /* First */
598 rank >= 0 && rank <= ranges[i][1]; /* Last */
599 rank += ranges[i][2] /* Stride */ ) {
604 *newgroup = MPI_GROUP_EMPTY;
606 *newgroup = smpi_group_new(size);
608 while (newrank < size) {
609 for (i = 0; i < n; i++) {
611 for (rank = ranges[i][0]; /* First */
612 rank >= 0 && rank <= ranges[i][1]; /* Last */
613 rank += ranges[i][2] /* Stride */ ) {
614 if (rank == newrank) {
620 index = smpi_group_index(group, newrank);
621 smpi_group_set_mapping(*newgroup, index, newrank);
627 smpi_group_use(*newgroup);
628 retval = MPI_SUCCESS;
634 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
639 if (comm == MPI_COMM_NULL) {
640 retval = MPI_ERR_COMM;
641 } else if (rank == NULL) {
642 retval = MPI_ERR_ARG;
644 *rank = smpi_comm_rank(comm);
645 retval = MPI_SUCCESS;
651 int PMPI_Comm_size(MPI_Comm comm, int *size)
656 if (comm == MPI_COMM_NULL) {
657 retval = MPI_ERR_COMM;
658 } else if (size == NULL) {
659 retval = MPI_ERR_ARG;
661 *size = smpi_comm_size(comm);
662 retval = MPI_SUCCESS;
668 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
673 if (comm == MPI_COMM_NULL) {
674 retval = MPI_ERR_COMM;
675 } else if (name == NULL || len == NULL) {
676 retval = MPI_ERR_ARG;
678 smpi_comm_get_name(comm, name, len);
679 retval = MPI_SUCCESS;
685 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
690 if (comm == MPI_COMM_NULL) {
691 retval = MPI_ERR_COMM;
692 } else if (group == NULL) {
693 retval = MPI_ERR_ARG;
695 *group = smpi_comm_group(comm);
696 retval = MPI_SUCCESS;
702 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
707 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
708 retval = MPI_ERR_COMM;
709 } else if (result == NULL) {
710 retval = MPI_ERR_ARG;
712 if (comm1 == comm2) { /* Same communicators means same groups */
716 smpi_group_compare(smpi_comm_group(comm1),
717 smpi_comm_group(comm2));
718 if (*result == MPI_IDENT) {
719 *result = MPI_CONGRUENT;
722 retval = MPI_SUCCESS;
728 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
733 if (comm == MPI_COMM_NULL) {
734 retval = MPI_ERR_COMM;
735 } else if (newcomm == NULL) {
736 retval = MPI_ERR_ARG;
738 *newcomm = smpi_comm_new(smpi_comm_group(comm));
739 retval = MPI_SUCCESS;
745 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
750 if (comm == MPI_COMM_NULL) {
751 retval = MPI_ERR_COMM;
752 } else if (group == MPI_GROUP_NULL) {
753 retval = MPI_ERR_GROUP;
754 } else if (newcomm == NULL) {
755 retval = MPI_ERR_ARG;
757 *newcomm = smpi_comm_new(group);
758 retval = MPI_SUCCESS;
764 int PMPI_Comm_free(MPI_Comm * comm)
770 retval = MPI_ERR_ARG;
771 } else if (*comm == MPI_COMM_NULL) {
772 retval = MPI_ERR_COMM;
774 smpi_comm_destroy(*comm);
775 *comm = MPI_COMM_NULL;
776 retval = MPI_SUCCESS;
782 int PMPI_Comm_disconnect(MPI_Comm * comm)
784 /* TODO: wait until all communication in comm are done */
789 retval = MPI_ERR_ARG;
790 } else if (*comm == MPI_COMM_NULL) {
791 retval = MPI_ERR_COMM;
793 smpi_comm_destroy(*comm);
794 *comm = MPI_COMM_NULL;
795 retval = MPI_SUCCESS;
801 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
806 if (comm_out == NULL) {
807 retval = MPI_ERR_ARG;
808 } else if (comm == MPI_COMM_NULL) {
809 retval = MPI_ERR_COMM;
811 *comm_out = smpi_comm_split(comm, color, key);
812 retval = MPI_SUCCESS;
818 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
819 int tag, MPI_Comm comm, MPI_Request * request)
824 if (request == NULL) {
825 retval = MPI_ERR_ARG;
826 } else if (comm == MPI_COMM_NULL) {
827 retval = MPI_ERR_COMM;
828 } else if (dst == MPI_PROC_NULL) {
829 retval = MPI_SUCCESS;
831 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
832 retval = MPI_SUCCESS;
838 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
839 int tag, MPI_Comm comm, MPI_Request * request)
844 if (request == NULL) {
845 retval = MPI_ERR_ARG;
846 } else if (comm == MPI_COMM_NULL) {
847 retval = MPI_ERR_COMM;
848 } else if (src == MPI_PROC_NULL) {
849 retval = MPI_SUCCESS;
851 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
852 retval = MPI_SUCCESS;
858 int PMPI_Start(MPI_Request * request)
863 if (request == NULL || *request == MPI_REQUEST_NULL) {
864 retval = MPI_ERR_ARG;
866 smpi_mpi_start(*request);
867 retval = MPI_SUCCESS;
873 int PMPI_Startall(int count, MPI_Request * requests)
878 if (requests == NULL) {
879 retval = MPI_ERR_ARG;
881 smpi_mpi_startall(count, requests);
882 retval = MPI_SUCCESS;
888 int PMPI_Request_free(MPI_Request * request)
893 if (request == MPI_REQUEST_NULL) {
894 retval = MPI_ERR_ARG;
896 smpi_mpi_request_free(request);
897 retval = MPI_SUCCESS;
903 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
904 int tag, MPI_Comm comm, MPI_Request * request)
910 if (request == NULL) {
911 retval = MPI_ERR_ARG;
912 } else if (comm == MPI_COMM_NULL) {
913 retval = MPI_ERR_COMM;
914 } else if (src == MPI_PROC_NULL) {
915 *request = MPI_REQUEST_NULL;
916 retval = MPI_SUCCESS;
917 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
918 retval = MPI_ERR_COMM;
919 } else if (count < 0) {
920 retval = MPI_ERR_COUNT;
921 } else if (buf==NULL && count > 0) {
922 retval = MPI_ERR_COUNT;
923 } else if (datatype == MPI_DATATYPE_NULL){
924 retval = MPI_ERR_TYPE;
925 } else if(tag<0 && tag != MPI_ANY_TAG){
926 retval = MPI_ERR_TAG;
930 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
931 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
932 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
935 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
936 retval = MPI_SUCCESS;
939 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
940 (*request)->recv = 1;
949 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
950 int tag, MPI_Comm comm, MPI_Request * request)
955 if (request == NULL) {
956 retval = MPI_ERR_ARG;
957 } else if (comm == MPI_COMM_NULL) {
958 retval = MPI_ERR_COMM;
959 } else if (dst == MPI_PROC_NULL) {
960 *request = MPI_REQUEST_NULL;
961 retval = MPI_SUCCESS;
962 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
963 retval = MPI_ERR_COMM;
964 } else if (count < 0) {
965 retval = MPI_ERR_COUNT;
966 } else if (buf==NULL && count > 0) {
967 retval = MPI_ERR_COUNT;
968 } else if (datatype == MPI_DATATYPE_NULL){
969 retval = MPI_ERR_TYPE;
970 } else if(tag<0 && tag != MPI_ANY_TAG){
971 retval = MPI_ERR_TAG;
975 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
976 TRACE_smpi_computing_out(rank);
977 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
978 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
979 TRACE_smpi_send(rank, rank, dst_traced);
982 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
983 retval = MPI_SUCCESS;
986 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
987 (*request)->send = 1;
988 TRACE_smpi_computing_in(rank);
998 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
999 MPI_Comm comm, MPI_Status * status)
1005 if (comm == MPI_COMM_NULL) {
1006 retval = MPI_ERR_COMM;
1007 } else if (src == MPI_PROC_NULL) {
1008 smpi_empty_status(status);
1009 status->MPI_SOURCE = MPI_PROC_NULL;
1010 retval = MPI_SUCCESS;
1011 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1012 retval = MPI_ERR_COMM;
1013 } else if (count < 0) {
1014 retval = MPI_ERR_COUNT;
1015 } else if (buf==NULL && count > 0) {
1016 retval = MPI_ERR_COUNT;
1017 } else if (datatype == MPI_DATATYPE_NULL){
1018 retval = MPI_ERR_TYPE;
1019 } else if(tag<0 && tag != MPI_ANY_TAG){
1020 retval = MPI_ERR_TAG;
1023 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1024 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1025 TRACE_smpi_computing_out(rank);
1027 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
1030 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1031 retval = MPI_SUCCESS;
1034 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1035 if(status!=MPI_STATUS_IGNORE)src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1036 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1037 TRACE_smpi_recv(rank, src_traced, rank);
1038 TRACE_smpi_computing_in(rank);
1046 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1053 if (comm == MPI_COMM_NULL) {
1054 retval = MPI_ERR_COMM;
1055 } else if (dst == MPI_PROC_NULL) {
1056 retval = MPI_SUCCESS;
1057 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1058 retval = MPI_ERR_COMM;
1059 } else if (count < 0) {
1060 retval = MPI_ERR_COUNT;
1061 } else if (buf==NULL && count > 0) {
1062 retval = MPI_ERR_COUNT;
1063 } else if (datatype == MPI_DATATYPE_NULL){
1064 retval = MPI_ERR_TYPE;
1065 } else if(tag<0 && tag != MPI_ANY_TAG){
1066 retval = MPI_ERR_TAG;
1070 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1071 TRACE_smpi_computing_out(rank);
1072 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1073 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1074 TRACE_smpi_send(rank, rank, dst_traced);
1077 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1078 retval = MPI_SUCCESS;
1081 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1082 TRACE_smpi_computing_in(rank);
1090 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1091 int dst, int sendtag, void *recvbuf, int recvcount,
1092 MPI_Datatype recvtype, int src, int recvtag,
1093 MPI_Comm comm, MPI_Status * status)
1099 if (comm == MPI_COMM_NULL) {
1100 retval = MPI_ERR_COMM;
1101 } else if (sendtype == MPI_DATATYPE_NULL
1102 || recvtype == MPI_DATATYPE_NULL) {
1103 retval = MPI_ERR_TYPE;
1104 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1105 smpi_empty_status(status);
1106 status->MPI_SOURCE = MPI_PROC_NULL;
1107 retval = MPI_SUCCESS;
1108 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1109 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1110 retval = MPI_ERR_COMM;
1111 } else if (sendcount < 0 || recvcount<0) {
1112 retval = MPI_ERR_COUNT;
1113 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1114 retval = MPI_ERR_COUNT;
1115 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1116 retval = MPI_ERR_TAG;
1120 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1121 TRACE_smpi_computing_out(rank);
1122 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1123 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1124 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1125 TRACE_smpi_send(rank, rank, dst_traced);
1126 TRACE_smpi_send(rank, src_traced, rank);
1130 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1131 recvcount, recvtype, src, recvtag, comm, status);
1132 retval = MPI_SUCCESS;
1135 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1136 TRACE_smpi_recv(rank, rank, dst_traced);
1137 TRACE_smpi_recv(rank, src_traced, rank);
1138 TRACE_smpi_computing_in(rank);
1147 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1148 int dst, int sendtag, int src, int recvtag,
1149 MPI_Comm comm, MPI_Status * status)
1151 //TODO: suboptimal implementation
1155 size = smpi_datatype_size(datatype) * count;
1156 recvbuf = xbt_new(char, size);
1158 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1159 datatype, src, recvtag, comm, status);
1160 memcpy(buf, recvbuf, size * sizeof(char));
1165 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1170 if (request == MPI_REQUEST_NULL || flag == NULL) {
1171 retval = MPI_ERR_ARG;
1172 } else if (*request == MPI_REQUEST_NULL) {
1174 retval = MPI_ERR_REQUEST;
1176 *flag = smpi_mpi_test(request, status);
1177 retval = MPI_SUCCESS;
1183 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1184 MPI_Status * status)
1189 if (index == NULL || flag == NULL) {
1190 retval = MPI_ERR_ARG;
1192 *flag = smpi_mpi_testany(count, requests, index, status);
1193 retval = MPI_SUCCESS;
1199 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1205 retval = MPI_ERR_ARG;
1207 *flag = smpi_mpi_testall(count, requests, statuses);
1208 retval = MPI_SUCCESS;
1214 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1218 if (status == NULL) {
1219 retval = MPI_ERR_ARG;
1220 } else if (comm == MPI_COMM_NULL) {
1221 retval = MPI_ERR_COMM;
1222 } else if (source == MPI_PROC_NULL) {
1223 smpi_empty_status(status);
1224 status->MPI_SOURCE = MPI_PROC_NULL;
1225 retval = MPI_SUCCESS;
1227 smpi_mpi_probe(source, tag, comm, status);
1228 retval = MPI_SUCCESS;
1235 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1240 retval = MPI_ERR_ARG;
1241 } else if (status == NULL) {
1242 retval = MPI_ERR_ARG;
1243 } else if (comm == MPI_COMM_NULL) {
1244 retval = MPI_ERR_COMM;
1245 } else if (source == MPI_PROC_NULL) {
1246 smpi_empty_status(status);
1247 status->MPI_SOURCE = MPI_PROC_NULL;
1248 retval = MPI_SUCCESS;
1250 smpi_mpi_iprobe(source, tag, comm, flag, status);
1251 retval = MPI_SUCCESS;
1257 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1263 if (request == NULL) {
1264 retval = MPI_ERR_ARG;
1265 } else if (*request == MPI_REQUEST_NULL) {
1266 retval = MPI_ERR_REQUEST;
1270 int rank = request && (*request)->comm != MPI_COMM_NULL
1271 ? smpi_process_index()
1273 TRACE_smpi_computing_out(rank);
1275 MPI_Group group = smpi_comm_group((*request)->comm);
1276 int src_traced = smpi_group_index(group, (*request)->src);
1277 int dst_traced = smpi_group_index(group, (*request)->dst);
1278 int is_wait_for_receive = (*request)->recv;
1279 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1282 smpi_mpi_wait(request, status);
1283 retval = MPI_SUCCESS;
1286 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1287 if (is_wait_for_receive) {
1288 TRACE_smpi_recv(rank, src_traced, dst_traced);
1290 TRACE_smpi_computing_in(rank);
1299 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1305 //save requests information for tracing
1307 xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
1308 xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
1309 xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
1310 for (i = 0; i < count; i++) {
1311 MPI_Request req = requests[i]; //already received requests are no longer valid
1313 int *asrc = xbt_new(int, 1);
1314 int *adst = xbt_new(int, 1);
1315 int *arecv = xbt_new(int, 1);
1319 xbt_dynar_insert_at(srcs, i, asrc);
1320 xbt_dynar_insert_at(dsts, i, adst);
1321 xbt_dynar_insert_at(recvs, i, arecv);
1326 int *t = xbt_new(int, 1);
1327 xbt_dynar_insert_at(srcs, i, t);
1328 xbt_dynar_insert_at(dsts, i, t);
1329 xbt_dynar_insert_at(recvs, i, t);
1333 int rank_traced = smpi_process_index();
1334 TRACE_smpi_computing_out(rank_traced);
1336 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1339 if (index == NULL) {
1340 retval = MPI_ERR_ARG;
1342 *index = smpi_mpi_waitany(count, requests, status);
1343 retval = MPI_SUCCESS;
1346 if(*index!=MPI_UNDEFINED){
1347 int src_traced, dst_traced, is_wait_for_receive;
1348 xbt_dynar_get_cpy(srcs, *index, &src_traced);
1349 xbt_dynar_get_cpy(dsts, *index, &dst_traced);
1350 xbt_dynar_get_cpy(recvs, *index, &is_wait_for_receive);
1351 if (is_wait_for_receive) {
1352 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1354 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1355 //clean-up of dynars
1356 xbt_dynar_free(&srcs);
1357 xbt_dynar_free(&dsts);
1358 xbt_dynar_free(&recvs);
1360 TRACE_smpi_computing_in(rank_traced);
1368 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1373 //save information from requests
1375 xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
1376 xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
1377 xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
1378 for (i = 0; i < count; i++) {
1379 MPI_Request req = requests[i];
1381 int *asrc = xbt_new(int, 1);
1382 int *adst = xbt_new(int, 1);
1383 int *arecv = xbt_new(int, 1);
1387 xbt_dynar_insert_at(srcs, i, asrc);
1388 xbt_dynar_insert_at(dsts, i, adst);
1389 xbt_dynar_insert_at(recvs, i, arecv);
1394 int *t = xbt_new(int, 1);
1395 xbt_dynar_insert_at(srcs, i, t);
1396 xbt_dynar_insert_at(dsts, i, t);
1397 xbt_dynar_insert_at(recvs, i, t);
1401 int rank_traced = smpi_process_index();
1402 TRACE_smpi_computing_out(rank_traced);
1404 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1406 smpi_mpi_waitall(count, requests, status);
1408 for (i = 0; i < count; i++) {
1409 int src_traced, dst_traced, is_wait_for_receive;
1410 xbt_dynar_get_cpy(srcs, i, &src_traced);
1411 xbt_dynar_get_cpy(dsts, i, &dst_traced);
1412 xbt_dynar_get_cpy(recvs, i, &is_wait_for_receive);
1413 if (is_wait_for_receive) {
1414 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1417 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1418 //clean-up of dynars
1419 xbt_dynar_free(&srcs);
1420 xbt_dynar_free(&dsts);
1421 xbt_dynar_free(&recvs);
1422 TRACE_smpi_computing_in(rank_traced);
1428 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1429 int *indices, MPI_Status status[])
1434 if (outcount == NULL || indices == NULL) {
1435 retval = MPI_ERR_ARG;
1437 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1438 retval = MPI_SUCCESS;
1444 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1445 int* indices, MPI_Status status[])
1450 if (outcount == NULL || indices == NULL) {
1451 retval = MPI_ERR_ARG;
1453 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1454 retval = MPI_SUCCESS;
1461 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1467 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1468 TRACE_smpi_computing_out(rank);
1469 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1470 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1472 if (comm == MPI_COMM_NULL) {
1473 retval = MPI_ERR_COMM;
1475 smpi_mpi_bcast(buf, count, datatype, root, comm);
1476 retval = MPI_SUCCESS;
1479 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1480 TRACE_smpi_computing_in(rank);
1486 int PMPI_Barrier(MPI_Comm comm)
1492 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1493 TRACE_smpi_computing_out(rank);
1494 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1496 if (comm == MPI_COMM_NULL) {
1497 retval = MPI_ERR_COMM;
1499 smpi_mpi_barrier(comm);
1500 retval = MPI_SUCCESS;
1503 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1504 TRACE_smpi_computing_in(rank);
1510 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1511 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1512 int root, MPI_Comm comm)
1518 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1519 TRACE_smpi_computing_out(rank);
1520 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1521 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1523 if (comm == MPI_COMM_NULL) {
1524 retval = MPI_ERR_COMM;
1525 } else if (sendtype == MPI_DATATYPE_NULL
1526 || recvtype == MPI_DATATYPE_NULL) {
1527 retval = MPI_ERR_TYPE;
1529 smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1530 recvtype, root, comm);
1531 retval = MPI_SUCCESS;
1534 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1535 TRACE_smpi_computing_in(rank);
1541 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1542 void *recvbuf, int *recvcounts, int *displs,
1543 MPI_Datatype recvtype, int root, MPI_Comm comm)
1549 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1550 TRACE_smpi_computing_out(rank);
1551 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1552 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1554 if (comm == MPI_COMM_NULL) {
1555 retval = MPI_ERR_COMM;
1556 } else if (sendtype == MPI_DATATYPE_NULL
1557 || recvtype == MPI_DATATYPE_NULL) {
1558 retval = MPI_ERR_TYPE;
1559 } else if (recvcounts == NULL || displs == NULL) {
1560 retval = MPI_ERR_ARG;
1562 smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1563 displs, recvtype, root, comm);
1564 retval = MPI_SUCCESS;
1567 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1568 TRACE_smpi_computing_in(rank);
1574 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1575 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1582 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1583 TRACE_smpi_computing_out(rank);
1584 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1586 if (comm == MPI_COMM_NULL) {
1587 retval = MPI_ERR_COMM;
1588 } else if (sendtype == MPI_DATATYPE_NULL
1589 || recvtype == MPI_DATATYPE_NULL) {
1590 retval = MPI_ERR_TYPE;
1592 smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1594 retval = MPI_SUCCESS;
1597 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1603 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1604 void *recvbuf, int *recvcounts, int *displs,
1605 MPI_Datatype recvtype, MPI_Comm comm)
1611 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1612 TRACE_smpi_computing_out(rank);
1613 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1615 if (comm == MPI_COMM_NULL) {
1616 retval = MPI_ERR_COMM;
1617 } else if (sendtype == MPI_DATATYPE_NULL
1618 || recvtype == MPI_DATATYPE_NULL) {
1619 retval = MPI_ERR_TYPE;
1620 } else if (recvcounts == NULL || displs == NULL) {
1621 retval = MPI_ERR_ARG;
1623 smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1624 displs, recvtype, comm);
1625 retval = MPI_SUCCESS;
1628 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1629 TRACE_smpi_computing_in(rank);
1635 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1636 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1637 int root, MPI_Comm comm)
1643 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1644 TRACE_smpi_computing_out(rank);
1645 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1647 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1649 if (comm == MPI_COMM_NULL) {
1650 retval = MPI_ERR_COMM;
1651 } else if (sendtype == MPI_DATATYPE_NULL
1652 || recvtype == MPI_DATATYPE_NULL) {
1653 retval = MPI_ERR_TYPE;
1655 smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1656 recvtype, root, comm);
1657 retval = MPI_SUCCESS;
1660 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1661 TRACE_smpi_computing_in(rank);
1667 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1668 MPI_Datatype sendtype, void *recvbuf, int recvcount,
1669 MPI_Datatype recvtype, int root, MPI_Comm comm)
1675 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1676 TRACE_smpi_computing_out(rank);
1677 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1678 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1680 if (comm == MPI_COMM_NULL) {
1681 retval = MPI_ERR_COMM;
1682 } else if (sendtype == MPI_DATATYPE_NULL
1683 || recvtype == MPI_DATATYPE_NULL) {
1684 retval = MPI_ERR_TYPE;
1685 } else if (sendcounts == NULL || displs == NULL) {
1686 retval = MPI_ERR_ARG;
1688 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
1689 recvcount, recvtype, root, comm);
1690 retval = MPI_SUCCESS;
1693 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1694 TRACE_smpi_computing_in(rank);
1700 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
1701 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1707 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1708 TRACE_smpi_computing_out(rank);
1709 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1710 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1712 if (comm == MPI_COMM_NULL) {
1713 retval = MPI_ERR_COMM;
1714 } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
1715 retval = MPI_ERR_ARG;
1717 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
1718 retval = MPI_SUCCESS;
1721 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1722 TRACE_smpi_computing_in(rank);
1728 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
1729 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1735 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1736 TRACE_smpi_computing_out(rank);
1737 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1739 if (comm == MPI_COMM_NULL) {
1740 retval = MPI_ERR_COMM;
1741 } else if (datatype == MPI_DATATYPE_NULL) {
1742 retval = MPI_ERR_TYPE;
1743 } else if (op == MPI_OP_NULL) {
1744 retval = MPI_ERR_OP;
1746 smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
1747 retval = MPI_SUCCESS;
1750 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1751 TRACE_smpi_computing_in(rank);
1757 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
1758 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1764 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1765 TRACE_smpi_computing_out(rank);
1766 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1768 if (comm == MPI_COMM_NULL) {
1769 retval = MPI_ERR_COMM;
1770 } else if (datatype == MPI_DATATYPE_NULL) {
1771 retval = MPI_ERR_TYPE;
1772 } else if (op == MPI_OP_NULL) {
1773 retval = MPI_ERR_OP;
1775 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
1776 retval = MPI_SUCCESS;
1779 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1780 TRACE_smpi_computing_in(rank);
1786 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
1787 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1789 int retval, i, size, count;
1791 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1795 TRACE_smpi_computing_out(rank);
1796 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1798 if (comm == MPI_COMM_NULL) {
1799 retval = MPI_ERR_COMM;
1800 } else if (datatype == MPI_DATATYPE_NULL) {
1801 retval = MPI_ERR_TYPE;
1802 } else if (op == MPI_OP_NULL) {
1803 retval = MPI_ERR_OP;
1804 } else if (recvcounts == NULL) {
1805 retval = MPI_ERR_ARG;
1807 /* arbitrarily choose root as rank 0 */
1808 /* TODO: faster direct implementation ? */
1809 size = smpi_comm_size(comm);
1811 displs = xbt_new(int, size);
1812 for (i = 0; i < size; i++) {
1813 count += recvcounts[i];
1816 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
1817 smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf,
1818 recvcounts[rank], datatype, 0, comm);
1820 retval = MPI_SUCCESS;
1823 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1824 TRACE_smpi_computing_in(rank);
1830 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1831 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1834 int retval, size, sendsize;
1838 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1839 TRACE_smpi_computing_out(rank);
1840 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1842 if (comm == MPI_COMM_NULL) {
1843 retval = MPI_ERR_COMM;
1844 } else if (sendtype == MPI_DATATYPE_NULL
1845 || recvtype == MPI_DATATYPE_NULL) {
1846 retval = MPI_ERR_TYPE;
1848 size = smpi_comm_size(comm);
1849 sendsize = smpi_datatype_size(sendtype) * sendcount;
1850 if (sendsize < 200 && size > 12) {
1852 smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype,
1853 recvbuf, recvcount, recvtype,
1855 } else if (sendsize < 3000) {
1857 smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount,
1859 recvcount, recvtype, comm);
1862 smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype,
1863 recvbuf, recvcount, recvtype,
1868 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1869 TRACE_smpi_computing_in(rank);
1875 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
1876 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
1877 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
1883 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1884 TRACE_smpi_computing_out(rank);
1885 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1887 if (comm == MPI_COMM_NULL) {
1888 retval = MPI_ERR_COMM;
1889 } else if (sendtype == MPI_DATATYPE_NULL
1890 || recvtype == MPI_DATATYPE_NULL) {
1891 retval = MPI_ERR_TYPE;
1892 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
1893 || recvdisps == NULL) {
1894 retval = MPI_ERR_ARG;
1897 smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype,
1898 recvbuf, recvcounts, recvdisps, recvtype,
1902 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1903 TRACE_smpi_computing_in(rank);
1910 int PMPI_Get_processor_name(char *name, int *resultlen)
1912 int retval = MPI_SUCCESS;
1915 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
1916 MPI_MAX_PROCESSOR_NAME - 1);
1919 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
1925 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
1927 int retval = MPI_SUCCESS;
1931 if (status == NULL || count == NULL) {
1932 retval = MPI_ERR_ARG;
1933 } else if (datatype == MPI_DATATYPE_NULL) {
1934 retval = MPI_ERR_TYPE;
1936 size = smpi_datatype_size(datatype);
1939 } else if (status->count % size != 0) {
1940 retval = MPI_UNDEFINED;
1942 *count = smpi_mpi_get_count(status, datatype);
1949 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
1953 if (old_type == MPI_DATATYPE_NULL) {
1954 retval = MPI_ERR_TYPE;
1955 } else if (count<=0){
1956 retval = MPI_ERR_COUNT;
1958 retval = smpi_datatype_contiguous(count, old_type, new_type);
1964 int PMPI_Type_commit(MPI_Datatype* datatype) {
1968 if (datatype == MPI_DATATYPE_NULL) {
1969 retval = MPI_ERR_TYPE;
1971 smpi_datatype_commit(datatype);
1972 retval = MPI_SUCCESS;
1979 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
1983 if (old_type == MPI_DATATYPE_NULL) {
1984 retval = MPI_ERR_TYPE;
1985 } else if (count<=0 || blocklen<=0){
1986 retval = MPI_ERR_COUNT;
1988 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
1994 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
1998 if (old_type == MPI_DATATYPE_NULL) {
1999 retval = MPI_ERR_TYPE;
2000 } else if (count<=0 || blocklen<=0){
2001 retval = MPI_ERR_COUNT;
2003 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2010 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2014 if (old_type == MPI_DATATYPE_NULL) {
2015 retval = MPI_ERR_TYPE;
2016 } else if (count<=0){
2017 retval = MPI_ERR_COUNT;
2019 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2025 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2029 if (old_type == MPI_DATATYPE_NULL) {
2030 retval = MPI_ERR_TYPE;
2031 } else if (count<=0){
2032 retval = MPI_ERR_COUNT;
2034 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2041 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2046 retval = MPI_ERR_COUNT;
2048 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2054 /* The following calls are not yet implemented and will fail at runtime. */
2055 /* Once implemented, please move them above this notice. */
2057 static int not_yet_implemented(void) {
2058 XBT_WARN("Not yet implemented");
2062 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2063 return not_yet_implemented();
2066 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2067 return not_yet_implemented();
2070 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periods, int reorder, MPI_Comm* comm_cart) {
2071 return not_yet_implemented();
2074 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2075 return not_yet_implemented();
2078 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2079 return not_yet_implemented();
2082 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2083 return not_yet_implemented();
2086 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2087 return not_yet_implemented();
2090 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2091 return not_yet_implemented();
2094 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2095 return not_yet_implemented();
2098 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2099 return not_yet_implemented();
2102 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2103 return not_yet_implemented();
2106 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2107 return not_yet_implemented();
2110 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2111 return not_yet_implemented();
2114 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2115 return not_yet_implemented();
2118 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2119 return not_yet_implemented();
2122 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2123 return not_yet_implemented();
2126 int PMPI_Error_class(int errorcode, int* errorclass) {
2127 return not_yet_implemented();
2130 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2131 return not_yet_implemented();
2134 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2135 return not_yet_implemented();
2138 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2139 return not_yet_implemented();
2142 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2143 return not_yet_implemented();
2146 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2147 return not_yet_implemented();
2151 int PMPI_Cancel(MPI_Request* request) {
2152 return not_yet_implemented();
2155 int PMPI_Buffer_attach(void* buffer, int size) {
2156 return not_yet_implemented();
2159 int PMPI_Buffer_detach(void* buffer, int* size) {
2160 return not_yet_implemented();
2163 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2164 return not_yet_implemented();
2167 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2169 return not_yet_implemented();
2172 int PMPI_Pcontrol(const int level )
2174 return not_yet_implemented();
2177 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2178 return not_yet_implemented();
2181 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2182 return not_yet_implemented();
2185 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2186 return not_yet_implemented();
2189 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2190 return not_yet_implemented();
2193 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2194 return not_yet_implemented();
2197 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2198 return not_yet_implemented();
2201 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2202 return not_yet_implemented();
2205 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2206 return not_yet_implemented();
2209 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2210 return not_yet_implemented();
2213 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2214 return not_yet_implemented();
2217 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2218 return not_yet_implemented();
2222 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2223 return not_yet_implemented();
2226 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2227 return not_yet_implemented();
2230 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2231 return not_yet_implemented();
2234 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2235 return not_yet_implemented();
2238 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2239 return not_yet_implemented();
2242 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2243 return not_yet_implemented();
2246 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2247 return not_yet_implemented();
2250 int PMPI_Keyval_free(int* keyval) {
2251 return not_yet_implemented();
2254 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2255 return not_yet_implemented();
2258 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2259 return not_yet_implemented();
2262 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2263 return not_yet_implemented();
2266 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2267 return not_yet_implemented();
2270 int PMPI_Initialized(int* flag) {
2271 return not_yet_implemented();