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_Ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
869 if (request == NULL) {
870 retval = MPI_ERR_ARG;
871 } else if (comm == MPI_COMM_NULL) {
872 retval = MPI_ERR_COMM;
873 } else if (dst == MPI_PROC_NULL) {
874 retval = MPI_SUCCESS;
876 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
877 retval = MPI_SUCCESS;
883 int PMPI_Start(MPI_Request * request)
888 if (request == NULL || *request == MPI_REQUEST_NULL) {
889 retval = MPI_ERR_ARG;
891 smpi_mpi_start(*request);
892 retval = MPI_SUCCESS;
898 int PMPI_Startall(int count, MPI_Request * requests)
903 if (requests == NULL) {
904 retval = MPI_ERR_ARG;
906 smpi_mpi_startall(count, requests);
907 retval = MPI_SUCCESS;
913 int PMPI_Request_free(MPI_Request * request)
918 if (*request == MPI_REQUEST_NULL) {
919 retval = MPI_ERR_ARG;
921 if((*request)->flags & PERSISTENT)(*request)->refcount--;
922 smpi_mpi_request_free(request);
923 retval = MPI_SUCCESS;
929 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
930 int tag, MPI_Comm comm, MPI_Request * request)
936 if (request == NULL) {
937 retval = MPI_ERR_ARG;
938 } else if (comm == MPI_COMM_NULL) {
939 retval = MPI_ERR_COMM;
940 } else if (src == MPI_PROC_NULL) {
941 *request = MPI_REQUEST_NULL;
942 retval = MPI_SUCCESS;
943 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
944 retval = MPI_ERR_COMM;
945 } else if (count < 0) {
946 retval = MPI_ERR_COUNT;
947 } else if (buf==NULL && count > 0) {
948 retval = MPI_ERR_COUNT;
949 } else if (datatype == MPI_DATATYPE_NULL){
950 retval = MPI_ERR_TYPE;
951 } else if(tag<0 && tag != MPI_ANY_TAG){
952 retval = MPI_ERR_TAG;
956 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
957 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
958 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
961 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
962 retval = MPI_SUCCESS;
965 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
966 (*request)->recv = 1;
975 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
976 int tag, MPI_Comm comm, MPI_Request * request)
981 if (request == NULL) {
982 retval = MPI_ERR_ARG;
983 } else if (comm == MPI_COMM_NULL) {
984 retval = MPI_ERR_COMM;
985 } else if (dst == MPI_PROC_NULL) {
986 *request = MPI_REQUEST_NULL;
987 retval = MPI_SUCCESS;
988 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
989 retval = MPI_ERR_COMM;
990 } else if (count < 0) {
991 retval = MPI_ERR_COUNT;
992 } else if (buf==NULL && count > 0) {
993 retval = MPI_ERR_COUNT;
994 } else if (datatype == MPI_DATATYPE_NULL){
995 retval = MPI_ERR_TYPE;
996 } else if(tag<0 && tag != MPI_ANY_TAG){
997 retval = MPI_ERR_TAG;
1001 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1002 TRACE_smpi_computing_out(rank);
1003 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1004 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1005 TRACE_smpi_send(rank, rank, dst_traced);
1008 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1009 retval = MPI_SUCCESS;
1012 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1013 (*request)->send = 1;
1014 TRACE_smpi_computing_in(rank);
1022 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
1026 if (request == NULL) {
1027 retval = MPI_ERR_ARG;
1028 } else if (comm == MPI_COMM_NULL) {
1029 retval = MPI_ERR_COMM;
1030 } else if (dst == MPI_PROC_NULL) {
1031 *request = MPI_REQUEST_NULL;
1032 retval = MPI_SUCCESS;
1033 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1034 retval = MPI_ERR_COMM;
1035 } else if (count < 0) {
1036 retval = MPI_ERR_COUNT;
1037 } else if (buf==NULL && count > 0) {
1038 retval = MPI_ERR_COUNT;
1039 } else if (datatype == MPI_DATATYPE_NULL){
1040 retval = MPI_ERR_TYPE;
1041 } else if(tag<0 && tag != MPI_ANY_TAG){
1042 retval = MPI_ERR_TAG;
1046 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1047 TRACE_smpi_computing_out(rank);
1048 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1049 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1050 TRACE_smpi_send(rank, rank, dst_traced);
1053 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1054 retval = MPI_SUCCESS;
1057 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1058 (*request)->send = 1;
1059 TRACE_smpi_computing_in(rank);
1067 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1068 MPI_Comm comm, MPI_Status * status)
1073 if (comm == MPI_COMM_NULL) {
1074 retval = MPI_ERR_COMM;
1075 } else if (src == MPI_PROC_NULL) {
1076 smpi_empty_status(status);
1077 status->MPI_SOURCE = MPI_PROC_NULL;
1078 retval = MPI_SUCCESS;
1079 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1080 retval = MPI_ERR_COMM;
1081 } else if (count < 0) {
1082 retval = MPI_ERR_COUNT;
1083 } else if (buf==NULL && count > 0) {
1084 retval = MPI_ERR_COUNT;
1085 } else if (datatype == MPI_DATATYPE_NULL){
1086 retval = MPI_ERR_TYPE;
1087 } else if(tag<0 && tag != MPI_ANY_TAG){
1088 retval = MPI_ERR_TAG;
1091 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1092 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1093 TRACE_smpi_computing_out(rank);
1095 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__);
1098 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1099 retval = MPI_SUCCESS;
1102 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1103 if(status!=MPI_STATUS_IGNORE)src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1104 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1105 TRACE_smpi_recv(rank, src_traced, rank);
1106 TRACE_smpi_computing_in(rank);
1114 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1121 if (comm == MPI_COMM_NULL) {
1122 retval = MPI_ERR_COMM;
1123 } else if (dst == MPI_PROC_NULL) {
1124 retval = MPI_SUCCESS;
1125 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1126 retval = MPI_ERR_COMM;
1127 } else if (count < 0) {
1128 retval = MPI_ERR_COUNT;
1129 } else if (buf==NULL && count > 0) {
1130 retval = MPI_ERR_COUNT;
1131 } else if (datatype == MPI_DATATYPE_NULL){
1132 retval = MPI_ERR_TYPE;
1133 } else if(tag<0 && tag != MPI_ANY_TAG){
1134 retval = MPI_ERR_TAG;
1138 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1139 TRACE_smpi_computing_out(rank);
1140 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1141 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1142 TRACE_smpi_send(rank, rank, dst_traced);
1145 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1146 retval = MPI_SUCCESS;
1149 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1150 TRACE_smpi_computing_in(rank);
1160 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1165 if (comm == MPI_COMM_NULL) {
1166 retval = MPI_ERR_COMM;
1167 } else if (dst == MPI_PROC_NULL) {
1168 retval = MPI_SUCCESS;
1169 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1170 retval = MPI_ERR_COMM;
1171 } else if (count < 0) {
1172 retval = MPI_ERR_COUNT;
1173 } else if (buf==NULL && count > 0) {
1174 retval = MPI_ERR_COUNT;
1175 } else if (datatype == MPI_DATATYPE_NULL){
1176 retval = MPI_ERR_TYPE;
1177 } else if(tag<0 && tag != MPI_ANY_TAG){
1178 retval = MPI_ERR_TAG;
1182 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1183 TRACE_smpi_computing_out(rank);
1184 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1185 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__);
1186 TRACE_smpi_send(rank, rank, dst_traced);
1189 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1190 retval = MPI_SUCCESS;
1193 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1194 TRACE_smpi_computing_in(rank);
1202 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1203 int dst, int sendtag, void *recvbuf, int recvcount,
1204 MPI_Datatype recvtype, int src, int recvtag,
1205 MPI_Comm comm, MPI_Status * status)
1211 if (comm == MPI_COMM_NULL) {
1212 retval = MPI_ERR_COMM;
1213 } else if (sendtype == MPI_DATATYPE_NULL
1214 || recvtype == MPI_DATATYPE_NULL) {
1215 retval = MPI_ERR_TYPE;
1216 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1217 smpi_empty_status(status);
1218 status->MPI_SOURCE = MPI_PROC_NULL;
1219 retval = MPI_SUCCESS;
1220 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1221 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1222 retval = MPI_ERR_COMM;
1223 } else if (sendcount < 0 || recvcount<0) {
1224 retval = MPI_ERR_COUNT;
1225 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1226 retval = MPI_ERR_COUNT;
1227 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1228 retval = MPI_ERR_TAG;
1232 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1233 TRACE_smpi_computing_out(rank);
1234 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1235 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1236 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1237 TRACE_smpi_send(rank, rank, dst_traced);
1241 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1242 recvcount, recvtype, src, recvtag, comm, status);
1243 retval = MPI_SUCCESS;
1246 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1247 TRACE_smpi_recv(rank, src_traced, rank);
1248 TRACE_smpi_computing_in(rank);
1257 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1258 int dst, int sendtag, int src, int recvtag,
1259 MPI_Comm comm, MPI_Status * status)
1261 //TODO: suboptimal implementation
1264 if (datatype == MPI_DATATYPE_NULL) {
1265 retval = MPI_ERR_TYPE;
1266 } else if (count < 0) {
1267 retval = MPI_ERR_COUNT;
1269 int size = smpi_datatype_get_extent(datatype) * count;
1270 recvbuf = xbt_new(char, size);
1272 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1273 datatype, src, recvtag, comm, status);
1274 if(retval==MPI_SUCCESS){
1275 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1283 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1288 if (request == MPI_REQUEST_NULL || flag == NULL) {
1289 retval = MPI_ERR_ARG;
1290 } else if (*request == MPI_REQUEST_NULL) {
1292 retval = MPI_ERR_REQUEST;
1294 *flag = smpi_mpi_test(request, status);
1295 retval = MPI_SUCCESS;
1301 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1302 MPI_Status * status)
1307 if (index == NULL || flag == NULL) {
1308 retval = MPI_ERR_ARG;
1310 *flag = smpi_mpi_testany(count, requests, index, status);
1311 retval = MPI_SUCCESS;
1317 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1323 retval = MPI_ERR_ARG;
1325 *flag = smpi_mpi_testall(count, requests, statuses);
1326 retval = MPI_SUCCESS;
1332 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1336 if (status == NULL) {
1337 retval = MPI_ERR_ARG;
1338 } else if (comm == MPI_COMM_NULL) {
1339 retval = MPI_ERR_COMM;
1340 } else if (source == MPI_PROC_NULL) {
1341 smpi_empty_status(status);
1342 status->MPI_SOURCE = MPI_PROC_NULL;
1343 retval = MPI_SUCCESS;
1345 smpi_mpi_probe(source, tag, comm, status);
1346 retval = MPI_SUCCESS;
1353 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1358 retval = MPI_ERR_ARG;
1359 } else if (status == NULL) {
1360 retval = MPI_ERR_ARG;
1361 } else if (comm == MPI_COMM_NULL) {
1362 retval = MPI_ERR_COMM;
1363 } else if (source == MPI_PROC_NULL) {
1364 smpi_empty_status(status);
1365 status->MPI_SOURCE = MPI_PROC_NULL;
1366 retval = MPI_SUCCESS;
1368 smpi_mpi_iprobe(source, tag, comm, flag, status);
1369 retval = MPI_SUCCESS;
1375 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1381 if (request == NULL) {
1382 retval = MPI_ERR_ARG;
1383 } else if (*request == MPI_REQUEST_NULL) {
1384 retval = MPI_ERR_REQUEST;
1388 int rank = request && (*request)->comm != MPI_COMM_NULL
1389 ? smpi_process_index()
1391 TRACE_smpi_computing_out(rank);
1393 int src_traced = (*request)->src;
1394 int dst_traced = (*request)->dst;
1395 int is_wait_for_receive = (*request)->recv;
1396 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__);
1399 smpi_mpi_wait(request, status);
1400 retval = MPI_SUCCESS;
1403 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1404 if (is_wait_for_receive) {
1405 TRACE_smpi_recv(rank, src_traced, dst_traced);
1407 TRACE_smpi_computing_in(rank);
1416 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1422 //save requests information for tracing
1424 int *srcs = xbt_new(int, count);
1425 int *dsts = xbt_new(int, count);
1426 int *recvs = xbt_new(int, count);
1427 for (i = 0; i < count; i++) {
1428 MPI_Request req = requests[i]; //already received requests are no longer valid
1432 recvs[i] = req->recv;
1435 int rank_traced = smpi_process_index();
1436 TRACE_smpi_computing_out(rank_traced);
1438 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1441 if (index == NULL) {
1442 retval = MPI_ERR_ARG;
1444 *index = smpi_mpi_waitany(count, requests, status);
1445 retval = MPI_SUCCESS;
1448 if(*index!=MPI_UNDEFINED){
1449 int src_traced = srcs[*index];
1450 int dst_traced = dsts[*index];
1451 int is_wait_for_receive = recvs[*index];
1452 if (is_wait_for_receive) {
1453 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1455 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1460 TRACE_smpi_computing_in(rank_traced);
1466 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1471 //save information from requests
1473 int *srcs = xbt_new(int, count);
1474 int *dsts = xbt_new(int, count);
1475 int *recvs = xbt_new(int, count);
1476 int valid_count = 0;
1477 for (i = 0; i < count; i++) {
1478 MPI_Request req = requests[i];
1479 if(req!=MPI_REQUEST_NULL){
1480 srcs[valid_count] = req->src;
1481 dsts[valid_count] = req->dst;
1482 recvs[valid_count] = req->recv;
1486 int rank_traced = smpi_process_index();
1487 TRACE_smpi_computing_out(rank_traced);
1489 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__);
1491 int retval = smpi_mpi_waitall(count, requests, status);
1493 for (i = 0; i < valid_count; i++) {
1494 int src_traced = srcs[i];
1495 int dst_traced = dsts[i];
1496 int is_wait_for_receive = recvs[i];
1497 if (is_wait_for_receive) {
1498 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1501 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1505 TRACE_smpi_computing_in(rank_traced);
1511 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1512 int *indices, MPI_Status status[])
1517 if (outcount == NULL || indices == NULL) {
1518 retval = MPI_ERR_ARG;
1520 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1521 retval = MPI_SUCCESS;
1527 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1528 int* indices, MPI_Status status[])
1533 if (outcount == NULL || indices == NULL) {
1534 retval = MPI_ERR_ARG;
1536 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1537 retval = MPI_SUCCESS;
1544 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1550 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1551 TRACE_smpi_computing_out(rank);
1552 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1553 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1555 if (comm == MPI_COMM_NULL) {
1556 retval = MPI_ERR_COMM;
1558 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1559 retval = MPI_SUCCESS;
1562 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1563 TRACE_smpi_computing_in(rank);
1569 int PMPI_Barrier(MPI_Comm comm)
1575 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1576 TRACE_smpi_computing_out(rank);
1577 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1579 if (comm == MPI_COMM_NULL) {
1580 retval = MPI_ERR_COMM;
1582 smpi_mpi_barrier(comm);
1583 retval = MPI_SUCCESS;
1586 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1587 TRACE_smpi_computing_in(rank);
1593 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1594 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1595 int root, MPI_Comm comm)
1601 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1602 TRACE_smpi_computing_out(rank);
1603 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1604 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1606 if (comm == MPI_COMM_NULL) {
1607 retval = MPI_ERR_COMM;
1608 } else if (sendtype == MPI_DATATYPE_NULL
1609 || recvtype == MPI_DATATYPE_NULL) {
1610 retval = MPI_ERR_TYPE;
1612 mpi_coll_gather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1613 recvtype, root, comm);
1614 retval = MPI_SUCCESS;
1617 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1618 TRACE_smpi_computing_in(rank);
1624 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1625 void *recvbuf, int *recvcounts, int *displs,
1626 MPI_Datatype recvtype, int root, MPI_Comm comm)
1632 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1633 TRACE_smpi_computing_out(rank);
1634 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1635 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1637 if (comm == MPI_COMM_NULL) {
1638 retval = MPI_ERR_COMM;
1639 } else if (sendtype == MPI_DATATYPE_NULL
1640 || recvtype == MPI_DATATYPE_NULL) {
1641 retval = MPI_ERR_TYPE;
1642 } else if (recvcounts == NULL || displs == NULL) {
1643 retval = MPI_ERR_ARG;
1645 smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1646 displs, recvtype, root, comm);
1647 retval = MPI_SUCCESS;
1650 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1651 TRACE_smpi_computing_in(rank);
1657 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1658 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1665 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1666 TRACE_smpi_computing_out(rank);
1667 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1669 if (comm == MPI_COMM_NULL) {
1670 retval = MPI_ERR_COMM;
1671 } else if (sendtype == MPI_DATATYPE_NULL
1672 || recvtype == MPI_DATATYPE_NULL) {
1673 retval = MPI_ERR_TYPE;
1675 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1677 retval = MPI_SUCCESS;
1680 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1686 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1687 void *recvbuf, int *recvcounts, int *displs,
1688 MPI_Datatype recvtype, MPI_Comm comm)
1694 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1695 TRACE_smpi_computing_out(rank);
1696 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1698 if (comm == MPI_COMM_NULL) {
1699 retval = MPI_ERR_COMM;
1700 } else if (sendtype == MPI_DATATYPE_NULL
1701 || recvtype == MPI_DATATYPE_NULL) {
1702 retval = MPI_ERR_TYPE;
1703 } else if (recvcounts == NULL || displs == NULL) {
1704 retval = MPI_ERR_ARG;
1706 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1707 displs, recvtype, comm);
1708 retval = MPI_SUCCESS;
1711 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1712 TRACE_smpi_computing_in(rank);
1718 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1719 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1720 int root, MPI_Comm comm)
1726 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1727 TRACE_smpi_computing_out(rank);
1728 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1730 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1732 if (comm == MPI_COMM_NULL) {
1733 retval = MPI_ERR_COMM;
1734 } else if (sendtype == MPI_DATATYPE_NULL
1735 || recvtype == MPI_DATATYPE_NULL) {
1736 retval = MPI_ERR_TYPE;
1738 smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1739 recvtype, root, comm);
1740 retval = MPI_SUCCESS;
1743 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1744 TRACE_smpi_computing_in(rank);
1750 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1751 MPI_Datatype sendtype, void *recvbuf, int recvcount,
1752 MPI_Datatype recvtype, int root, MPI_Comm comm)
1758 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1759 TRACE_smpi_computing_out(rank);
1760 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1761 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1763 if (comm == MPI_COMM_NULL) {
1764 retval = MPI_ERR_COMM;
1765 } else if (sendtype == MPI_DATATYPE_NULL
1766 || recvtype == MPI_DATATYPE_NULL) {
1767 retval = MPI_ERR_TYPE;
1768 } else if (sendcounts == NULL || displs == NULL) {
1769 retval = MPI_ERR_ARG;
1771 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
1772 recvcount, recvtype, root, comm);
1773 retval = MPI_SUCCESS;
1776 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1777 TRACE_smpi_computing_in(rank);
1783 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
1784 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
1790 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1791 TRACE_smpi_computing_out(rank);
1792 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1793 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__);
1795 if (comm == MPI_COMM_NULL) {
1796 retval = MPI_ERR_COMM;
1797 } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
1798 retval = MPI_ERR_ARG;
1800 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
1801 retval = MPI_SUCCESS;
1804 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1805 TRACE_smpi_computing_in(rank);
1811 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
1812 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1818 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1819 TRACE_smpi_computing_out(rank);
1820 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1822 if (comm == MPI_COMM_NULL) {
1823 retval = MPI_ERR_COMM;
1824 } else if (datatype == MPI_DATATYPE_NULL) {
1825 retval = MPI_ERR_TYPE;
1826 } else if (op == MPI_OP_NULL) {
1827 retval = MPI_ERR_OP;
1829 mpi_coll_allreduce_fun(sendbuf, recvbuf, count, datatype, op, comm);
1830 retval = MPI_SUCCESS;
1833 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1834 TRACE_smpi_computing_in(rank);
1840 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
1841 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1847 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1848 TRACE_smpi_computing_out(rank);
1849 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1851 if (comm == MPI_COMM_NULL) {
1852 retval = MPI_ERR_COMM;
1853 } else if (datatype == MPI_DATATYPE_NULL) {
1854 retval = MPI_ERR_TYPE;
1855 } else if (op == MPI_OP_NULL) {
1856 retval = MPI_ERR_OP;
1858 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
1859 retval = MPI_SUCCESS;
1862 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1863 TRACE_smpi_computing_in(rank);
1869 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
1870 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1872 int retval, i, size, count;
1874 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1878 TRACE_smpi_computing_out(rank);
1879 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1881 if (comm == MPI_COMM_NULL) {
1882 retval = MPI_ERR_COMM;
1883 } else if (datatype == MPI_DATATYPE_NULL) {
1884 retval = MPI_ERR_TYPE;
1885 } else if (op == MPI_OP_NULL) {
1886 retval = MPI_ERR_OP;
1887 } else if (recvcounts == NULL) {
1888 retval = MPI_ERR_ARG;
1890 /* arbitrarily choose root as rank 0 */
1891 /* TODO: faster direct implementation ? */
1892 size = smpi_comm_size(comm);
1894 displs = xbt_new(int, size);
1895 for (i = 0; i < size; i++) {
1896 count += recvcounts[i];
1899 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, 0, comm);
1900 smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf,
1901 recvcounts[rank], datatype, 0, comm);
1903 retval = MPI_SUCCESS;
1906 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1907 TRACE_smpi_computing_in(rank);
1913 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1914 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1921 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1922 TRACE_smpi_computing_out(rank);
1923 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1925 if (comm == MPI_COMM_NULL) {
1926 retval = MPI_ERR_COMM;
1927 } else if (sendtype == MPI_DATATYPE_NULL
1928 || recvtype == MPI_DATATYPE_NULL) {
1929 retval = MPI_ERR_TYPE;
1931 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1934 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1935 TRACE_smpi_computing_in(rank);
1941 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
1942 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
1943 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
1949 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1950 TRACE_smpi_computing_out(rank);
1951 TRACE_smpi_collective_in(rank, -1, __FUNCTION__);
1953 if (comm == MPI_COMM_NULL) {
1954 retval = MPI_ERR_COMM;
1955 } else if (sendtype == MPI_DATATYPE_NULL
1956 || recvtype == MPI_DATATYPE_NULL) {
1957 retval = MPI_ERR_TYPE;
1958 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
1959 || recvdisps == NULL) {
1960 retval = MPI_ERR_ARG;
1963 mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
1964 recvbuf, recvcounts, recvdisps, recvtype,
1968 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1969 TRACE_smpi_computing_in(rank);
1976 int PMPI_Get_processor_name(char *name, int *resultlen)
1978 int retval = MPI_SUCCESS;
1981 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
1982 strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
1983 strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
1984 MPI_MAX_PROCESSOR_NAME - 1 );
1987 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
1993 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
1995 int retval = MPI_SUCCESS;
1999 if (status == NULL || count == NULL) {
2000 retval = MPI_ERR_ARG;
2001 } else if (datatype == MPI_DATATYPE_NULL) {
2002 retval = MPI_ERR_TYPE;
2004 size = smpi_datatype_size(datatype);
2007 } else if (status->count % size != 0) {
2008 retval = MPI_UNDEFINED;
2010 *count = smpi_mpi_get_count(status, datatype);
2017 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2021 if (old_type == MPI_DATATYPE_NULL) {
2022 retval = MPI_ERR_TYPE;
2023 } else if (count<0){
2024 retval = MPI_ERR_COUNT;
2026 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2032 int PMPI_Type_commit(MPI_Datatype* datatype) {
2036 if (datatype == MPI_DATATYPE_NULL) {
2037 retval = MPI_ERR_TYPE;
2039 smpi_datatype_commit(datatype);
2040 retval = MPI_SUCCESS;
2047 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2051 if (old_type == MPI_DATATYPE_NULL) {
2052 retval = MPI_ERR_TYPE;
2053 } else if (count<0 || blocklen<0){
2054 retval = MPI_ERR_COUNT;
2056 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2062 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2066 if (old_type == MPI_DATATYPE_NULL) {
2067 retval = MPI_ERR_TYPE;
2068 } else if (count<0 || blocklen<0){
2069 retval = MPI_ERR_COUNT;
2071 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2078 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2082 if (old_type == MPI_DATATYPE_NULL) {
2083 retval = MPI_ERR_TYPE;
2084 } else if (count<0){
2085 retval = MPI_ERR_COUNT;
2087 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2093 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2097 if (old_type == MPI_DATATYPE_NULL) {
2098 retval = MPI_ERR_TYPE;
2099 } else if (count<0){
2100 retval = MPI_ERR_COUNT;
2102 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2109 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2114 retval = MPI_ERR_COUNT;
2116 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2121 int PMPI_Error_class(int errorcode, int* errorclass) {
2122 // assume smpi uses only standard mpi error codes
2123 *errorclass=errorcode;
2128 int PMPI_Initialized(int* flag) {
2129 *flag=(smpi_process_data()!=NULL);
2133 /* The following calls are not yet implemented and will fail at runtime. */
2134 /* Once implemented, please move them above this notice. */
2136 static int not_yet_implemented(void) {
2137 XBT_WARN("Not yet implemented");
2141 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2142 return not_yet_implemented();
2145 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2146 return not_yet_implemented();
2149 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periods, int reorder, MPI_Comm* comm_cart) {
2150 return not_yet_implemented();
2153 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2154 return not_yet_implemented();
2157 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2158 return not_yet_implemented();
2161 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2162 return not_yet_implemented();
2165 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2166 return not_yet_implemented();
2169 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2170 return not_yet_implemented();
2173 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2174 return not_yet_implemented();
2177 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2178 return not_yet_implemented();
2181 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2182 return not_yet_implemented();
2185 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2186 return not_yet_implemented();
2189 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2190 return not_yet_implemented();
2193 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2194 return not_yet_implemented();
2197 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2198 return not_yet_implemented();
2201 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2202 return not_yet_implemented();
2205 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2206 return not_yet_implemented();
2209 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2210 return not_yet_implemented();
2213 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2214 return not_yet_implemented();
2217 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2218 return not_yet_implemented();
2221 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2222 return not_yet_implemented();
2226 int PMPI_Cancel(MPI_Request* request) {
2227 return not_yet_implemented();
2230 int PMPI_Buffer_attach(void* buffer, int size) {
2231 return not_yet_implemented();
2234 int PMPI_Buffer_detach(void* buffer, int* size) {
2235 return not_yet_implemented();
2238 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2239 return not_yet_implemented();
2242 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2244 return not_yet_implemented();
2247 int PMPI_Pcontrol(const int level )
2249 return not_yet_implemented();
2252 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2253 return not_yet_implemented();
2258 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2259 return not_yet_implemented();
2262 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2263 return not_yet_implemented();
2266 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2267 return not_yet_implemented();
2270 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2271 return not_yet_implemented();
2274 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2275 return not_yet_implemented();
2278 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2279 return not_yet_implemented();
2282 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2283 return not_yet_implemented();
2286 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2287 return not_yet_implemented();
2290 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2291 return not_yet_implemented();
2294 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2295 return not_yet_implemented();
2298 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2299 return not_yet_implemented();
2302 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2303 return not_yet_implemented();
2306 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2307 return not_yet_implemented();
2310 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2311 return not_yet_implemented();
2314 int PMPI_Keyval_free(int* keyval) {
2315 return not_yet_implemented();
2318 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2319 return not_yet_implemented();
2322 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2323 return not_yet_implemented();
2326 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2327 return not_yet_implemented();
2330 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2331 return not_yet_implemented();
2334 int PMPI_Win_fence( int assert, MPI_Win win){
2335 return not_yet_implemented();
2338 int PMPI_Win_free( MPI_Win* win){
2339 return not_yet_implemented();
2342 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2343 return not_yet_implemented();
2346 int PMPI_Info_create( MPI_Info *info){
2347 return not_yet_implemented();
2350 int PMPI_Info_set( MPI_Info *info, char *key, char *value){
2351 return not_yet_implemented();
2354 int PMPI_Info_free( MPI_Info *info){
2355 return not_yet_implemented();
2358 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2359 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2360 return not_yet_implemented();