1 /* Copyright (c) 2007-2013. 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);
30 smpi_process_mark_as_initialized();
32 int rank = smpi_process_index();
33 TRACE_smpi_init(rank);
34 TRACE_smpi_computing_init(rank);
35 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
36 extra->type = TRACING_INIT;
37 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
38 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
44 int PMPI_Finalize(void)
48 int rank = smpi_process_index();
49 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
50 extra->type = TRACING_FINALIZE;
51 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
53 smpi_process_finalize();
55 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
56 TRACE_smpi_finalize(smpi_process_index());
58 smpi_process_destroy();
62 int PMPI_Finalized(int* flag)
64 *flag=smpi_process_finalized();
68 int PMPI_Get_version (int *version,int *subversion){
69 *version = MPI_VERSION;
70 *subversion= MPI_SUBVERSION;
74 int PMPI_Get_library_version (char *version,int *len){
75 int retval = MPI_SUCCESS;
77 snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2013",SIMGRID_VERSION_MAJOR,
78 SIMGRID_VERSION_MINOR);
79 *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
84 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
86 if (provided != NULL) {
87 *provided = MPI_THREAD_MULTIPLE;
89 return MPI_Init(argc, argv);
92 int PMPI_Query_thread(int *provided)
97 if (provided == NULL) {
100 *provided = MPI_THREAD_MULTIPLE;
101 retval = MPI_SUCCESS;
107 int PMPI_Is_thread_main(int *flag)
113 retval = MPI_ERR_ARG;
115 *flag = smpi_process_index() == 0;
116 retval = MPI_SUCCESS;
122 int PMPI_Abort(MPI_Comm comm, int errorcode)
125 smpi_process_destroy();
126 // FIXME: should kill all processes in comm instead
127 simcall_process_kill(SIMIX_process_self());
131 double PMPI_Wtime(void)
134 if (smpi_process_initialized() && !smpi_process_finalized() && !smpi_process_get_sampling()) {
136 time = SIMIX_get_clock();
139 time = SIMIX_get_clock();
144 extern double sg_maxmin_precision;
145 double PMPI_Wtick(void)
147 return sg_maxmin_precision;
150 int PMPI_Address(void *location, MPI_Aint * address)
156 retval = MPI_ERR_ARG;
158 *address = (MPI_Aint) location;
159 retval = MPI_SUCCESS;
165 int PMPI_Get_address(void *location, MPI_Aint * address)
167 return PMPI_Address(location, address);
170 int PMPI_Type_free(MPI_Datatype * datatype)
176 retval = MPI_ERR_ARG;
178 smpi_datatype_free(datatype);
179 retval = MPI_SUCCESS;
185 int PMPI_Type_size(MPI_Datatype datatype, int *size)
190 if (datatype == MPI_DATATYPE_NULL) {
191 retval = MPI_ERR_TYPE;
192 } else if (size == NULL) {
193 retval = MPI_ERR_ARG;
195 *size = (int) smpi_datatype_size(datatype);
196 retval = MPI_SUCCESS;
202 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
207 if (datatype == MPI_DATATYPE_NULL) {
208 retval = MPI_ERR_TYPE;
209 } else if (lb == NULL || extent == NULL) {
210 retval = MPI_ERR_ARG;
212 retval = smpi_datatype_extent(datatype, lb, extent);
218 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
220 return PMPI_Type_get_extent(datatype, lb, extent);
223 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
228 if (datatype == MPI_DATATYPE_NULL) {
229 retval = MPI_ERR_TYPE;
230 } else if (extent == NULL) {
231 retval = MPI_ERR_ARG;
233 *extent = smpi_datatype_get_extent(datatype);
234 retval = MPI_SUCCESS;
240 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
245 if (datatype == MPI_DATATYPE_NULL) {
246 retval = MPI_ERR_TYPE;
247 } else if (disp == NULL) {
248 retval = MPI_ERR_ARG;
250 *disp = smpi_datatype_lb(datatype);
251 retval = MPI_SUCCESS;
257 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
262 if (datatype == MPI_DATATYPE_NULL) {
263 retval = MPI_ERR_TYPE;
264 } else if (disp == NULL) {
265 retval = MPI_ERR_ARG;
267 *disp = smpi_datatype_ub(datatype);
268 retval = MPI_SUCCESS;
274 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
279 if (function == NULL || op == NULL) {
280 retval = MPI_ERR_ARG;
282 *op = smpi_op_new(function, commute);
283 retval = MPI_SUCCESS;
289 int PMPI_Op_free(MPI_Op * op)
295 retval = MPI_ERR_ARG;
296 } else if (*op == MPI_OP_NULL) {
299 smpi_op_destroy(*op);
301 retval = MPI_SUCCESS;
307 int PMPI_Group_free(MPI_Group * group)
313 retval = MPI_ERR_ARG;
315 smpi_group_destroy(*group);
316 *group = MPI_GROUP_NULL;
317 retval = MPI_SUCCESS;
323 int PMPI_Group_size(MPI_Group group, int *size)
328 if (group == MPI_GROUP_NULL) {
329 retval = MPI_ERR_GROUP;
330 } else if (size == NULL) {
331 retval = MPI_ERR_ARG;
333 *size = smpi_group_size(group);
334 retval = MPI_SUCCESS;
340 int PMPI_Group_rank(MPI_Group group, int *rank)
345 if (group == MPI_GROUP_NULL) {
346 retval = MPI_ERR_GROUP;
347 } else if (rank == NULL) {
348 retval = MPI_ERR_ARG;
350 *rank = smpi_group_rank(group, smpi_process_index());
351 retval = MPI_SUCCESS;
357 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
358 MPI_Group group2, int *ranks2)
360 int retval, i, index;
362 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
363 retval = MPI_ERR_GROUP;
365 for (i = 0; i < n; i++) {
366 if(ranks1[i]==MPI_PROC_NULL){
367 ranks2[i]=MPI_PROC_NULL;
369 index = smpi_group_index(group1, ranks1[i]);
370 ranks2[i] = smpi_group_rank(group2, index);
373 retval = MPI_SUCCESS;
379 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
384 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
385 retval = MPI_ERR_GROUP;
386 } else if (result == NULL) {
387 retval = MPI_ERR_ARG;
389 *result = smpi_group_compare(group1, group2);
390 retval = MPI_SUCCESS;
396 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
397 MPI_Group * newgroup)
399 int retval, i, proc1, proc2, size, size2;
402 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
403 retval = MPI_ERR_GROUP;
404 } else if (newgroup == NULL) {
405 retval = MPI_ERR_ARG;
407 size = smpi_group_size(group1);
408 size2 = smpi_group_size(group2);
409 for (i = 0; i < size2; i++) {
410 proc2 = smpi_group_index(group2, i);
411 proc1 = smpi_group_rank(group1, proc2);
412 if (proc1 == MPI_UNDEFINED) {
417 *newgroup = MPI_GROUP_EMPTY;
419 *newgroup = smpi_group_new(size);
420 size2 = smpi_group_size(group1);
421 for (i = 0; i < size2; i++) {
422 proc1 = smpi_group_index(group1, i);
423 smpi_group_set_mapping(*newgroup, proc1, i);
425 for (i = size2; i < size; i++) {
426 proc2 = smpi_group_index(group2, i - size2);
427 smpi_group_set_mapping(*newgroup, proc2, i);
430 retval = MPI_SUCCESS;
436 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
437 MPI_Group * newgroup)
439 int retval, i, proc1, proc2, size;
442 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
443 retval = MPI_ERR_GROUP;
444 } else if (newgroup == NULL) {
445 retval = MPI_ERR_ARG;
447 size = smpi_group_size(group2);
448 for (i = 0; i < size; i++) {
449 proc2 = smpi_group_index(group2, i);
450 proc1 = smpi_group_rank(group1, proc2);
451 if (proc1 == MPI_UNDEFINED) {
456 *newgroup = MPI_GROUP_EMPTY;
458 *newgroup = smpi_group_new(size);
460 for (i = 0; i < smpi_group_size(group2); i++) {
461 proc2 = smpi_group_index(group2, i);
462 proc1 = smpi_group_rank(group1, proc2);
463 if (proc1 != MPI_UNDEFINED) {
464 smpi_group_set_mapping(*newgroup, proc2, j);
469 retval = MPI_SUCCESS;
475 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
477 int retval, i, proc1, proc2, size, size2;
480 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
481 retval = MPI_ERR_GROUP;
482 } else if (newgroup == NULL) {
483 retval = MPI_ERR_ARG;
485 size = size2 = smpi_group_size(group1);
486 for (i = 0; i < size2; i++) {
487 proc1 = smpi_group_index(group1, i);
488 proc2 = smpi_group_rank(group2, proc1);
489 if (proc2 != MPI_UNDEFINED) {
494 *newgroup = MPI_GROUP_EMPTY;
496 *newgroup = smpi_group_new(size);
497 for (i = 0; i < size2; i++) {
498 proc1 = smpi_group_index(group1, i);
499 proc2 = smpi_group_rank(group2, proc1);
500 if (proc2 == MPI_UNDEFINED) {
501 smpi_group_set_mapping(*newgroup, proc1, i);
505 retval = MPI_SUCCESS;
511 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
513 int retval, i, index;
516 if (group == MPI_GROUP_NULL) {
517 retval = MPI_ERR_GROUP;
518 } else if (newgroup == NULL) {
519 retval = MPI_ERR_ARG;
522 *newgroup = MPI_GROUP_EMPTY;
523 } else if (n == smpi_group_size(group)) {
525 if(group!= smpi_comm_group(MPI_COMM_WORLD)
526 && group != MPI_GROUP_NULL
527 && group != smpi_comm_group(MPI_COMM_SELF)
528 && group != MPI_GROUP_EMPTY)
529 smpi_group_use(group);
531 *newgroup = smpi_group_new(n);
532 for (i = 0; i < n; i++) {
533 index = smpi_group_index(group, ranks[i]);
534 smpi_group_set_mapping(*newgroup, index, i);
537 retval = MPI_SUCCESS;
543 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
545 int retval, i, j, newsize, oldsize, index;
548 if (group == MPI_GROUP_NULL) {
549 retval = MPI_ERR_GROUP;
550 } else if (newgroup == NULL) {
551 retval = MPI_ERR_ARG;
555 if(group!= smpi_comm_group(MPI_COMM_WORLD)
556 && group != MPI_GROUP_NULL
557 && group != smpi_comm_group(MPI_COMM_SELF)
558 && group != MPI_GROUP_EMPTY)
559 smpi_group_use(group);
560 } else if (n == smpi_group_size(group)) {
561 *newgroup = MPI_GROUP_EMPTY;
563 oldsize=smpi_group_size(group);
564 newsize = oldsize - n;
565 *newgroup = smpi_group_new(newsize);
567 int* to_exclude=xbt_new0(int, smpi_group_size(group));
568 for(i=0; i<oldsize; i++)
571 to_exclude[ranks[i]]=1;
574 for(i=0; i<oldsize; i++){
575 if(to_exclude[i]==0){
576 index = smpi_group_index(group, i);
577 smpi_group_set_mapping(*newgroup, index, j);
582 xbt_free(to_exclude);
584 retval = MPI_SUCCESS;
590 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
591 MPI_Group * newgroup)
593 int retval, i, j, rank, size, index;
596 if (group == MPI_GROUP_NULL) {
597 retval = MPI_ERR_GROUP;
598 } else if (newgroup == NULL) {
599 retval = MPI_ERR_ARG;
602 *newgroup = MPI_GROUP_EMPTY;
605 for (i = 0; i < n; i++) {
606 for (rank = ranges[i][0]; /* First */
607 rank >= 0; /* Last */
611 rank += ranges[i][2]; /* Stride */
612 if (ranges[i][0]<ranges[i][1]){
613 if(rank > ranges[i][1])
616 if(rank < ranges[i][1])
622 *newgroup = smpi_group_new(size);
624 for (i = 0; i < n; i++) {
625 for (rank = ranges[i][0]; /* First */
626 rank >= 0; /* Last */
628 index = smpi_group_index(group, rank);
629 smpi_group_set_mapping(*newgroup, index, j);
631 rank += ranges[i][2]; /* Stride */
632 if (ranges[i][0]<ranges[i][1]){
633 if(rank > ranges[i][1])
636 if(rank < ranges[i][1])
642 retval = MPI_SUCCESS;
648 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
649 MPI_Group * newgroup)
651 int retval, i, rank, newrank,oldrank, size, index, add;
654 if (group == MPI_GROUP_NULL) {
655 retval = MPI_ERR_GROUP;
656 } else if (newgroup == NULL) {
657 retval = MPI_ERR_ARG;
661 if(group!= smpi_comm_group(MPI_COMM_WORLD)
662 && group != MPI_GROUP_NULL
663 && group != smpi_comm_group(MPI_COMM_SELF)
664 && group != MPI_GROUP_EMPTY)
665 smpi_group_use(group);
667 size = smpi_group_size(group);
668 for (i = 0; i < n; i++) {
669 for (rank = ranges[i][0]; /* First */
670 rank >= 0; /* Last */
674 rank += ranges[i][2]; /* Stride */
675 if (ranges[i][0]<ranges[i][1]){
676 if(rank > ranges[i][1])
679 if(rank < ranges[i][1])
685 *newgroup = MPI_GROUP_EMPTY;
687 *newgroup = smpi_group_new(size);
690 while (newrank < size) {
692 for (i = 0; i < n; i++) {
693 for (rank = ranges[i][0];rank >= 0;){
699 rank += ranges[i][2]; /* Stride */
701 if (ranges[i][0]<ranges[i][1]){
702 if(rank > ranges[i][1])
705 if(rank < ranges[i][1])
711 index = smpi_group_index(group, oldrank);
712 smpi_group_set_mapping(*newgroup, index, newrank);
720 retval = MPI_SUCCESS;
726 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
731 if (comm == MPI_COMM_NULL) {
732 retval = MPI_ERR_COMM;
733 } else if (rank == NULL) {
734 retval = MPI_ERR_ARG;
736 *rank = smpi_comm_rank(comm);
737 retval = MPI_SUCCESS;
743 int PMPI_Comm_size(MPI_Comm comm, int *size)
748 if (comm == MPI_COMM_NULL) {
749 retval = MPI_ERR_COMM;
750 } else if (size == NULL) {
751 retval = MPI_ERR_ARG;
753 *size = smpi_comm_size(comm);
754 retval = MPI_SUCCESS;
760 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
765 if (comm == MPI_COMM_NULL) {
766 retval = MPI_ERR_COMM;
767 } else if (name == NULL || len == NULL) {
768 retval = MPI_ERR_ARG;
770 smpi_comm_get_name(comm, name, len);
771 retval = MPI_SUCCESS;
777 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
782 if (comm == MPI_COMM_NULL) {
783 retval = MPI_ERR_COMM;
784 } else if (group == NULL) {
785 retval = MPI_ERR_ARG;
787 *group = smpi_comm_group(comm);
788 if(*group!= smpi_comm_group(MPI_COMM_WORLD)
789 && *group != MPI_GROUP_NULL
790 && *group != smpi_comm_group(MPI_COMM_SELF)
791 && *group != MPI_GROUP_EMPTY)
792 smpi_group_use(*group);
793 retval = MPI_SUCCESS;
799 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
804 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
805 retval = MPI_ERR_COMM;
806 } else if (result == NULL) {
807 retval = MPI_ERR_ARG;
809 if (comm1 == comm2) { /* Same communicators means same groups */
813 smpi_group_compare(smpi_comm_group(comm1),
814 smpi_comm_group(comm2));
815 if (*result == MPI_IDENT) {
816 *result = MPI_CONGRUENT;
819 retval = MPI_SUCCESS;
825 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
830 if (comm == MPI_COMM_NULL) {
831 retval = MPI_ERR_COMM;
832 } else if (newcomm == NULL) {
833 retval = MPI_ERR_ARG;
835 *newcomm = smpi_comm_new(smpi_comm_group(comm));
836 retval = MPI_SUCCESS;
842 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
847 if (comm == MPI_COMM_NULL) {
848 retval = MPI_ERR_COMM;
849 } else if (group == MPI_GROUP_NULL) {
850 retval = MPI_ERR_GROUP;
851 } else if (newcomm == NULL) {
852 retval = MPI_ERR_ARG;
853 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
854 *newcomm= MPI_COMM_NULL;
855 retval = MPI_SUCCESS;
858 *newcomm = smpi_comm_new(group);
859 retval = MPI_SUCCESS;
865 int PMPI_Comm_free(MPI_Comm * comm)
871 retval = MPI_ERR_ARG;
872 } else if (*comm == MPI_COMM_NULL) {
873 retval = MPI_ERR_COMM;
875 smpi_comm_destroy(*comm);
876 *comm = MPI_COMM_NULL;
877 retval = MPI_SUCCESS;
883 int PMPI_Comm_disconnect(MPI_Comm * comm)
885 /* TODO: wait until all communication in comm are done */
890 retval = MPI_ERR_ARG;
891 } else if (*comm == MPI_COMM_NULL) {
892 retval = MPI_ERR_COMM;
894 smpi_comm_destroy(*comm);
895 *comm = MPI_COMM_NULL;
896 retval = MPI_SUCCESS;
902 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
907 if (comm_out == NULL) {
908 retval = MPI_ERR_ARG;
909 } else if (comm == MPI_COMM_NULL) {
910 retval = MPI_ERR_COMM;
912 *comm_out = smpi_comm_split(comm, color, key);
913 retval = MPI_SUCCESS;
919 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
920 int tag, MPI_Comm comm, MPI_Request * request)
925 if (request == NULL) {
926 retval = MPI_ERR_ARG;
927 } else if (comm == MPI_COMM_NULL) {
928 retval = MPI_ERR_COMM;
929 } else if (dst == MPI_PROC_NULL) {
930 retval = MPI_SUCCESS;
932 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
933 retval = MPI_SUCCESS;
936 if (retval != MPI_SUCCESS && request)
937 *request = MPI_REQUEST_NULL;
941 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
942 int tag, MPI_Comm comm, MPI_Request * request)
947 if (request == NULL) {
948 retval = MPI_ERR_ARG;
949 } else if (comm == MPI_COMM_NULL) {
950 retval = MPI_ERR_COMM;
951 } else if (src == MPI_PROC_NULL) {
952 retval = MPI_SUCCESS;
954 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
955 retval = MPI_SUCCESS;
958 if (retval != MPI_SUCCESS && request)
959 *request = MPI_REQUEST_NULL;
963 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
964 int dst, int tag, MPI_Comm comm, MPI_Request* request)
969 if (request == NULL) {
970 retval = MPI_ERR_ARG;
971 } else if (comm == MPI_COMM_NULL) {
972 retval = MPI_ERR_COMM;
973 } else if (dst == MPI_PROC_NULL) {
974 retval = MPI_SUCCESS;
976 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
977 retval = MPI_SUCCESS;
980 if (retval != MPI_SUCCESS && request)
981 *request = MPI_REQUEST_NULL;
985 int PMPI_Start(MPI_Request * request)
990 if (request == NULL || *request == MPI_REQUEST_NULL) {
991 retval = MPI_ERR_ARG;
993 smpi_mpi_start(*request);
994 retval = MPI_SUCCESS;
1000 int PMPI_Startall(int count, MPI_Request * requests)
1005 if (requests == NULL) {
1006 retval = MPI_ERR_ARG;
1008 smpi_mpi_startall(count, requests);
1009 retval = MPI_SUCCESS;
1015 int PMPI_Request_free(MPI_Request * request)
1020 if (*request == MPI_REQUEST_NULL) {
1021 retval = MPI_ERR_ARG;
1023 if((*request)->flags & PERSISTENT)(*request)->refcount--;
1024 smpi_mpi_request_free(request);
1025 retval = MPI_SUCCESS;
1031 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
1032 int tag, MPI_Comm comm, MPI_Request * request)
1038 if (request == NULL) {
1039 retval = MPI_ERR_ARG;
1040 } else if (comm == MPI_COMM_NULL) {
1041 retval = MPI_ERR_COMM;
1042 } else if (src == MPI_PROC_NULL) {
1043 *request = MPI_REQUEST_NULL;
1044 retval = MPI_SUCCESS;
1045 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1046 retval = MPI_ERR_COMM;
1047 } else if (count < 0) {
1048 retval = MPI_ERR_COUNT;
1049 } else if (buf==NULL && count > 0) {
1050 retval = MPI_ERR_COUNT;
1051 } else if (datatype == MPI_DATATYPE_NULL){
1052 retval = MPI_ERR_TYPE;
1053 } else if(tag<0 && tag != MPI_ANY_TAG){
1054 retval = MPI_ERR_TAG;
1058 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1059 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1061 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1062 extra->type = TRACING_IRECV;
1063 extra->send_size = count;
1064 extra->src = src_traced;
1066 extra->datatype1 = encode_datatype(datatype);
1067 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1070 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1071 retval = MPI_SUCCESS;
1074 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1075 (*request)->recv = 1;
1080 if (retval != MPI_SUCCESS && request)
1081 *request = MPI_REQUEST_NULL;
1086 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1087 int tag, MPI_Comm comm, MPI_Request * request)
1092 if (request == NULL) {
1093 retval = MPI_ERR_ARG;
1094 } else if (comm == MPI_COMM_NULL) {
1095 retval = MPI_ERR_COMM;
1096 } else if (dst == MPI_PROC_NULL) {
1097 *request = MPI_REQUEST_NULL;
1098 retval = MPI_SUCCESS;
1099 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1100 retval = MPI_ERR_RANK;
1101 } else if (count < 0) {
1102 retval = MPI_ERR_COUNT;
1103 } else if (buf==NULL && count > 0) {
1104 retval = MPI_ERR_COUNT;
1105 } else if (datatype == MPI_DATATYPE_NULL){
1106 retval = MPI_ERR_TYPE;
1107 } else if(tag<0 && tag != MPI_ANY_TAG){
1108 retval = MPI_ERR_TAG;
1112 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1113 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1115 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1116 extra->type = TRACING_ISEND;
1117 extra->send_size = count;
1119 extra->dst = dst_traced;
1120 extra->datatype1 = encode_datatype(datatype);
1121 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1122 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1125 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1126 retval = MPI_SUCCESS;
1129 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1130 (*request)->send = 1;
1135 if (retval != MPI_SUCCESS && request)
1136 *request = MPI_REQUEST_NULL;
1140 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1141 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1146 if (request == NULL) {
1147 retval = MPI_ERR_ARG;
1148 } else if (comm == MPI_COMM_NULL) {
1149 retval = MPI_ERR_COMM;
1150 } else if (dst == MPI_PROC_NULL) {
1151 *request = MPI_REQUEST_NULL;
1152 retval = MPI_SUCCESS;
1153 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1154 retval = MPI_ERR_RANK;
1155 } else if (count < 0) {
1156 retval = MPI_ERR_COUNT;
1157 } else if (buf==NULL && count > 0) {
1158 retval = MPI_ERR_COUNT;
1159 } else if (datatype == MPI_DATATYPE_NULL){
1160 retval = MPI_ERR_TYPE;
1161 } else if(tag<0 && tag != MPI_ANY_TAG){
1162 retval = MPI_ERR_TAG;
1166 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1167 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1168 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1169 extra->type = TRACING_ISSEND;
1170 extra->send_size = count;
1172 extra->dst = dst_traced;
1173 extra->datatype1 = encode_datatype(datatype);
1174 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1175 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1178 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1179 retval = MPI_SUCCESS;
1182 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1183 (*request)->send = 1;
1188 if (retval != MPI_SUCCESS && request)
1189 *request = MPI_REQUEST_NULL;
1193 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1194 MPI_Comm comm, MPI_Status * status)
1199 if (comm == MPI_COMM_NULL) {
1200 retval = MPI_ERR_COMM;
1201 } else if (src == MPI_PROC_NULL) {
1202 smpi_empty_status(status);
1203 status->MPI_SOURCE = MPI_PROC_NULL;
1204 retval = MPI_SUCCESS;
1205 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1206 retval = MPI_ERR_RANK;
1207 } else if (count < 0) {
1208 retval = MPI_ERR_COUNT;
1209 } else if (buf==NULL && count > 0) {
1210 retval = MPI_ERR_COUNT;
1211 } else if (datatype == MPI_DATATYPE_NULL){
1212 retval = MPI_ERR_TYPE;
1213 } else if(tag<0 && tag != MPI_ANY_TAG){
1214 retval = MPI_ERR_TAG;
1217 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1218 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1219 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1220 extra->type = TRACING_RECV;
1221 extra->send_size = count;
1222 extra->src = src_traced;
1224 extra->datatype1 = encode_datatype(datatype);
1225 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1228 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1229 retval = MPI_SUCCESS;
1232 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1233 if(status!=MPI_STATUS_IGNORE){
1234 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1235 TRACE_smpi_recv(rank, src_traced, rank);
1237 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1245 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1252 if (comm == MPI_COMM_NULL) {
1253 retval = MPI_ERR_COMM;
1254 } else if (dst == MPI_PROC_NULL) {
1255 retval = MPI_SUCCESS;
1256 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1257 retval = MPI_ERR_RANK;
1258 } else if (count < 0) {
1259 retval = MPI_ERR_COUNT;
1260 } else if (buf==NULL && count > 0) {
1261 retval = MPI_ERR_COUNT;
1262 } else if (datatype == MPI_DATATYPE_NULL){
1263 retval = MPI_ERR_TYPE;
1264 } else if(tag<0 && tag != MPI_ANY_TAG){
1265 retval = MPI_ERR_TAG;
1269 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1270 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1271 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1272 extra->type = TRACING_SEND;
1273 extra->send_size = count;
1275 extra->dst = dst_traced;
1276 extra->datatype1 = encode_datatype(datatype);
1277 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1278 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1281 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1282 retval = MPI_SUCCESS;
1285 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1295 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1300 if (comm == MPI_COMM_NULL) {
1301 retval = MPI_ERR_COMM;
1302 } else if (dst == MPI_PROC_NULL) {
1303 retval = MPI_SUCCESS;
1304 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1305 retval = MPI_ERR_RANK;
1306 } else if (count < 0) {
1307 retval = MPI_ERR_COUNT;
1308 } else if (buf==NULL && count > 0) {
1309 retval = MPI_ERR_COUNT;
1310 } else if (datatype == MPI_DATATYPE_NULL){
1311 retval = MPI_ERR_TYPE;
1312 } else if(tag<0 && tag != MPI_ANY_TAG){
1313 retval = MPI_ERR_TAG;
1317 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1318 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1319 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1320 extra->type = TRACING_SSEND;
1321 extra->send_size = count;
1323 extra->dst = dst_traced;
1324 extra->datatype1 = encode_datatype(datatype);
1325 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra); TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1328 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1329 retval = MPI_SUCCESS;
1332 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1340 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1341 int dst, int sendtag, void *recvbuf, int recvcount,
1342 MPI_Datatype recvtype, int src, int recvtag,
1343 MPI_Comm comm, MPI_Status * status)
1349 if (comm == MPI_COMM_NULL) {
1350 retval = MPI_ERR_COMM;
1351 } else if (sendtype == MPI_DATATYPE_NULL
1352 || recvtype == MPI_DATATYPE_NULL) {
1353 retval = MPI_ERR_TYPE;
1354 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1355 smpi_empty_status(status);
1356 status->MPI_SOURCE = MPI_PROC_NULL;
1357 retval = MPI_SUCCESS;
1358 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1359 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1360 retval = MPI_ERR_RANK;
1361 } else if (sendcount < 0 || recvcount<0) {
1362 retval = MPI_ERR_COUNT;
1363 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1364 retval = MPI_ERR_COUNT;
1365 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1366 retval = MPI_ERR_TAG;
1370 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1371 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1372 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1373 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1374 extra->type = TRACING_SENDRECV;
1375 extra->send_size = sendcount;
1376 extra->recv_size = recvcount;
1377 extra->src = src_traced;
1378 extra->dst = dst_traced;
1379 extra->datatype1 = encode_datatype(sendtype);
1380 extra->datatype2 = encode_datatype(recvtype);
1382 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1383 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1387 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1388 recvcount, recvtype, src, recvtag, comm, status);
1389 retval = MPI_SUCCESS;
1392 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1393 TRACE_smpi_recv(rank, src_traced, rank);
1402 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1403 int dst, int sendtag, int src, int recvtag,
1404 MPI_Comm comm, MPI_Status * status)
1406 //TODO: suboptimal implementation
1409 if (datatype == MPI_DATATYPE_NULL) {
1410 retval = MPI_ERR_TYPE;
1411 } else if (count < 0) {
1412 retval = MPI_ERR_COUNT;
1414 int size = smpi_datatype_get_extent(datatype) * count;
1415 recvbuf = xbt_new0(char, size);
1417 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1418 datatype, src, recvtag, comm, status);
1419 if(retval==MPI_SUCCESS){
1420 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1428 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1433 if (request == NULL || flag == NULL) {
1434 retval = MPI_ERR_ARG;
1435 } else if (*request == MPI_REQUEST_NULL) {
1437 smpi_empty_status(status);
1438 retval = MPI_ERR_REQUEST;
1440 *flag = smpi_mpi_test(request, status);
1441 retval = MPI_SUCCESS;
1447 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1448 MPI_Status * status)
1453 if (index == NULL || flag == NULL) {
1454 retval = MPI_ERR_ARG;
1456 *flag = smpi_mpi_testany(count, requests, index, status);
1457 retval = MPI_SUCCESS;
1463 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1469 retval = MPI_ERR_ARG;
1471 *flag = smpi_mpi_testall(count, requests, statuses);
1472 retval = MPI_SUCCESS;
1478 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1482 if (status == NULL) {
1483 retval = MPI_ERR_ARG;
1484 } else if (comm == MPI_COMM_NULL) {
1485 retval = MPI_ERR_COMM;
1486 } else if (source == MPI_PROC_NULL) {
1487 smpi_empty_status(status);
1488 status->MPI_SOURCE = MPI_PROC_NULL;
1489 retval = MPI_SUCCESS;
1491 smpi_mpi_probe(source, tag, comm, status);
1492 retval = MPI_SUCCESS;
1499 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1504 retval = MPI_ERR_ARG;
1505 } else if (status == NULL) {
1506 retval = MPI_ERR_ARG;
1507 } else if (comm == MPI_COMM_NULL) {
1508 retval = MPI_ERR_COMM;
1509 } else if (source == MPI_PROC_NULL) {
1511 smpi_empty_status(status);
1512 status->MPI_SOURCE = MPI_PROC_NULL;
1513 retval = MPI_SUCCESS;
1515 smpi_mpi_iprobe(source, tag, comm, flag, status);
1516 retval = MPI_SUCCESS;
1522 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1528 smpi_empty_status(status);
1530 if (request == NULL) {
1531 retval = MPI_ERR_ARG;
1532 } else if (*request == MPI_REQUEST_NULL) {
1533 retval = MPI_ERR_REQUEST;
1537 int rank = request && (*request)->comm != MPI_COMM_NULL
1538 ? smpi_process_index()
1541 int src_traced = (*request)->src;
1542 int dst_traced = (*request)->dst;
1543 MPI_Comm comm = (*request)->comm;
1544 int is_wait_for_receive = (*request)->recv;
1545 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1546 extra->type = TRACING_WAIT;
1547 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1550 smpi_mpi_wait(request, status);
1551 retval = MPI_SUCCESS;
1554 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1555 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1556 if (is_wait_for_receive) {
1557 if(src_traced==MPI_ANY_SOURCE)
1558 src_traced = (status!=MPI_STATUS_IGNORE) ?
1559 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1561 TRACE_smpi_recv(rank, src_traced, dst_traced);
1571 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1578 //save requests information for tracing
1580 int *srcs = xbt_new0(int, count);
1581 int *dsts = xbt_new0(int, count);
1582 int *recvs = xbt_new0(int, count);
1583 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1585 for (i = 0; i < count; i++) {
1586 MPI_Request req = requests[i]; //already received requests are no longer valid
1590 recvs[i] = req->recv;
1591 comms[i] = req->comm;
1594 int rank_traced = smpi_process_index();
1595 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1596 extra->type = TRACING_WAITANY;
1597 extra->send_size=count;
1598 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1601 *index = smpi_mpi_waitany(count, requests, status);
1603 if(*index!=MPI_UNDEFINED){
1604 int src_traced = srcs[*index];
1605 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1606 int dst_traced = dsts[*index];
1607 int is_wait_for_receive = recvs[*index];
1608 if (is_wait_for_receive) {
1609 if(srcs[*index]==MPI_ANY_SOURCE)
1610 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1611 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1613 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1615 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1627 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1632 //save information from requests
1634 int *srcs = xbt_new0(int, count);
1635 int *dsts = xbt_new0(int, count);
1636 int *recvs = xbt_new0(int, count);
1637 int *valid = xbt_new0(int, count);
1638 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1640 //int valid_count = 0;
1641 for (i = 0; i < count; i++) {
1642 MPI_Request req = requests[i];
1643 if(req!=MPI_REQUEST_NULL){
1646 recvs[i] = req->recv;
1647 comms[i] = req->comm;
1653 int rank_traced = smpi_process_index();
1654 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1655 extra->type = TRACING_WAITALL;
1656 extra->send_size=count;
1657 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1659 int retval = smpi_mpi_waitall(count, requests, status);
1661 for (i = 0; i < count; i++) {
1663 //int src_traced = srcs[*index];
1664 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1665 int src_traced = srcs[i];
1666 int dst_traced = dsts[i];
1667 int is_wait_for_receive = recvs[i];
1668 if (is_wait_for_receive) {
1669 if(src_traced==MPI_ANY_SOURCE)
1670 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1671 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1673 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1677 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1689 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1690 int *indices, MPI_Status status[])
1695 if (outcount == NULL) {
1696 retval = MPI_ERR_ARG;
1698 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1699 retval = MPI_SUCCESS;
1705 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1706 int* indices, MPI_Status status[])
1711 if (outcount == NULL) {
1712 retval = MPI_ERR_ARG;
1714 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1715 retval = MPI_SUCCESS;
1722 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1728 if (comm == MPI_COMM_NULL) {
1729 retval = MPI_ERR_COMM;
1732 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1733 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1735 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1736 extra->type = TRACING_BCAST;
1737 extra->send_size = count;
1738 extra->root = root_traced;
1739 extra->datatype1 = encode_datatype(datatype);
1740 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1743 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1744 retval = MPI_SUCCESS;
1746 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1754 int PMPI_Barrier(MPI_Comm comm)
1760 if (comm == MPI_COMM_NULL) {
1761 retval = MPI_ERR_COMM;
1764 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1765 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1766 extra->type = TRACING_BARRIER;
1767 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1769 mpi_coll_barrier_fun(comm);
1770 retval = MPI_SUCCESS;
1772 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1780 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1781 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1782 int root, MPI_Comm comm)
1788 if (comm == MPI_COMM_NULL) {
1789 retval = MPI_ERR_COMM;
1790 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1791 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1792 retval = MPI_ERR_TYPE;
1793 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1794 ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1795 retval = MPI_ERR_COUNT;
1798 char* sendtmpbuf = (char*) sendbuf;
1799 int sendtmpcount = sendcount;
1800 MPI_Datatype sendtmptype = sendtype;
1801 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1803 sendtmptype=recvtype;
1806 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1807 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1808 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1809 extra->type = TRACING_GATHER;
1810 extra->send_size = sendtmpcount;
1811 extra->recv_size = recvcount;
1812 extra->root = root_traced;
1813 extra->datatype1 = encode_datatype(sendtmptype);
1814 extra->datatype2 = encode_datatype(recvtype);
1816 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1818 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1819 recvtype, root, comm);
1822 retval = MPI_SUCCESS;
1824 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1832 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1833 void *recvbuf, int *recvcounts, int *displs,
1834 MPI_Datatype recvtype, int root, MPI_Comm comm)
1840 if (comm == MPI_COMM_NULL) {
1841 retval = MPI_ERR_COMM;
1842 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1843 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1844 retval = MPI_ERR_TYPE;
1845 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1846 retval = MPI_ERR_COUNT;
1847 } else if (recvcounts == NULL || displs == NULL) {
1848 retval = MPI_ERR_ARG;
1850 char* sendtmpbuf = (char*) sendbuf;
1851 int sendtmpcount = sendcount;
1852 MPI_Datatype sendtmptype = sendtype;
1853 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1855 sendtmptype=recvtype;
1859 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1860 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1862 int size = smpi_comm_size(comm);
1863 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1864 extra->type = TRACING_GATHERV;
1865 extra->send_size = sendtmpcount;
1866 extra->recvcounts= xbt_malloc(size*sizeof(int));
1867 for(i=0; i< size; i++)//copy data to avoid bad free
1868 extra->recvcounts[i] = recvcounts[i];
1869 extra->num_processes = size;
1870 extra->root = root_traced;
1871 extra->datatype1 = encode_datatype(sendtmptype);
1872 extra->datatype2 = encode_datatype(recvtype);
1874 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1876 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1877 displs, recvtype, root, comm);
1878 retval = MPI_SUCCESS;
1880 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1888 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1889 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1896 if (comm == MPI_COMM_NULL) {
1897 retval = MPI_ERR_COMM;
1898 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1899 (recvtype == MPI_DATATYPE_NULL)){
1900 retval = MPI_ERR_TYPE;
1901 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1903 retval = MPI_ERR_COUNT;
1905 if(sendbuf == MPI_IN_PLACE) {
1906 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1907 sendcount=recvcount;
1911 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1912 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1913 extra->type = TRACING_ALLGATHER;
1914 extra->send_size = sendcount;
1915 extra->recv_size = recvcount;
1916 extra->datatype1 = encode_datatype(sendtype);
1917 extra->datatype2 = encode_datatype(recvtype);
1919 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1921 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1923 retval = MPI_SUCCESS;
1926 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1933 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1934 void *recvbuf, int *recvcounts, int *displs,
1935 MPI_Datatype recvtype, MPI_Comm comm)
1941 if (comm == MPI_COMM_NULL) {
1942 retval = MPI_ERR_COMM;
1943 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1944 (recvtype == MPI_DATATYPE_NULL)){
1945 retval = MPI_ERR_TYPE;
1946 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1947 retval = MPI_ERR_COUNT;
1948 } else if (recvcounts == NULL || displs == NULL) {
1949 retval = MPI_ERR_ARG;
1952 if(sendbuf == MPI_IN_PLACE) {
1953 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1954 sendcount=recvcounts[smpi_comm_rank(comm)];
1958 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1960 int size = smpi_comm_size(comm);
1961 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1962 extra->type = TRACING_ALLGATHERV;
1963 extra->send_size = sendcount;
1964 extra->recvcounts= xbt_malloc(size*sizeof(int));
1965 for(i=0; i< size; i++)//copy data to avoid bad free
1966 extra->recvcounts[i] = recvcounts[i];
1967 extra->num_processes = size;
1968 extra->datatype1 = encode_datatype(sendtype);
1969 extra->datatype2 = encode_datatype(recvtype);
1971 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1973 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1974 displs, recvtype, comm);
1975 retval = MPI_SUCCESS;
1977 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1985 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1986 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1987 int root, MPI_Comm comm)
1993 if (comm == MPI_COMM_NULL) {
1994 retval = MPI_ERR_COMM;
1995 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1996 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1997 retval = MPI_ERR_TYPE;
2000 if (recvbuf == MPI_IN_PLACE) {
2002 recvcount=sendcount;
2005 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2006 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2007 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2008 extra->type = TRACING_SCATTER;
2009 extra->send_size = sendcount;
2010 extra->recv_size= recvcount;
2011 extra->root = root_traced;
2012 extra->datatype1 = encode_datatype(sendtype);
2013 extra->datatype2 = encode_datatype(recvtype);
2015 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2017 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
2018 recvtype, root, comm);
2019 retval = MPI_SUCCESS;
2021 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2029 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
2030 MPI_Datatype sendtype, void *recvbuf, int recvcount,
2031 MPI_Datatype recvtype, int root, MPI_Comm comm)
2037 if (comm == MPI_COMM_NULL) {
2038 retval = MPI_ERR_COMM;
2039 } else if (sendcounts == NULL || displs == NULL) {
2040 retval = MPI_ERR_ARG;
2041 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2042 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2043 retval = MPI_ERR_TYPE;
2045 if (recvbuf == MPI_IN_PLACE) {
2047 recvcount=sendcounts[smpi_comm_rank(comm)];
2050 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2051 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2053 int size = smpi_comm_size(comm);
2054 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2055 extra->type = TRACING_SCATTERV;
2056 extra->recv_size = recvcount;
2057 extra->sendcounts= xbt_malloc(size*sizeof(int));
2058 for(i=0; i< size; i++)//copy data to avoid bad free
2059 extra->sendcounts[i] = sendcounts[i];
2060 extra->num_processes = size;
2061 extra->root = root_traced;
2062 extra->datatype1 = encode_datatype(sendtype);
2063 extra->datatype2 = encode_datatype(recvtype);
2065 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2068 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2069 recvcount, recvtype, root, comm);
2070 retval = MPI_SUCCESS;
2072 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2080 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2081 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2087 if (comm == MPI_COMM_NULL) {
2088 retval = MPI_ERR_COMM;
2089 } else if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
2090 retval = MPI_ERR_ARG;
2093 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2094 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2095 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2096 extra->type = TRACING_REDUCE;
2097 extra->send_size = count;
2098 extra->datatype1 = encode_datatype(datatype);
2099 extra->root = root_traced;
2101 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2103 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2105 retval = MPI_SUCCESS;
2107 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2115 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2116 MPI_Datatype datatype, MPI_Op op){
2120 if (datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
2121 retval = MPI_ERR_ARG;
2123 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2130 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2131 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2137 if (comm == MPI_COMM_NULL) {
2138 retval = MPI_ERR_COMM;
2139 } else if (datatype == MPI_DATATYPE_NULL) {
2140 retval = MPI_ERR_TYPE;
2141 } else if (op == MPI_OP_NULL) {
2142 retval = MPI_ERR_OP;
2145 char* sendtmpbuf = (char*) sendbuf;
2146 if( sendbuf == MPI_IN_PLACE ) {
2147 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2148 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2151 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2152 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2153 extra->type = TRACING_ALLREDUCE;
2154 extra->send_size = count;
2155 extra->datatype1 = encode_datatype(datatype);
2157 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2159 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2161 if( sendbuf == MPI_IN_PLACE ) {
2162 xbt_free(sendtmpbuf);
2165 retval = MPI_SUCCESS;
2167 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2175 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2176 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2182 if (comm == MPI_COMM_NULL) {
2183 retval = MPI_ERR_COMM;
2184 } else if (datatype == MPI_DATATYPE_NULL) {
2185 retval = MPI_ERR_TYPE;
2186 } else if (op == MPI_OP_NULL) {
2187 retval = MPI_ERR_OP;
2190 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2191 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2192 extra->type = TRACING_SCAN;
2193 extra->send_size = count;
2194 extra->datatype1 = encode_datatype(datatype);
2196 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2198 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2199 retval = MPI_SUCCESS;
2201 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2209 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2210 MPI_Op op, MPI_Comm comm){
2215 if (comm == MPI_COMM_NULL) {
2216 retval = MPI_ERR_COMM;
2217 } else if (datatype == MPI_DATATYPE_NULL) {
2218 retval = MPI_ERR_TYPE;
2219 } else if (op == MPI_OP_NULL) {
2220 retval = MPI_ERR_OP;
2223 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2224 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2225 extra->type = TRACING_EXSCAN;
2226 extra->send_size = count;
2227 extra->datatype1 = encode_datatype(datatype);
2229 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2231 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2232 retval = MPI_SUCCESS;
2234 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2242 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2243 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2248 if (comm == MPI_COMM_NULL) {
2249 retval = MPI_ERR_COMM;
2250 } else if (datatype == MPI_DATATYPE_NULL) {
2251 retval = MPI_ERR_TYPE;
2252 } else if (op == MPI_OP_NULL) {
2253 retval = MPI_ERR_OP;
2254 } else if (recvcounts == NULL) {
2255 retval = MPI_ERR_ARG;
2258 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2260 int size = smpi_comm_size(comm);
2261 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2262 extra->type = TRACING_REDUCE_SCATTER;
2263 extra->send_size = 0;
2264 extra->recvcounts= xbt_malloc(size*sizeof(int));
2265 for(i=0; i< size; i++)//copy data to avoid bad free
2266 extra->recvcounts[i] = recvcounts[i];
2267 extra->num_processes = size;
2268 extra->datatype1 = encode_datatype(datatype);
2270 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2272 void* sendtmpbuf=sendbuf;
2273 if(sendbuf==MPI_IN_PLACE){
2277 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2278 datatype, op, comm);
2279 retval = MPI_SUCCESS;
2281 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2289 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2290 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2295 if (comm == MPI_COMM_NULL) {
2296 retval = MPI_ERR_COMM;
2297 } else if (datatype == MPI_DATATYPE_NULL) {
2298 retval = MPI_ERR_TYPE;
2299 } else if (op == MPI_OP_NULL) {
2300 retval = MPI_ERR_OP;
2301 } else if (recvcount < 0) {
2302 retval = MPI_ERR_ARG;
2304 int count=smpi_comm_size(comm);
2307 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2308 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2309 extra->type = TRACING_REDUCE_SCATTER;
2310 extra->send_size = 0;
2311 extra->recvcounts= xbt_malloc(count*sizeof(int));
2312 for(i=0; i< count; i++)//copy data to avoid bad free
2313 extra->recvcounts[i] = recvcount;
2314 extra->num_processes = count;
2315 extra->datatype1 = encode_datatype(datatype);
2317 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2319 int* recvcounts=(int*)xbt_malloc(count);
2320 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2321 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2322 datatype, op, comm);
2323 xbt_free(recvcounts);
2324 retval = MPI_SUCCESS;
2326 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2334 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2335 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2342 if (comm == MPI_COMM_NULL) {
2343 retval = MPI_ERR_COMM;
2344 } else if (sendtype == MPI_DATATYPE_NULL
2345 || recvtype == MPI_DATATYPE_NULL) {
2346 retval = MPI_ERR_TYPE;
2349 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2350 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2351 extra->type = TRACING_ALLTOALL;
2352 extra->send_size = sendcount;
2353 extra->recv_size = recvcount;
2354 extra->datatype1 = encode_datatype(sendtype);
2355 extra->datatype2 = encode_datatype(recvtype);
2357 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2359 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2361 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2369 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2370 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2371 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2377 if (comm == MPI_COMM_NULL) {
2378 retval = MPI_ERR_COMM;
2379 } else if (sendtype == MPI_DATATYPE_NULL
2380 || recvtype == MPI_DATATYPE_NULL) {
2381 retval = MPI_ERR_TYPE;
2382 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2383 || recvdisps == NULL) {
2384 retval = MPI_ERR_ARG;
2387 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2389 int size = smpi_comm_size(comm);
2390 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2391 extra->type = TRACING_ALLTOALLV;
2392 extra->send_size = 0;
2393 extra->recv_size = 0;
2394 extra->recvcounts= xbt_malloc(size*sizeof(int));
2395 extra->sendcounts= xbt_malloc(size*sizeof(int));
2397 for(i=0; i< size; i++){//copy data to avoid bad free
2398 extra->send_size += sendcounts[i];
2399 extra->recv_size += recvcounts[i];
2401 extra->sendcounts[i] = sendcounts[i];
2402 extra->recvcounts[i] = recvcounts[i];
2404 extra->num_processes = size;
2406 extra->datatype1 = encode_datatype(sendtype);
2407 extra->datatype2 = encode_datatype(recvtype);
2409 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2412 mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2413 recvbuf, recvcounts, recvdisps, recvtype,
2416 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2425 int PMPI_Get_processor_name(char *name, int *resultlen)
2427 int retval = MPI_SUCCESS;
2430 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2431 strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2432 strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2433 MPI_MAX_PROCESSOR_NAME - 1 );
2436 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2442 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2444 int retval = MPI_SUCCESS;
2448 if (status == NULL || count == NULL) {
2449 retval = MPI_ERR_ARG;
2450 } else if (datatype == MPI_DATATYPE_NULL) {
2451 retval = MPI_ERR_TYPE;
2453 size = smpi_datatype_size(datatype);
2456 } else if (status->count % size != 0) {
2457 retval = MPI_UNDEFINED;
2459 *count = smpi_mpi_get_count(status, datatype);
2466 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2470 if (old_type == MPI_DATATYPE_NULL) {
2471 retval = MPI_ERR_TYPE;
2472 } else if (count<0){
2473 retval = MPI_ERR_COUNT;
2475 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2481 int PMPI_Type_commit(MPI_Datatype* datatype) {
2485 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2486 retval = MPI_ERR_TYPE;
2488 smpi_datatype_commit(datatype);
2489 retval = MPI_SUCCESS;
2496 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2500 if (old_type == MPI_DATATYPE_NULL) {
2501 retval = MPI_ERR_TYPE;
2502 } else if (count<0 || blocklen<0){
2503 retval = MPI_ERR_COUNT;
2505 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2511 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2515 if (old_type == MPI_DATATYPE_NULL) {
2516 retval = MPI_ERR_TYPE;
2517 } else if (count<0 || blocklen<0){
2518 retval = MPI_ERR_COUNT;
2520 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2526 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2527 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2530 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2534 if (old_type == MPI_DATATYPE_NULL) {
2535 retval = MPI_ERR_TYPE;
2536 } else if (count<0){
2537 retval = MPI_ERR_COUNT;
2539 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2545 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2549 if (old_type == MPI_DATATYPE_NULL) {
2550 retval = MPI_ERR_TYPE;
2551 } else if (count<0){
2552 retval = MPI_ERR_COUNT;
2554 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2560 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2564 if (old_type == MPI_DATATYPE_NULL) {
2565 retval = MPI_ERR_TYPE;
2566 } else if (count<0){
2567 retval = MPI_ERR_COUNT;
2569 int* blocklens=(int*)xbt_malloc(blocklength*count);
2570 for (i=0; i<count;i++)blocklens[i]=blocklength;
2571 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2572 xbt_free(blocklens);
2579 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2583 if (old_type == MPI_DATATYPE_NULL) {
2584 retval = MPI_ERR_TYPE;
2585 } else if (count<0){
2586 retval = MPI_ERR_COUNT;
2588 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2594 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2595 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2598 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2602 if (old_type == MPI_DATATYPE_NULL) {
2603 retval = MPI_ERR_TYPE;
2604 } else if (count<0){
2605 retval = MPI_ERR_COUNT;
2607 int* blocklens=(int*)xbt_malloc(blocklength*count);
2608 for (i=0; i<count;i++)blocklens[i]=blocklength;
2609 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2610 xbt_free(blocklens);
2617 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2622 retval = MPI_ERR_COUNT;
2624 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2630 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2631 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2635 int PMPI_Error_class(int errorcode, int* errorclass) {
2636 // assume smpi uses only standard mpi error codes
2637 *errorclass=errorcode;
2642 int PMPI_Initialized(int* flag) {
2643 *flag=smpi_process_initialized();
2647 /* The following calls are not yet implemented and will fail at runtime. */
2648 /* Once implemented, please move them above this notice. */
2650 #define NOT_YET_IMPLEMENTED {\
2651 XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__);\
2652 return MPI_SUCCESS;\
2656 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
2660 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2665 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2670 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2674 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2678 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periods, int reorder, MPI_Comm* comm_cart) {
2682 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2686 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2690 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2694 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2698 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2702 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2706 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2710 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2714 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2718 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2722 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2726 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2730 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2734 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2738 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2742 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2746 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2750 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2754 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
2758 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
2762 int PMPI_Cancel(MPI_Request* request) {
2766 int PMPI_Buffer_attach(void* buffer, int size) {
2770 int PMPI_Buffer_detach(void* buffer, int* size) {
2774 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2778 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2783 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
2788 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
2793 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
2798 int PMPI_Comm_free_keyval(int* keyval) {
2802 int PMPI_Pcontrol(const int level )
2807 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2811 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
2816 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
2821 int PMPI_Type_delete_attr (MPI_Datatype type, int comm_keyval)
2826 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
2831 int PMPI_Type_free_keyval(int* keyval) {
2835 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2839 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2843 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2847 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2851 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2855 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2859 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2863 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2867 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2871 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2875 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2879 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2883 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2887 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2891 int PMPI_Keyval_free(int* keyval) {
2895 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2899 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2903 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
2907 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
2911 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
2915 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2919 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2923 int PMPI_Win_fence( int assert, MPI_Win win){
2927 int PMPI_Win_free( MPI_Win* win){
2931 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2935 int PMPI_Info_create( MPI_Info *info){
2939 int PMPI_Info_set( MPI_Info info, char *key, char *value){
2943 int PMPI_Info_free( MPI_Info *info){
2947 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2948 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2952 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
2953 int *num_addresses, int *num_datatypes, int *combiner){
2957 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
2958 int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
2959 MPI_Datatype* array_of_datatypes){
2963 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
2964 int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
2965 int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
2969 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2973 int PMPI_Type_create_subarray(int ndims,int *array_of_sizes, int *array_of_subsizes, int *array_of_starts, int order, MPI_Datatype oldtype, MPI_Datatype *newtype){
2977 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
2981 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
2982 void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
2987 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
2991 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
2995 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
2999 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3003 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3007 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3011 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3015 int PMPI_Add_error_class( int *errorclass){
3019 int PMPI_Add_error_code( int errorclass, int *errorcode){
3023 int PMPI_Add_error_string( int errorcode, char *string){
3027 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3031 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3035 int PMPI_Info_delete(MPI_Info info, char *key){
3039 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3043 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3047 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3051 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3055 int PMPI_Grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request){
3059 int PMPI_Grequest_complete( MPI_Request request){
3063 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3067 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3071 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3075 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3079 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3083 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3087 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3091 int PMPI_Open_port( MPI_Info info, char *port_name){
3095 int PMPI_Close_port(char *port_name){
3099 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3103 int PMPI_Comm_spawn( char *command, char **argv, int maxprocs, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3107 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3108 int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3109 MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3113 int PMPI_Comm_get_parent( MPI_Comm *parent){