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)
187 if (datatype == MPI_DATATYPE_NULL) {
188 retval = MPI_ERR_TYPE;
189 } else if (extent == NULL) {
190 retval = MPI_ERR_ARG;
192 *extent = smpi_datatype_get_extent(datatype);
193 retval = MPI_SUCCESS;
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 if(*group!= smpi_comm_group(MPI_COMM_WORLD))// do not free the group of the comm_world
275 smpi_group_destroy(*group);
276 *group = MPI_GROUP_NULL;
277 retval = MPI_SUCCESS;
283 int PMPI_Group_size(MPI_Group group, int *size)
288 if (group == MPI_GROUP_NULL) {
289 retval = MPI_ERR_GROUP;
290 } else if (size == NULL) {
291 retval = MPI_ERR_ARG;
293 *size = smpi_group_size(group);
294 retval = MPI_SUCCESS;
300 int PMPI_Group_rank(MPI_Group group, int *rank)
305 if (group == MPI_GROUP_NULL) {
306 retval = MPI_ERR_GROUP;
307 } else if (rank == NULL) {
308 retval = MPI_ERR_ARG;
310 *rank = smpi_group_rank(group, smpi_process_index());
311 retval = MPI_SUCCESS;
317 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
318 MPI_Group group2, int *ranks2)
320 int retval, i, index;
323 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
324 retval = MPI_ERR_GROUP;
326 for (i = 0; i < n; i++) {
327 index = smpi_group_index(group1, ranks1[i]);
328 ranks2[i] = smpi_group_rank(group2, index);
330 retval = MPI_SUCCESS;
336 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
341 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
342 retval = MPI_ERR_GROUP;
343 } else if (result == NULL) {
344 retval = MPI_ERR_ARG;
346 *result = smpi_group_compare(group1, group2);
347 retval = MPI_SUCCESS;
353 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
354 MPI_Group * newgroup)
356 int retval, i, proc1, proc2, size, size2;
359 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
360 retval = MPI_ERR_GROUP;
361 } else if (newgroup == NULL) {
362 retval = MPI_ERR_ARG;
364 size = smpi_group_size(group1);
365 size2 = smpi_group_size(group2);
366 for (i = 0; i < size2; i++) {
367 proc2 = smpi_group_index(group2, i);
368 proc1 = smpi_group_rank(group1, proc2);
369 if (proc1 == MPI_UNDEFINED) {
374 *newgroup = MPI_GROUP_EMPTY;
376 *newgroup = smpi_group_new(size);
377 size2 = smpi_group_size(group1);
378 for (i = 0; i < size2; i++) {
379 proc1 = smpi_group_index(group1, i);
380 smpi_group_set_mapping(*newgroup, proc1, i);
382 for (i = size2; i < size; i++) {
383 proc2 = smpi_group_index(group2, i - size2);
384 smpi_group_set_mapping(*newgroup, proc2, i);
387 smpi_group_use(*newgroup);
388 retval = MPI_SUCCESS;
394 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
395 MPI_Group * newgroup)
397 int retval, i, proc1, proc2, size;
400 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
401 retval = MPI_ERR_GROUP;
402 } else if (newgroup == NULL) {
403 retval = MPI_ERR_ARG;
405 size = smpi_group_size(group2);
406 for (i = 0; i < size; 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);
418 for (i = 0; i < smpi_group_size(group2); i++) {
419 proc2 = smpi_group_index(group2, i);
420 proc1 = smpi_group_rank(group1, proc2);
421 if (proc1 != MPI_UNDEFINED) {
422 smpi_group_set_mapping(*newgroup, proc2, j);
427 smpi_group_use(*newgroup);
428 retval = MPI_SUCCESS;
434 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
436 int retval, i, proc1, proc2, size, size2;
439 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
440 retval = MPI_ERR_GROUP;
441 } else if (newgroup == NULL) {
442 retval = MPI_ERR_ARG;
444 size = size2 = smpi_group_size(group1);
445 for (i = 0; i < size2; i++) {
446 proc1 = smpi_group_index(group1, i);
447 proc2 = smpi_group_rank(group2, proc1);
448 if (proc2 != MPI_UNDEFINED) {
453 *newgroup = MPI_GROUP_EMPTY;
455 *newgroup = smpi_group_new(size);
456 for (i = 0; i < size2; i++) {
457 proc1 = smpi_group_index(group1, i);
458 proc2 = smpi_group_rank(group2, proc1);
459 if (proc2 == MPI_UNDEFINED) {
460 smpi_group_set_mapping(*newgroup, proc1, i);
464 smpi_group_use(*newgroup);
465 retval = MPI_SUCCESS;
471 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
473 int retval, i, index;
476 if (group == MPI_GROUP_NULL) {
477 retval = MPI_ERR_GROUP;
478 } else if (newgroup == NULL) {
479 retval = MPI_ERR_ARG;
482 *newgroup = MPI_GROUP_EMPTY;
483 } else if (n == smpi_group_size(group)) {
486 *newgroup = smpi_group_new(n);
487 for (i = 0; i < n; i++) {
488 index = smpi_group_index(group, ranks[i]);
489 smpi_group_set_mapping(*newgroup, index, i);
492 smpi_group_use(*newgroup);
493 retval = MPI_SUCCESS;
499 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
501 int retval, i, j, newsize, oldsize, index;
504 if (group == MPI_GROUP_NULL) {
505 retval = MPI_ERR_GROUP;
506 } else if (newgroup == NULL) {
507 retval = MPI_ERR_ARG;
511 } else if (n == smpi_group_size(group)) {
512 *newgroup = MPI_GROUP_EMPTY;
514 oldsize=smpi_group_size(group);
515 newsize = oldsize - n;
516 *newgroup = smpi_group_new(newsize);
518 int* to_exclude=xbt_new(int, smpi_group_size(group));
519 for(i=0; i<oldsize; i++)
522 to_exclude[ranks[i]]=1;
525 for(i=0; i<oldsize; i++){
526 if(to_exclude[i]==0){
527 index = smpi_group_index(group, i);
528 smpi_group_set_mapping(*newgroup, index, j);
533 xbt_free(to_exclude);
535 smpi_group_use(*newgroup);
536 retval = MPI_SUCCESS;
542 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
543 MPI_Group * newgroup)
545 int retval, i, j, rank, size, index;
548 if (group == MPI_GROUP_NULL) {
549 retval = MPI_ERR_GROUP;
550 } else if (newgroup == NULL) {
551 retval = MPI_ERR_ARG;
554 *newgroup = MPI_GROUP_EMPTY;
557 for (i = 0; i < n; i++) {
558 for (rank = ranges[i][0]; /* First */
559 rank >= 0 && rank <= ranges[i][1]; /* Last */
560 rank += ranges[i][2] /* Stride */ ) {
564 if (size == smpi_group_size(group)) {
567 *newgroup = smpi_group_new(size);
569 for (i = 0; i < n; i++) {
570 for (rank = ranges[i][0]; /* First */
571 rank >= 0 && rank <= ranges[i][1]; /* Last */
572 rank += ranges[i][2] /* Stride */ ) {
573 index = smpi_group_index(group, rank);
574 smpi_group_set_mapping(*newgroup, index, j);
580 smpi_group_use(*newgroup);
581 retval = MPI_SUCCESS;
587 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
588 MPI_Group * newgroup)
590 int retval, i, newrank, rank, size, index, add;
593 if (group == MPI_GROUP_NULL) {
594 retval = MPI_ERR_GROUP;
595 } else if (newgroup == NULL) {
596 retval = MPI_ERR_ARG;
601 size = smpi_group_size(group);
602 for (i = 0; i < n; i++) {
603 for (rank = ranges[i][0]; /* First */
604 rank >= 0 && rank <= ranges[i][1]; /* Last */
605 rank += ranges[i][2] /* Stride */ ) {
610 *newgroup = MPI_GROUP_EMPTY;
612 *newgroup = smpi_group_new(size);
614 while (newrank < size) {
615 for (i = 0; i < n; i++) {
617 for (rank = ranges[i][0]; /* First */
618 rank >= 0 && rank <= ranges[i][1]; /* Last */
619 rank += ranges[i][2] /* Stride */ ) {
620 if (rank == newrank) {
626 index = smpi_group_index(group, newrank);
627 smpi_group_set_mapping(*newgroup, index, newrank);
630 newrank++; //added to avoid looping, need to be checked ..
634 smpi_group_use(*newgroup);
635 retval = MPI_SUCCESS;
641 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
646 if (comm == MPI_COMM_NULL) {
647 retval = MPI_ERR_COMM;
648 } else if (rank == NULL) {
649 retval = MPI_ERR_ARG;
651 *rank = smpi_comm_rank(comm);
652 retval = MPI_SUCCESS;
658 int PMPI_Comm_size(MPI_Comm comm, int *size)
663 if (comm == MPI_COMM_NULL) {
664 retval = MPI_ERR_COMM;
665 } else if (size == NULL) {
666 retval = MPI_ERR_ARG;
668 *size = smpi_comm_size(comm);
669 retval = MPI_SUCCESS;
675 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
680 if (comm == MPI_COMM_NULL) {
681 retval = MPI_ERR_COMM;
682 } else if (name == NULL || len == NULL) {
683 retval = MPI_ERR_ARG;
685 smpi_comm_get_name(comm, name, len);
686 retval = MPI_SUCCESS;
692 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
697 if (comm == MPI_COMM_NULL) {
698 retval = MPI_ERR_COMM;
699 } else if (group == NULL) {
700 retval = MPI_ERR_ARG;
702 *group = smpi_comm_group(comm);
703 retval = MPI_SUCCESS;
709 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
714 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
715 retval = MPI_ERR_COMM;
716 } else if (result == NULL) {
717 retval = MPI_ERR_ARG;
719 if (comm1 == comm2) { /* Same communicators means same groups */
723 smpi_group_compare(smpi_comm_group(comm1),
724 smpi_comm_group(comm2));
725 if (*result == MPI_IDENT) {
726 *result = MPI_CONGRUENT;
729 retval = MPI_SUCCESS;
735 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
740 if (comm == MPI_COMM_NULL) {
741 retval = MPI_ERR_COMM;
742 } else if (newcomm == NULL) {
743 retval = MPI_ERR_ARG;
745 *newcomm = smpi_comm_new(smpi_comm_group(comm));
746 retval = MPI_SUCCESS;
752 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
757 if (comm == MPI_COMM_NULL) {
758 retval = MPI_ERR_COMM;
759 } else if (group == MPI_GROUP_NULL) {
760 retval = MPI_ERR_GROUP;
761 } else if (newcomm == NULL) {
762 retval = MPI_ERR_ARG;
764 *newcomm = smpi_comm_new(group);
765 retval = MPI_SUCCESS;
771 int PMPI_Comm_free(MPI_Comm * comm)
777 retval = MPI_ERR_ARG;
778 } else if (*comm == MPI_COMM_NULL) {
779 retval = MPI_ERR_COMM;
781 smpi_comm_destroy(*comm);
782 *comm = MPI_COMM_NULL;
783 retval = MPI_SUCCESS;
789 int PMPI_Comm_disconnect(MPI_Comm * comm)
791 /* TODO: wait until all communication in comm are done */
796 retval = MPI_ERR_ARG;
797 } else if (*comm == MPI_COMM_NULL) {
798 retval = MPI_ERR_COMM;
800 smpi_comm_destroy(*comm);
801 *comm = MPI_COMM_NULL;
802 retval = MPI_SUCCESS;
808 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
813 if (comm_out == NULL) {
814 retval = MPI_ERR_ARG;
815 } else if (comm == MPI_COMM_NULL) {
816 retval = MPI_ERR_COMM;
818 *comm_out = smpi_comm_split(comm, color, key);
819 retval = MPI_SUCCESS;
825 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
826 int tag, MPI_Comm comm, MPI_Request * request)
831 if (request == NULL) {
832 retval = MPI_ERR_ARG;
833 } else if (comm == MPI_COMM_NULL) {
834 retval = MPI_ERR_COMM;
835 } else if (dst == MPI_PROC_NULL) {
836 retval = MPI_SUCCESS;
838 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
839 retval = MPI_SUCCESS;
845 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
846 int tag, MPI_Comm comm, MPI_Request * request)
851 if (request == NULL) {
852 retval = MPI_ERR_ARG;
853 } else if (comm == MPI_COMM_NULL) {
854 retval = MPI_ERR_COMM;
855 } else if (src == MPI_PROC_NULL) {
856 retval = MPI_SUCCESS;
858 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
859 retval = MPI_SUCCESS;
865 int PMPI_Start(MPI_Request * request)
870 if (request == NULL || *request == MPI_REQUEST_NULL) {
871 retval = MPI_ERR_ARG;
873 smpi_mpi_start(*request);
874 retval = MPI_SUCCESS;
880 int PMPI_Startall(int count, MPI_Request * requests)
885 if (requests == NULL) {
886 retval = MPI_ERR_ARG;
888 smpi_mpi_startall(count, requests);
889 retval = MPI_SUCCESS;
895 int PMPI_Request_free(MPI_Request * request)
900 if (request == MPI_REQUEST_NULL) {
901 retval = MPI_ERR_ARG;
903 smpi_mpi_request_free(request);
904 retval = MPI_SUCCESS;
910 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
911 int tag, MPI_Comm comm, MPI_Request * request)
917 if (request == NULL) {
918 retval = MPI_ERR_ARG;
919 } else if (comm == MPI_COMM_NULL) {
920 retval = MPI_ERR_COMM;
921 } else if (src == MPI_PROC_NULL) {
922 *request = MPI_REQUEST_NULL;
923 retval = MPI_SUCCESS;
924 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
925 retval = MPI_ERR_COMM;
926 } else if (count < 0) {
927 retval = MPI_ERR_COUNT;
928 } else if (buf==NULL && count > 0) {
929 retval = MPI_ERR_COUNT;
930 } else if (datatype == MPI_DATATYPE_NULL){
931 retval = MPI_ERR_TYPE;
932 } else if(tag<0 && tag != MPI_ANY_TAG){
933 retval = MPI_ERR_TAG;
937 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
938 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
939 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
942 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
943 retval = MPI_SUCCESS;
946 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
947 (*request)->recv = 1;
956 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
957 int tag, MPI_Comm comm, MPI_Request * request)
962 if (request == NULL) {
963 retval = MPI_ERR_ARG;
964 } else if (comm == MPI_COMM_NULL) {
965 retval = MPI_ERR_COMM;
966 } else if (dst == MPI_PROC_NULL) {
967 *request = MPI_REQUEST_NULL;
968 retval = MPI_SUCCESS;
969 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
970 retval = MPI_ERR_COMM;
971 } else if (count < 0) {
972 retval = MPI_ERR_COUNT;
973 } else if (buf==NULL && count > 0) {
974 retval = MPI_ERR_COUNT;
975 } else if (datatype == MPI_DATATYPE_NULL){
976 retval = MPI_ERR_TYPE;
977 } else if(tag<0 && tag != MPI_ANY_TAG){
978 retval = MPI_ERR_TAG;
982 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
983 TRACE_smpi_computing_out(rank);
984 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
985 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
986 TRACE_smpi_send(rank, rank, dst_traced);
989 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
990 retval = MPI_SUCCESS;
993 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
994 (*request)->send = 1;
995 TRACE_smpi_computing_in(rank);
1005 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1006 MPI_Comm comm, MPI_Status * status)
1011 if (comm == MPI_COMM_NULL) {
1012 retval = MPI_ERR_COMM;
1013 } else if (src == MPI_PROC_NULL) {
1014 smpi_empty_status(status);
1015 status->MPI_SOURCE = MPI_PROC_NULL;
1016 retval = MPI_SUCCESS;
1017 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1018 retval = MPI_ERR_COMM;
1019 } else if (count < 0) {
1020 retval = MPI_ERR_COUNT;
1021 } else if (buf==NULL && count > 0) {
1022 retval = MPI_ERR_COUNT;
1023 } else if (datatype == MPI_DATATYPE_NULL){
1024 retval = MPI_ERR_TYPE;
1025 } else if(tag<0 && tag != MPI_ANY_TAG){
1026 retval = MPI_ERR_TAG;
1029 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1030 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1031 TRACE_smpi_computing_out(rank);
1033 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
1036 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1037 retval = MPI_SUCCESS;
1040 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1041 if(status!=MPI_STATUS_IGNORE)src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1042 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1043 TRACE_smpi_recv(rank, src_traced, rank);
1044 TRACE_smpi_computing_in(rank);
1052 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1059 if (comm == MPI_COMM_NULL) {
1060 retval = MPI_ERR_COMM;
1061 } else if (dst == MPI_PROC_NULL) {
1062 retval = MPI_SUCCESS;
1063 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1064 retval = MPI_ERR_COMM;
1065 } else if (count < 0) {
1066 retval = MPI_ERR_COUNT;
1067 } else if (buf==NULL && count > 0) {
1068 retval = MPI_ERR_COUNT;
1069 } else if (datatype == MPI_DATATYPE_NULL){
1070 retval = MPI_ERR_TYPE;
1071 } else if(tag<0 && tag != MPI_ANY_TAG){
1072 retval = MPI_ERR_TAG;
1076 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1077 TRACE_smpi_computing_out(rank);
1078 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1079 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1080 TRACE_smpi_send(rank, rank, dst_traced);
1083 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1084 retval = MPI_SUCCESS;
1087 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1088 TRACE_smpi_computing_in(rank);
1096 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1097 int dst, int sendtag, void *recvbuf, int recvcount,
1098 MPI_Datatype recvtype, int src, int recvtag,
1099 MPI_Comm comm, MPI_Status * status)
1105 if (comm == MPI_COMM_NULL) {
1106 retval = MPI_ERR_COMM;
1107 } else if (sendtype == MPI_DATATYPE_NULL
1108 || recvtype == MPI_DATATYPE_NULL) {
1109 retval = MPI_ERR_TYPE;
1110 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1111 smpi_empty_status(status);
1112 status->MPI_SOURCE = MPI_PROC_NULL;
1113 retval = MPI_SUCCESS;
1114 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1115 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1116 retval = MPI_ERR_COMM;
1117 } else if (sendcount < 0 || recvcount<0) {
1118 retval = MPI_ERR_COUNT;
1119 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1120 retval = MPI_ERR_COUNT;
1121 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1122 retval = MPI_ERR_TAG;
1126 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1127 TRACE_smpi_computing_out(rank);
1128 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1129 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1130 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1131 TRACE_smpi_send(rank, rank, dst_traced);
1132 TRACE_smpi_send(rank, src_traced, rank);
1136 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1137 recvcount, recvtype, src, recvtag, comm, status);
1138 retval = MPI_SUCCESS;
1141 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1142 TRACE_smpi_recv(rank, rank, dst_traced);
1143 TRACE_smpi_recv(rank, src_traced, rank);
1144 TRACE_smpi_computing_in(rank);
1153 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1154 int dst, int sendtag, int src, int recvtag,
1155 MPI_Comm comm, MPI_Status * status)
1157 //TODO: suboptimal implementation
1160 if ((datatype == MPI_DATATYPE_NULL)||(datatype->has_subtype==1)) {
1161 retval = MPI_ERR_TYPE;
1162 } else if (count < 0) {
1163 retval = MPI_ERR_COUNT;
1165 int size = smpi_datatype_size(datatype) * count;
1166 recvbuf = xbt_new(char, size);
1168 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1169 datatype, src, recvtag, comm, status);
1170 if(retval==MPI_SUCCESS){
1171 memcpy(buf, recvbuf, size * sizeof(char));
1179 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1184 if (request == MPI_REQUEST_NULL || flag == NULL) {
1185 retval = MPI_ERR_ARG;
1186 } else if (*request == MPI_REQUEST_NULL) {
1188 retval = MPI_ERR_REQUEST;
1190 *flag = smpi_mpi_test(request, status);
1191 retval = MPI_SUCCESS;
1197 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1198 MPI_Status * status)
1203 if (index == NULL || flag == NULL) {
1204 retval = MPI_ERR_ARG;
1206 *flag = smpi_mpi_testany(count, requests, index, status);
1207 retval = MPI_SUCCESS;
1213 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1219 retval = MPI_ERR_ARG;
1221 *flag = smpi_mpi_testall(count, requests, statuses);
1222 retval = MPI_SUCCESS;
1228 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1232 if (status == NULL) {
1233 retval = MPI_ERR_ARG;
1234 } else if (comm == MPI_COMM_NULL) {
1235 retval = MPI_ERR_COMM;
1236 } else if (source == MPI_PROC_NULL) {
1237 smpi_empty_status(status);
1238 status->MPI_SOURCE = MPI_PROC_NULL;
1239 retval = MPI_SUCCESS;
1241 smpi_mpi_probe(source, tag, comm, status);
1242 retval = MPI_SUCCESS;
1249 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1254 retval = MPI_ERR_ARG;
1255 } else if (status == NULL) {
1256 retval = MPI_ERR_ARG;
1257 } else if (comm == MPI_COMM_NULL) {
1258 retval = MPI_ERR_COMM;
1259 } else if (source == MPI_PROC_NULL) {
1260 smpi_empty_status(status);
1261 status->MPI_SOURCE = MPI_PROC_NULL;
1262 retval = MPI_SUCCESS;
1264 smpi_mpi_iprobe(source, tag, comm, flag, status);
1265 retval = MPI_SUCCESS;
1271 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1277 if (request == NULL) {
1278 retval = MPI_ERR_ARG;
1279 } else if (*request == MPI_REQUEST_NULL) {
1280 retval = MPI_ERR_REQUEST;
1284 int rank = request && (*request)->comm != MPI_COMM_NULL
1285 ? smpi_process_index()
1287 TRACE_smpi_computing_out(rank);
1289 MPI_Group group = smpi_comm_group((*request)->comm);
1290 int src_traced = smpi_group_index(group, (*request)->src);
1291 int dst_traced = smpi_group_index(group, (*request)->dst);
1292 int is_wait_for_receive = (*request)->recv;
1293 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1296 smpi_mpi_wait(request, status);
1297 retval = MPI_SUCCESS;
1300 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1301 if (is_wait_for_receive) {
1302 TRACE_smpi_recv(rank, src_traced, dst_traced);
1304 TRACE_smpi_computing_in(rank);
1313 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1319 //save requests information for tracing
1321 xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
1322 xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
1323 xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
1324 for (i = 0; i < count; i++) {
1325 MPI_Request req = requests[i]; //already received requests are no longer valid
1327 int *asrc = xbt_new(int, 1);
1328 int *adst = xbt_new(int, 1);
1329 int *arecv = xbt_new(int, 1);
1333 xbt_dynar_insert_at(srcs, i, asrc);
1334 xbt_dynar_insert_at(dsts, i, adst);
1335 xbt_dynar_insert_at(recvs, i, arecv);
1340 int *t = xbt_new(int, 1);
1341 xbt_dynar_insert_at(srcs, i, t);
1342 xbt_dynar_insert_at(dsts, i, t);
1343 xbt_dynar_insert_at(recvs, i, t);
1347 int rank_traced = smpi_process_index();
1348 TRACE_smpi_computing_out(rank_traced);
1350 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1353 if (index == NULL) {
1354 retval = MPI_ERR_ARG;
1356 *index = smpi_mpi_waitany(count, requests, status);
1357 retval = MPI_SUCCESS;
1360 if(*index!=MPI_UNDEFINED){
1361 int src_traced, dst_traced, is_wait_for_receive;
1362 xbt_dynar_get_cpy(srcs, *index, &src_traced);
1363 xbt_dynar_get_cpy(dsts, *index, &dst_traced);
1364 xbt_dynar_get_cpy(recvs, *index, &is_wait_for_receive);
1365 if (is_wait_for_receive) {
1366 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1368 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1369 //clean-up of dynars
1370 xbt_dynar_free(&srcs);
1371 xbt_dynar_free(&dsts);
1372 xbt_dynar_free(&recvs);
1374 TRACE_smpi_computing_in(rank_traced);
1380 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1385 //save information from requests
1387 xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), NULL);
1388 xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), NULL);
1389 xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), NULL);
1390 for (i = 0; i < count; i++) {
1391 MPI_Request req = requests[i];
1393 int *asrc = xbt_new(int, 1);
1394 int *adst = xbt_new(int, 1);
1395 int *arecv = xbt_new(int, 1);
1399 xbt_dynar_insert_at(srcs, i, asrc);
1400 xbt_dynar_insert_at(dsts, i, adst);
1401 xbt_dynar_insert_at(recvs, i, arecv);
1406 int *t = xbt_new(int, 1);
1407 xbt_dynar_insert_at(srcs, i, t);
1408 xbt_dynar_insert_at(dsts, i, t);
1409 xbt_dynar_insert_at(recvs, i, t);
1413 int rank_traced = smpi_process_index();
1414 TRACE_smpi_computing_out(rank_traced);
1416 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1418 int retval = smpi_mpi_waitall(count, requests, status);
1420 for (i = 0; i < count; i++) {
1421 int src_traced, dst_traced, is_wait_for_receive;
1422 xbt_dynar_get_cpy(srcs, i, &src_traced);
1423 xbt_dynar_get_cpy(dsts, i, &dst_traced);
1424 xbt_dynar_get_cpy(recvs, i, &is_wait_for_receive);
1425 if (is_wait_for_receive) {
1426 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1429 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1430 //clean-up of dynars
1431 xbt_dynar_free(&srcs);
1432 xbt_dynar_free(&dsts);
1433 xbt_dynar_free(&recvs);
1434 TRACE_smpi_computing_in(rank_traced);
1440 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1441 int *indices, MPI_Status status[])
1446 if (outcount == NULL || indices == NULL) {
1447 retval = MPI_ERR_ARG;
1449 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1450 retval = MPI_SUCCESS;
1456 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1457 int* indices, MPI_Status status[])
1462 if (outcount == NULL || indices == NULL) {
1463 retval = MPI_ERR_ARG;
1465 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1466 retval = MPI_SUCCESS;
1473 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1479 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1480 TRACE_smpi_computing_out(rank);
1481 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1482 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1484 if (comm == MPI_COMM_NULL) {
1485 retval = MPI_ERR_COMM;
1487 smpi_mpi_bcast(buf, count, datatype, root, comm);
1488 retval = MPI_SUCCESS;
1491 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1492 TRACE_smpi_computing_in(rank);
1498 int PMPI_Barrier(MPI_Comm comm)
1504 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1505 TRACE_smpi_computing_out(rank);
1506 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1508 if (comm == MPI_COMM_NULL) {
1509 retval = MPI_ERR_COMM;
1511 smpi_mpi_barrier(comm);
1512 retval = MPI_SUCCESS;
1515 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1516 TRACE_smpi_computing_in(rank);
1522 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1523 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1524 int root, MPI_Comm comm)
1530 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1531 TRACE_smpi_computing_out(rank);
1532 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1533 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1535 if (comm == MPI_COMM_NULL) {
1536 retval = MPI_ERR_COMM;
1537 } else if (sendtype == MPI_DATATYPE_NULL
1538 || recvtype == MPI_DATATYPE_NULL) {
1539 retval = MPI_ERR_TYPE;
1541 smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1542 recvtype, root, comm);
1543 retval = MPI_SUCCESS;
1546 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1547 TRACE_smpi_computing_in(rank);
1553 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1554 void *recvbuf, int *recvcounts, int *displs,
1555 MPI_Datatype recvtype, int root, MPI_Comm comm)
1561 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1562 TRACE_smpi_computing_out(rank);
1563 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1564 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1566 if (comm == MPI_COMM_NULL) {
1567 retval = MPI_ERR_COMM;
1568 } else if (sendtype == MPI_DATATYPE_NULL
1569 || recvtype == MPI_DATATYPE_NULL) {
1570 retval = MPI_ERR_TYPE;
1571 } else if (recvcounts == NULL || displs == NULL) {
1572 retval = MPI_ERR_ARG;
1574 smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1575 displs, recvtype, root, comm);
1576 retval = MPI_SUCCESS;
1579 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1580 TRACE_smpi_computing_in(rank);
1586 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1587 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1594 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1595 TRACE_smpi_computing_out(rank);
1596 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1598 if (comm == MPI_COMM_NULL) {
1599 retval = MPI_ERR_COMM;
1600 } else if (sendtype == MPI_DATATYPE_NULL
1601 || recvtype == MPI_DATATYPE_NULL) {
1602 retval = MPI_ERR_TYPE;
1604 smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1606 retval = MPI_SUCCESS;
1609 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1615 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1616 void *recvbuf, int *recvcounts, int *displs,
1617 MPI_Datatype recvtype, MPI_Comm comm)
1623 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1624 TRACE_smpi_computing_out(rank);
1625 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1627 if (comm == MPI_COMM_NULL) {
1628 retval = MPI_ERR_COMM;
1629 } else if (sendtype == MPI_DATATYPE_NULL
1630 || recvtype == MPI_DATATYPE_NULL) {
1631 retval = MPI_ERR_TYPE;
1632 } else if (recvcounts == NULL || displs == NULL) {
1633 retval = MPI_ERR_ARG;
1635 smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1636 displs, recvtype, comm);
1637 retval = MPI_SUCCESS;
1640 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1641 TRACE_smpi_computing_in(rank);
1647 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1648 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1649 int root, MPI_Comm comm)
1655 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1656 TRACE_smpi_computing_out(rank);
1657 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1659 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1661 if (comm == MPI_COMM_NULL) {
1662 retval = MPI_ERR_COMM;
1663 } else if (sendtype == MPI_DATATYPE_NULL
1664 || recvtype == MPI_DATATYPE_NULL) {
1665 retval = MPI_ERR_TYPE;
1667 smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1668 recvtype, root, comm);
1669 retval = MPI_SUCCESS;
1672 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1673 TRACE_smpi_computing_in(rank);
1679 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1680 MPI_Datatype sendtype, void *recvbuf, int recvcount,
1681 MPI_Datatype recvtype, int root, MPI_Comm comm)
1687 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1688 TRACE_smpi_computing_out(rank);
1689 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1690 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1692 if (comm == MPI_COMM_NULL) {
1693 retval = MPI_ERR_COMM;
1694 } else if (sendtype == MPI_DATATYPE_NULL
1695 || recvtype == MPI_DATATYPE_NULL) {
1696 retval = MPI_ERR_TYPE;
1697 } else if (sendcounts == NULL || displs == NULL) {
1698 retval = MPI_ERR_ARG;
1700 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
1701 recvcount, recvtype, root, comm);
1702 retval = MPI_SUCCESS;
1705 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1706 TRACE_smpi_computing_in(rank);
1712 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
1713 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1719 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1720 TRACE_smpi_computing_out(rank);
1721 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1722 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1724 if (comm == MPI_COMM_NULL) {
1725 retval = MPI_ERR_COMM;
1726 } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
1727 retval = MPI_ERR_ARG;
1729 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
1730 retval = MPI_SUCCESS;
1733 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1734 TRACE_smpi_computing_in(rank);
1740 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
1741 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1747 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1748 TRACE_smpi_computing_out(rank);
1749 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1751 if (comm == MPI_COMM_NULL) {
1752 retval = MPI_ERR_COMM;
1753 } else if (datatype == MPI_DATATYPE_NULL) {
1754 retval = MPI_ERR_TYPE;
1755 } else if (op == MPI_OP_NULL) {
1756 retval = MPI_ERR_OP;
1758 smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
1759 retval = MPI_SUCCESS;
1762 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1763 TRACE_smpi_computing_in(rank);
1769 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
1770 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1776 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1777 TRACE_smpi_computing_out(rank);
1778 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1780 if (comm == MPI_COMM_NULL) {
1781 retval = MPI_ERR_COMM;
1782 } else if (datatype == MPI_DATATYPE_NULL) {
1783 retval = MPI_ERR_TYPE;
1784 } else if (op == MPI_OP_NULL) {
1785 retval = MPI_ERR_OP;
1787 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
1788 retval = MPI_SUCCESS;
1791 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1792 TRACE_smpi_computing_in(rank);
1798 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
1799 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1801 int retval, i, size, count;
1803 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1807 TRACE_smpi_computing_out(rank);
1808 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1810 if (comm == MPI_COMM_NULL) {
1811 retval = MPI_ERR_COMM;
1812 } else if (datatype == MPI_DATATYPE_NULL) {
1813 retval = MPI_ERR_TYPE;
1814 } else if (op == MPI_OP_NULL) {
1815 retval = MPI_ERR_OP;
1816 } else if (recvcounts == NULL) {
1817 retval = MPI_ERR_ARG;
1819 /* arbitrarily choose root as rank 0 */
1820 /* TODO: faster direct implementation ? */
1821 size = smpi_comm_size(comm);
1823 displs = xbt_new(int, size);
1824 for (i = 0; i < size; i++) {
1825 count += recvcounts[i];
1828 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
1829 smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf,
1830 recvcounts[rank], datatype, 0, comm);
1832 retval = MPI_SUCCESS;
1835 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1836 TRACE_smpi_computing_in(rank);
1842 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1843 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1846 int retval, size, sendsize;
1850 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1851 TRACE_smpi_computing_out(rank);
1852 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1854 if (comm == MPI_COMM_NULL) {
1855 retval = MPI_ERR_COMM;
1856 } else if (sendtype == MPI_DATATYPE_NULL
1857 || recvtype == MPI_DATATYPE_NULL) {
1858 retval = MPI_ERR_TYPE;
1860 size = smpi_comm_size(comm);
1861 sendsize = smpi_datatype_size(sendtype) * sendcount;
1862 if (sendsize < 200 && size > 12) {
1864 smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype,
1865 recvbuf, recvcount, recvtype,
1867 } else if (sendsize < 3000) {
1869 smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount,
1871 recvcount, recvtype, comm);
1874 smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype,
1875 recvbuf, recvcount, recvtype,
1880 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1881 TRACE_smpi_computing_in(rank);
1887 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
1888 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
1889 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
1895 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1896 TRACE_smpi_computing_out(rank);
1897 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1899 if (comm == MPI_COMM_NULL) {
1900 retval = MPI_ERR_COMM;
1901 } else if (sendtype == MPI_DATATYPE_NULL
1902 || recvtype == MPI_DATATYPE_NULL) {
1903 retval = MPI_ERR_TYPE;
1904 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
1905 || recvdisps == NULL) {
1906 retval = MPI_ERR_ARG;
1909 smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype,
1910 recvbuf, recvcounts, recvdisps, recvtype,
1914 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1915 TRACE_smpi_computing_in(rank);
1922 int PMPI_Get_processor_name(char *name, int *resultlen)
1924 int retval = MPI_SUCCESS;
1927 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
1928 strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
1929 strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
1930 MPI_MAX_PROCESSOR_NAME - 1 );
1933 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
1939 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
1941 int retval = MPI_SUCCESS;
1945 if (status == NULL || count == NULL) {
1946 retval = MPI_ERR_ARG;
1947 } else if (datatype == MPI_DATATYPE_NULL) {
1948 retval = MPI_ERR_TYPE;
1950 size = smpi_datatype_size(datatype);
1953 } else if (status->count % size != 0) {
1954 retval = MPI_UNDEFINED;
1956 *count = smpi_mpi_get_count(status, datatype);
1963 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
1967 if (old_type == MPI_DATATYPE_NULL) {
1968 retval = MPI_ERR_TYPE;
1969 } else if (count<0){
1970 retval = MPI_ERR_COUNT;
1972 retval = smpi_datatype_contiguous(count, old_type, new_type);
1978 int PMPI_Type_commit(MPI_Datatype* datatype) {
1982 if (datatype == MPI_DATATYPE_NULL) {
1983 retval = MPI_ERR_TYPE;
1985 smpi_datatype_commit(datatype);
1986 retval = MPI_SUCCESS;
1993 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
1997 if (old_type == MPI_DATATYPE_NULL) {
1998 retval = MPI_ERR_TYPE;
1999 } else if (count<0 || blocklen<0){
2000 retval = MPI_ERR_COUNT;
2002 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2008 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2012 if (old_type == MPI_DATATYPE_NULL) {
2013 retval = MPI_ERR_TYPE;
2014 } else if (count<0 || blocklen<0){
2015 retval = MPI_ERR_COUNT;
2017 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2024 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2028 if (old_type == MPI_DATATYPE_NULL) {
2029 retval = MPI_ERR_TYPE;
2030 } else if (count<0){
2031 retval = MPI_ERR_COUNT;
2033 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2039 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2043 if (old_type == MPI_DATATYPE_NULL) {
2044 retval = MPI_ERR_TYPE;
2045 } else if (count<0){
2046 retval = MPI_ERR_COUNT;
2048 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2055 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2060 retval = MPI_ERR_COUNT;
2062 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2067 int PMPI_Error_class(int errorcode, int* errorclass) {
2068 // assume smpi uses only standard mpi error codes
2069 *errorclass=errorcode;
2073 /* The following calls are not yet implemented and will fail at runtime. */
2074 /* Once implemented, please move them above this notice. */
2076 static int not_yet_implemented(void) {
2077 XBT_WARN("Not yet implemented");
2081 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2082 return not_yet_implemented();
2085 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2086 return not_yet_implemented();
2089 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periods, int reorder, MPI_Comm* comm_cart) {
2090 return not_yet_implemented();
2093 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2094 return not_yet_implemented();
2097 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2098 return not_yet_implemented();
2101 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2102 return not_yet_implemented();
2105 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2106 return not_yet_implemented();
2109 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2110 return not_yet_implemented();
2113 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2114 return not_yet_implemented();
2117 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2118 return not_yet_implemented();
2121 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2122 return not_yet_implemented();
2125 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2126 return not_yet_implemented();
2129 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2130 return not_yet_implemented();
2133 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2134 return not_yet_implemented();
2137 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2138 return not_yet_implemented();
2141 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2142 return not_yet_implemented();
2145 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2146 return not_yet_implemented();
2149 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2150 return not_yet_implemented();
2153 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2154 return not_yet_implemented();
2157 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2158 return not_yet_implemented();
2161 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2162 return not_yet_implemented();
2166 int PMPI_Cancel(MPI_Request* request) {
2167 return not_yet_implemented();
2170 int PMPI_Buffer_attach(void* buffer, int size) {
2171 return not_yet_implemented();
2174 int PMPI_Buffer_detach(void* buffer, int* size) {
2175 return not_yet_implemented();
2178 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2179 return not_yet_implemented();
2182 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2184 return not_yet_implemented();
2187 int PMPI_Pcontrol(const int level )
2189 return not_yet_implemented();
2192 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2193 return not_yet_implemented();
2196 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2197 return not_yet_implemented();
2200 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2201 return not_yet_implemented();
2204 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2205 return not_yet_implemented();
2208 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2209 return not_yet_implemented();
2212 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2213 return not_yet_implemented();
2216 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2217 return not_yet_implemented();
2220 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2221 return not_yet_implemented();
2224 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2225 return not_yet_implemented();
2228 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2229 return not_yet_implemented();
2232 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2233 return not_yet_implemented();
2237 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2238 return not_yet_implemented();
2241 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2242 return not_yet_implemented();
2245 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2246 return not_yet_implemented();
2249 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2250 return not_yet_implemented();
2253 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2254 return not_yet_implemented();
2257 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2258 return not_yet_implemented();
2261 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2262 return not_yet_implemented();
2265 int PMPI_Keyval_free(int* keyval) {
2266 return not_yet_implemented();
2269 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2270 return not_yet_implemented();
2273 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2274 return not_yet_implemented();
2277 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2278 return not_yet_implemented();
2281 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2282 return not_yet_implemented();
2285 int PMPI_Initialized(int* flag) {
2286 return not_yet_implemented();