1 /* Copyright (c) 2007-2014. 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-2014",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)
96 if (provided == NULL) {
99 *provided = MPI_THREAD_MULTIPLE;
100 retval = MPI_SUCCESS;
105 int PMPI_Is_thread_main(int *flag)
110 retval = MPI_ERR_ARG;
112 *flag = smpi_process_index() == 0;
113 retval = MPI_SUCCESS;
118 int PMPI_Abort(MPI_Comm comm, int errorcode)
121 smpi_process_destroy();
122 // FIXME: should kill all processes in comm instead
123 simcall_process_kill(SIMIX_process_self());
127 double PMPI_Wtime(void)
130 if (smpi_process_initialized() && !smpi_process_finalized() && !smpi_process_get_sampling()) {
132 time = SIMIX_get_clock();
135 time = SIMIX_get_clock();
140 extern double sg_maxmin_precision;
141 double PMPI_Wtick(void)
143 return sg_maxmin_precision;
146 int PMPI_Address(void *location, MPI_Aint * address)
151 retval = MPI_ERR_ARG;
153 *address = (MPI_Aint) location;
154 retval = MPI_SUCCESS;
159 int PMPI_Get_address(void *location, MPI_Aint * address)
161 return PMPI_Address(location, address);
164 int PMPI_Type_free(MPI_Datatype * datatype)
167 /* Free a predefined datatype is an error according to the standard, and
168 should be checked for */
169 if (*datatype == MPI_DATATYPE_NULL) {
170 retval = MPI_ERR_ARG;
172 smpi_datatype_free(datatype);
173 retval = MPI_SUCCESS;
178 int PMPI_Type_size(MPI_Datatype datatype, int *size)
182 if (datatype == MPI_DATATYPE_NULL) {
183 retval = MPI_ERR_TYPE;
184 } else if (size == NULL) {
185 retval = MPI_ERR_ARG;
187 *size = (int) smpi_datatype_size(datatype);
188 retval = MPI_SUCCESS;
193 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
197 if (datatype == MPI_DATATYPE_NULL) {
198 retval = MPI_ERR_TYPE;
199 } else if (lb == NULL || extent == NULL) {
200 retval = MPI_ERR_ARG;
202 retval = smpi_datatype_extent(datatype, lb, extent);
207 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
209 return PMPI_Type_get_extent(datatype, lb, extent);
212 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
216 if (datatype == MPI_DATATYPE_NULL) {
217 retval = MPI_ERR_TYPE;
218 } else if (extent == NULL) {
219 retval = MPI_ERR_ARG;
221 *extent = smpi_datatype_get_extent(datatype);
222 retval = MPI_SUCCESS;
227 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
231 if (datatype == MPI_DATATYPE_NULL) {
232 retval = MPI_ERR_TYPE;
233 } else if (disp == NULL) {
234 retval = MPI_ERR_ARG;
236 *disp = smpi_datatype_lb(datatype);
237 retval = MPI_SUCCESS;
242 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
246 if (datatype == MPI_DATATYPE_NULL) {
247 retval = MPI_ERR_TYPE;
248 } else if (disp == NULL) {
249 retval = MPI_ERR_ARG;
251 *disp = smpi_datatype_ub(datatype);
252 retval = MPI_SUCCESS;
257 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
261 if (function == NULL || op == NULL) {
262 retval = MPI_ERR_ARG;
264 *op = smpi_op_new(function, commute);
265 retval = MPI_SUCCESS;
270 int PMPI_Op_free(MPI_Op * op)
275 retval = MPI_ERR_ARG;
276 } else if (*op == MPI_OP_NULL) {
279 smpi_op_destroy(*op);
281 retval = MPI_SUCCESS;
286 int PMPI_Group_free(MPI_Group * group)
291 retval = MPI_ERR_ARG;
293 smpi_group_destroy(*group);
294 *group = MPI_GROUP_NULL;
295 retval = MPI_SUCCESS;
300 int PMPI_Group_size(MPI_Group group, int *size)
304 if (group == MPI_GROUP_NULL) {
305 retval = MPI_ERR_GROUP;
306 } else if (size == NULL) {
307 retval = MPI_ERR_ARG;
309 *size = smpi_group_size(group);
310 retval = MPI_SUCCESS;
315 int PMPI_Group_rank(MPI_Group group, int *rank)
319 if (group == MPI_GROUP_NULL) {
320 retval = MPI_ERR_GROUP;
321 } else if (rank == NULL) {
322 retval = MPI_ERR_ARG;
324 *rank = smpi_group_rank(group, smpi_process_index());
325 retval = MPI_SUCCESS;
330 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
331 MPI_Group group2, int *ranks2)
333 int retval, i, index;
334 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
335 retval = MPI_ERR_GROUP;
337 for (i = 0; i < n; i++) {
338 if(ranks1[i]==MPI_PROC_NULL){
339 ranks2[i]=MPI_PROC_NULL;
341 index = smpi_group_index(group1, ranks1[i]);
342 ranks2[i] = smpi_group_rank(group2, index);
345 retval = MPI_SUCCESS;
350 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
354 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
355 retval = MPI_ERR_GROUP;
356 } else if (result == NULL) {
357 retval = MPI_ERR_ARG;
359 *result = smpi_group_compare(group1, group2);
360 retval = MPI_SUCCESS;
365 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
366 MPI_Group * newgroup)
368 int retval, i, proc1, proc2, size, size2;
370 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
371 retval = MPI_ERR_GROUP;
372 } else if (newgroup == NULL) {
373 retval = MPI_ERR_ARG;
375 size = smpi_group_size(group1);
376 size2 = smpi_group_size(group2);
377 for (i = 0; i < size2; i++) {
378 proc2 = smpi_group_index(group2, i);
379 proc1 = smpi_group_rank(group1, proc2);
380 if (proc1 == MPI_UNDEFINED) {
385 *newgroup = MPI_GROUP_EMPTY;
387 *newgroup = smpi_group_new(size);
388 size2 = smpi_group_size(group1);
389 for (i = 0; i < size2; i++) {
390 proc1 = smpi_group_index(group1, i);
391 smpi_group_set_mapping(*newgroup, proc1, i);
393 for (i = size2; i < size; i++) {
394 proc2 = smpi_group_index(group2, i - size2);
395 smpi_group_set_mapping(*newgroup, proc2, i);
398 retval = MPI_SUCCESS;
403 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
404 MPI_Group * newgroup)
406 int retval, i, proc1, proc2, size;
408 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
409 retval = MPI_ERR_GROUP;
410 } else if (newgroup == NULL) {
411 retval = MPI_ERR_ARG;
413 size = smpi_group_size(group2);
414 for (i = 0; i < size; i++) {
415 proc2 = smpi_group_index(group2, i);
416 proc1 = smpi_group_rank(group1, proc2);
417 if (proc1 == MPI_UNDEFINED) {
422 *newgroup = MPI_GROUP_EMPTY;
424 *newgroup = smpi_group_new(size);
426 for (i = 0; i < smpi_group_size(group2); i++) {
427 proc2 = smpi_group_index(group2, i);
428 proc1 = smpi_group_rank(group1, proc2);
429 if (proc1 != MPI_UNDEFINED) {
430 smpi_group_set_mapping(*newgroup, proc2, j);
435 retval = MPI_SUCCESS;
440 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
442 int retval, i, proc1, proc2, size, size2;
444 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
445 retval = MPI_ERR_GROUP;
446 } else if (newgroup == NULL) {
447 retval = MPI_ERR_ARG;
449 size = size2 = smpi_group_size(group1);
450 for (i = 0; i < size2; i++) {
451 proc1 = smpi_group_index(group1, i);
452 proc2 = smpi_group_rank(group2, proc1);
453 if (proc2 != MPI_UNDEFINED) {
458 *newgroup = MPI_GROUP_EMPTY;
460 *newgroup = smpi_group_new(size);
461 for (i = 0; i < size2; i++) {
462 proc1 = smpi_group_index(group1, i);
463 proc2 = smpi_group_rank(group2, proc1);
464 if (proc2 == MPI_UNDEFINED) {
465 smpi_group_set_mapping(*newgroup, proc1, i);
469 retval = MPI_SUCCESS;
474 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
476 int retval, i, index;
478 if (group == MPI_GROUP_NULL) {
479 retval = MPI_ERR_GROUP;
480 } else if (newgroup == NULL) {
481 retval = MPI_ERR_ARG;
484 *newgroup = MPI_GROUP_EMPTY;
485 } else if (n == smpi_group_size(group)) {
487 if(group!= smpi_comm_group(MPI_COMM_WORLD)
488 && group != MPI_GROUP_NULL
489 && group != smpi_comm_group(MPI_COMM_SELF)
490 && group != MPI_GROUP_EMPTY)
491 smpi_group_use(group);
493 *newgroup = smpi_group_new(n);
494 for (i = 0; i < n; i++) {
495 index = smpi_group_index(group, ranks[i]);
496 smpi_group_set_mapping(*newgroup, index, i);
499 retval = MPI_SUCCESS;
504 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
506 int retval, i, j, newsize, oldsize, index;
508 if (group == MPI_GROUP_NULL) {
509 retval = MPI_ERR_GROUP;
510 } else if (newgroup == NULL) {
511 retval = MPI_ERR_ARG;
515 if(group!= smpi_comm_group(MPI_COMM_WORLD)
516 && group != MPI_GROUP_NULL
517 && group != smpi_comm_group(MPI_COMM_SELF)
518 && group != MPI_GROUP_EMPTY)
519 smpi_group_use(group);
520 } else if (n == smpi_group_size(group)) {
521 *newgroup = MPI_GROUP_EMPTY;
523 oldsize=smpi_group_size(group);
524 newsize = oldsize - n;
525 *newgroup = smpi_group_new(newsize);
527 int* to_exclude=xbt_new0(int, smpi_group_size(group));
528 for(i=0; i<oldsize; i++)
531 to_exclude[ranks[i]]=1;
534 for(i=0; i<oldsize; i++){
535 if(to_exclude[i]==0){
536 index = smpi_group_index(group, i);
537 smpi_group_set_mapping(*newgroup, index, j);
542 xbt_free(to_exclude);
544 retval = MPI_SUCCESS;
549 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
550 MPI_Group * newgroup)
552 int retval, i, j, rank, size, index;
554 if (group == MPI_GROUP_NULL) {
555 retval = MPI_ERR_GROUP;
556 } else if (newgroup == NULL) {
557 retval = MPI_ERR_ARG;
560 *newgroup = MPI_GROUP_EMPTY;
563 for (i = 0; i < n; i++) {
564 for (rank = ranges[i][0]; /* First */
565 rank >= 0; /* Last */
569 rank += ranges[i][2]; /* Stride */
570 if (ranges[i][0]<ranges[i][1]){
571 if(rank > ranges[i][1])
574 if(rank < ranges[i][1])
580 *newgroup = smpi_group_new(size);
582 for (i = 0; i < n; i++) {
583 for (rank = ranges[i][0]; /* First */
584 rank >= 0; /* Last */
586 index = smpi_group_index(group, rank);
587 smpi_group_set_mapping(*newgroup, index, j);
589 rank += ranges[i][2]; /* Stride */
590 if (ranges[i][0]<ranges[i][1]){
591 if(rank > ranges[i][1])
594 if(rank < ranges[i][1])
600 retval = MPI_SUCCESS;
605 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
606 MPI_Group * newgroup)
608 int retval, i, rank, newrank,oldrank, size, index, add;
610 if (group == MPI_GROUP_NULL) {
611 retval = MPI_ERR_GROUP;
612 } else if (newgroup == NULL) {
613 retval = MPI_ERR_ARG;
617 if(group!= smpi_comm_group(MPI_COMM_WORLD)
618 && group != MPI_GROUP_NULL
619 && group != smpi_comm_group(MPI_COMM_SELF)
620 && group != MPI_GROUP_EMPTY)
621 smpi_group_use(group);
623 size = smpi_group_size(group);
624 for (i = 0; i < n; i++) {
625 for (rank = ranges[i][0]; /* First */
626 rank >= 0; /* Last */
630 rank += ranges[i][2]; /* Stride */
631 if (ranges[i][0]<ranges[i][1]){
632 if(rank > ranges[i][1])
635 if(rank < ranges[i][1])
641 *newgroup = MPI_GROUP_EMPTY;
643 *newgroup = smpi_group_new(size);
646 while (newrank < size) {
648 for (i = 0; i < n; i++) {
649 for (rank = ranges[i][0];rank >= 0;){
655 rank += ranges[i][2]; /* Stride */
657 if (ranges[i][0]<ranges[i][1]){
658 if(rank > ranges[i][1])
661 if(rank < ranges[i][1])
667 index = smpi_group_index(group, oldrank);
668 smpi_group_set_mapping(*newgroup, index, newrank);
676 retval = MPI_SUCCESS;
681 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
684 if (comm == MPI_COMM_NULL) {
685 retval = MPI_ERR_COMM;
686 } else if (rank == NULL) {
687 retval = MPI_ERR_ARG;
689 *rank = smpi_comm_rank(comm);
690 retval = MPI_SUCCESS;
695 int PMPI_Comm_size(MPI_Comm comm, int *size)
698 if (comm == MPI_COMM_NULL) {
699 retval = MPI_ERR_COMM;
700 } else if (size == NULL) {
701 retval = MPI_ERR_ARG;
703 *size = smpi_comm_size(comm);
704 retval = MPI_SUCCESS;
709 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
713 if (comm == MPI_COMM_NULL) {
714 retval = MPI_ERR_COMM;
715 } else if (name == NULL || len == NULL) {
716 retval = MPI_ERR_ARG;
718 smpi_comm_get_name(comm, name, len);
719 retval = MPI_SUCCESS;
724 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
728 if (comm == MPI_COMM_NULL) {
729 retval = MPI_ERR_COMM;
730 } else if (group == NULL) {
731 retval = MPI_ERR_ARG;
733 *group = smpi_comm_group(comm);
734 if(*group!= smpi_comm_group(MPI_COMM_WORLD)
735 && *group != MPI_GROUP_NULL
736 && *group != smpi_comm_group(MPI_COMM_SELF)
737 && *group != MPI_GROUP_EMPTY)
738 smpi_group_use(*group);
739 retval = MPI_SUCCESS;
744 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
748 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
749 retval = MPI_ERR_COMM;
750 } else if (result == NULL) {
751 retval = MPI_ERR_ARG;
753 if (comm1 == comm2) { /* Same communicators means same groups */
757 smpi_group_compare(smpi_comm_group(comm1),
758 smpi_comm_group(comm2));
759 if (*result == MPI_IDENT) {
760 *result = MPI_CONGRUENT;
763 retval = MPI_SUCCESS;
768 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
772 if (comm == MPI_COMM_NULL) {
773 retval = MPI_ERR_COMM;
774 } else if (newcomm == NULL) {
775 retval = MPI_ERR_ARG;
777 *newcomm = smpi_comm_new(smpi_comm_group(comm), smpi_comm_topo(comm));
778 retval = MPI_SUCCESS;
783 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
787 if (comm == MPI_COMM_NULL) {
788 retval = MPI_ERR_COMM;
789 } else if (group == MPI_GROUP_NULL) {
790 retval = MPI_ERR_GROUP;
791 } else if (newcomm == NULL) {
792 retval = MPI_ERR_ARG;
793 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
794 *newcomm= MPI_COMM_NULL;
795 retval = MPI_SUCCESS;
798 *newcomm = smpi_comm_new(group, NULL);
799 retval = MPI_SUCCESS;
804 int PMPI_Comm_free(MPI_Comm * comm)
809 retval = MPI_ERR_ARG;
810 } else if (*comm == MPI_COMM_NULL) {
811 retval = MPI_ERR_COMM;
813 smpi_comm_destroy(*comm);
814 *comm = MPI_COMM_NULL;
815 retval = MPI_SUCCESS;
820 int PMPI_Comm_disconnect(MPI_Comm * comm)
822 /* TODO: wait until all communication in comm are done */
826 retval = MPI_ERR_ARG;
827 } else if (*comm == MPI_COMM_NULL) {
828 retval = MPI_ERR_COMM;
830 smpi_comm_destroy(*comm);
831 *comm = MPI_COMM_NULL;
832 retval = MPI_SUCCESS;
837 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
842 if (comm_out == NULL) {
843 retval = MPI_ERR_ARG;
844 } else if (comm == MPI_COMM_NULL) {
845 retval = MPI_ERR_COMM;
847 *comm_out = smpi_comm_split(comm, color, key);
848 retval = MPI_SUCCESS;
855 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
856 int tag, MPI_Comm comm, MPI_Request * request)
861 if (request == NULL) {
862 retval = MPI_ERR_ARG;
863 } else if (comm == MPI_COMM_NULL) {
864 retval = MPI_ERR_COMM;
865 } else if (!is_datatype_valid(datatype)) {
866 retval = MPI_ERR_TYPE;
867 } else if (dst == MPI_PROC_NULL) {
868 retval = MPI_SUCCESS;
870 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
871 retval = MPI_SUCCESS;
874 if (retval != MPI_SUCCESS && request)
875 *request = MPI_REQUEST_NULL;
879 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
880 int tag, MPI_Comm comm, MPI_Request * request)
885 if (request == NULL) {
886 retval = MPI_ERR_ARG;
887 } else if (comm == MPI_COMM_NULL) {
888 retval = MPI_ERR_COMM;
889 } else if (!is_datatype_valid(datatype)) {
890 retval = MPI_ERR_TYPE;
891 } else if (src == MPI_PROC_NULL) {
892 retval = MPI_SUCCESS;
894 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
895 retval = MPI_SUCCESS;
898 if (retval != MPI_SUCCESS && request)
899 *request = MPI_REQUEST_NULL;
903 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
904 int dst, int tag, MPI_Comm comm, MPI_Request* request)
909 if (request == NULL) {
910 retval = MPI_ERR_ARG;
911 } else if (comm == MPI_COMM_NULL) {
912 retval = MPI_ERR_COMM;
913 } else if (!is_datatype_valid(datatype)) {
914 retval = MPI_ERR_TYPE;
915 } else if (dst == MPI_PROC_NULL) {
916 retval = MPI_SUCCESS;
918 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
919 retval = MPI_SUCCESS;
922 if (retval != MPI_SUCCESS && request)
923 *request = MPI_REQUEST_NULL;
927 int PMPI_Start(MPI_Request * request)
932 if (request == NULL || *request == MPI_REQUEST_NULL) {
933 retval = MPI_ERR_REQUEST;
935 smpi_mpi_start(*request);
936 retval = MPI_SUCCESS;
942 int PMPI_Startall(int count, MPI_Request * requests)
947 if (requests == NULL) {
948 retval = MPI_ERR_ARG;
950 retval = MPI_SUCCESS;
951 for (i = 0 ; i < count ; i++) {
952 if(requests[i] == MPI_REQUEST_NULL) {
953 retval = MPI_ERR_REQUEST;
956 if(retval != MPI_ERR_REQUEST) {
957 smpi_mpi_startall(count, requests);
964 int PMPI_Request_free(MPI_Request * request)
969 if (*request == MPI_REQUEST_NULL) {
970 retval = MPI_ERR_ARG;
972 smpi_mpi_request_free(request);
973 retval = MPI_SUCCESS;
979 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
980 int tag, MPI_Comm comm, MPI_Request * request)
986 if (request == NULL) {
987 retval = MPI_ERR_ARG;
988 } else if (comm == MPI_COMM_NULL) {
989 retval = MPI_ERR_COMM;
990 } else if (src == MPI_PROC_NULL) {
991 *request = MPI_REQUEST_NULL;
992 retval = MPI_SUCCESS;
993 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
994 retval = MPI_ERR_COMM;
995 } else if (count < 0) {
996 retval = MPI_ERR_COUNT;
997 } else if (buf==NULL && count > 0) {
998 retval = MPI_ERR_COUNT;
999 } else if (!is_datatype_valid(datatype)) {
1000 retval = MPI_ERR_TYPE;
1001 } else if(tag<0 && tag != MPI_ANY_TAG){
1002 retval = MPI_ERR_TAG;
1006 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1007 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1009 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1010 extra->type = TRACING_IRECV;
1011 extra->send_size = count;
1012 extra->src = src_traced;
1014 extra->datatype1 = encode_datatype(datatype);
1015 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1018 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1019 retval = MPI_SUCCESS;
1022 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1023 (*request)->recv = 1;
1028 if (retval != MPI_SUCCESS && request)
1029 *request = MPI_REQUEST_NULL;
1034 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1035 int tag, MPI_Comm comm, MPI_Request * request)
1040 if (request == NULL) {
1041 retval = MPI_ERR_ARG;
1042 } else if (comm == MPI_COMM_NULL) {
1043 retval = MPI_ERR_COMM;
1044 } else if (dst == MPI_PROC_NULL) {
1045 *request = MPI_REQUEST_NULL;
1046 retval = MPI_SUCCESS;
1047 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1048 retval = MPI_ERR_RANK;
1049 } else if (count < 0) {
1050 retval = MPI_ERR_COUNT;
1051 } else if (buf==NULL && count > 0) {
1052 retval = MPI_ERR_COUNT;
1053 } else if (!is_datatype_valid(datatype)) {
1054 retval = MPI_ERR_TYPE;
1055 } else if(tag<0 && tag != MPI_ANY_TAG){
1056 retval = MPI_ERR_TAG;
1060 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1061 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1063 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1064 extra->type = TRACING_ISEND;
1065 extra->send_size = count;
1067 extra->dst = dst_traced;
1068 extra->datatype1 = encode_datatype(datatype);
1069 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1070 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1073 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1074 retval = MPI_SUCCESS;
1077 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1078 (*request)->send = 1;
1083 if (retval != MPI_SUCCESS && request)
1084 *request = MPI_REQUEST_NULL;
1088 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1089 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1094 if (request == NULL) {
1095 retval = MPI_ERR_ARG;
1096 } else if (comm == MPI_COMM_NULL) {
1097 retval = MPI_ERR_COMM;
1098 } else if (dst == MPI_PROC_NULL) {
1099 *request = MPI_REQUEST_NULL;
1100 retval = MPI_SUCCESS;
1101 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1102 retval = MPI_ERR_RANK;
1103 } else if (count < 0) {
1104 retval = MPI_ERR_COUNT;
1105 } else if (buf==NULL && count > 0) {
1106 retval = MPI_ERR_COUNT;
1107 } else if (!is_datatype_valid(datatype)) {
1108 retval = MPI_ERR_TYPE;
1109 } else if(tag<0 && tag != MPI_ANY_TAG){
1110 retval = MPI_ERR_TAG;
1114 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1115 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1116 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1117 extra->type = TRACING_ISSEND;
1118 extra->send_size = count;
1120 extra->dst = dst_traced;
1121 extra->datatype1 = encode_datatype(datatype);
1122 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1123 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1126 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1127 retval = MPI_SUCCESS;
1130 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1131 (*request)->send = 1;
1136 if (retval != MPI_SUCCESS && request)
1137 *request = MPI_REQUEST_NULL;
1141 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1142 MPI_Comm comm, MPI_Status * status)
1147 if (comm == MPI_COMM_NULL) {
1148 retval = MPI_ERR_COMM;
1149 } else if (src == MPI_PROC_NULL) {
1150 smpi_empty_status(status);
1151 status->MPI_SOURCE = MPI_PROC_NULL;
1152 retval = MPI_SUCCESS;
1153 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <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 (!is_datatype_valid(datatype)) {
1160 retval = MPI_ERR_TYPE;
1161 } else if(tag<0 && tag != MPI_ANY_TAG){
1162 retval = MPI_ERR_TAG;
1165 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1166 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1167 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1168 extra->type = TRACING_RECV;
1169 extra->send_size = count;
1170 extra->src = src_traced;
1172 extra->datatype1 = encode_datatype(datatype);
1173 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1176 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1177 retval = MPI_SUCCESS;
1180 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1181 if(status!=MPI_STATUS_IGNORE){
1182 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1183 TRACE_smpi_recv(rank, src_traced, rank);
1185 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1193 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1200 if (comm == MPI_COMM_NULL) {
1201 retval = MPI_ERR_COMM;
1202 } else if (dst == MPI_PROC_NULL) {
1203 retval = MPI_SUCCESS;
1204 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1205 retval = MPI_ERR_RANK;
1206 } else if (count < 0) {
1207 retval = MPI_ERR_COUNT;
1208 } else if (buf==NULL && count > 0) {
1209 retval = MPI_ERR_COUNT;
1210 } else if (!is_datatype_valid(datatype)) {
1211 retval = MPI_ERR_TYPE;
1212 } else if(tag<0 && tag != MPI_ANY_TAG){
1213 retval = MPI_ERR_TAG;
1217 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1218 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1219 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1220 extra->type = TRACING_SEND;
1221 extra->send_size = count;
1223 extra->dst = dst_traced;
1224 extra->datatype1 = encode_datatype(datatype);
1225 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1226 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1229 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1230 retval = MPI_SUCCESS;
1233 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1243 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1248 if (comm == MPI_COMM_NULL) {
1249 retval = MPI_ERR_COMM;
1250 } else if (dst == MPI_PROC_NULL) {
1251 retval = MPI_SUCCESS;
1252 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1253 retval = MPI_ERR_RANK;
1254 } else if (count < 0) {
1255 retval = MPI_ERR_COUNT;
1256 } else if (buf==NULL && count > 0) {
1257 retval = MPI_ERR_COUNT;
1258 } else if (!is_datatype_valid(datatype)){
1259 retval = MPI_ERR_TYPE;
1260 } else if(tag<0 && tag != MPI_ANY_TAG){
1261 retval = MPI_ERR_TAG;
1265 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1266 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1267 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1268 extra->type = TRACING_SSEND;
1269 extra->send_size = count;
1271 extra->dst = dst_traced;
1272 extra->datatype1 = encode_datatype(datatype);
1273 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra); TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1276 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1277 retval = MPI_SUCCESS;
1280 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1288 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1289 int dst, int sendtag, void *recvbuf, int recvcount,
1290 MPI_Datatype recvtype, int src, int recvtag,
1291 MPI_Comm comm, MPI_Status * status)
1297 if (comm == MPI_COMM_NULL) {
1298 retval = MPI_ERR_COMM;
1299 } else if (!is_datatype_valid(sendtype)
1300 || !is_datatype_valid(recvtype)) {
1301 retval = MPI_ERR_TYPE;
1302 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1303 smpi_empty_status(status);
1304 status->MPI_SOURCE = MPI_PROC_NULL;
1305 retval = MPI_SUCCESS;
1306 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1307 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1308 retval = MPI_ERR_RANK;
1309 } else if (sendcount < 0 || recvcount<0) {
1310 retval = MPI_ERR_COUNT;
1311 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1312 retval = MPI_ERR_COUNT;
1313 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1314 retval = MPI_ERR_TAG;
1318 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1319 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1320 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1321 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1322 extra->type = TRACING_SENDRECV;
1323 extra->send_size = sendcount;
1324 extra->recv_size = recvcount;
1325 extra->src = src_traced;
1326 extra->dst = dst_traced;
1327 extra->datatype1 = encode_datatype(sendtype);
1328 extra->datatype2 = encode_datatype(recvtype);
1330 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1331 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1335 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1336 recvcount, recvtype, src, recvtag, comm, status);
1337 retval = MPI_SUCCESS;
1340 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1341 TRACE_smpi_recv(rank, src_traced, rank);
1350 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1351 int dst, int sendtag, int src, int recvtag,
1352 MPI_Comm comm, MPI_Status * status)
1354 //TODO: suboptimal implementation
1357 if (!is_datatype_valid(datatype)) {
1358 retval = MPI_ERR_TYPE;
1359 } else if (count < 0) {
1360 retval = MPI_ERR_COUNT;
1362 int size = smpi_datatype_get_extent(datatype) * count;
1363 recvbuf = xbt_new0(char, size);
1365 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1366 datatype, src, recvtag, comm, status);
1367 if(retval==MPI_SUCCESS){
1368 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1376 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1380 if (request == NULL || flag == NULL) {
1381 retval = MPI_ERR_ARG;
1382 } else if (*request == MPI_REQUEST_NULL) {
1384 smpi_empty_status(status);
1385 retval = MPI_ERR_REQUEST;
1388 int rank = request && (*request)->comm != MPI_COMM_NULL
1389 ? smpi_process_index()
1392 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1393 extra->type = TRACING_TEST;
1394 TRACE_smpi_testing_in(rank, extra);
1396 *flag = smpi_mpi_test(request, status);
1398 TRACE_smpi_testing_out(rank);
1400 retval = MPI_SUCCESS;
1406 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1407 MPI_Status * status)
1412 if (index == NULL || flag == NULL) {
1413 retval = MPI_ERR_ARG;
1415 *flag = smpi_mpi_testany(count, requests, index, status);
1416 retval = MPI_SUCCESS;
1422 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1428 retval = MPI_ERR_ARG;
1430 *flag = smpi_mpi_testall(count, requests, statuses);
1431 retval = MPI_SUCCESS;
1437 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1441 if (status == NULL) {
1442 retval = MPI_ERR_ARG;
1443 } else if (comm == MPI_COMM_NULL) {
1444 retval = MPI_ERR_COMM;
1445 } else if (source == MPI_PROC_NULL) {
1446 smpi_empty_status(status);
1447 status->MPI_SOURCE = MPI_PROC_NULL;
1448 retval = MPI_SUCCESS;
1450 smpi_mpi_probe(source, tag, comm, status);
1451 retval = MPI_SUCCESS;
1458 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1463 retval = MPI_ERR_ARG;
1464 } else if (status == NULL) {
1465 retval = MPI_ERR_ARG;
1466 } else if (comm == MPI_COMM_NULL) {
1467 retval = MPI_ERR_COMM;
1468 } else if (source == MPI_PROC_NULL) {
1470 smpi_empty_status(status);
1471 status->MPI_SOURCE = MPI_PROC_NULL;
1472 retval = MPI_SUCCESS;
1474 smpi_mpi_iprobe(source, tag, comm, flag, status);
1475 retval = MPI_SUCCESS;
1481 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1487 smpi_empty_status(status);
1489 if (request == NULL) {
1490 retval = MPI_ERR_ARG;
1491 } else if (*request == MPI_REQUEST_NULL) {
1492 retval = MPI_ERR_REQUEST;
1496 int rank = request && (*request)->comm != MPI_COMM_NULL
1497 ? smpi_process_index()
1500 int src_traced = (*request)->src;
1501 int dst_traced = (*request)->dst;
1502 MPI_Comm comm = (*request)->comm;
1503 int is_wait_for_receive = (*request)->recv;
1504 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1505 extra->type = TRACING_WAIT;
1506 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1509 smpi_mpi_wait(request, status);
1510 retval = MPI_SUCCESS;
1513 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1514 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1515 if (is_wait_for_receive) {
1516 if(src_traced==MPI_ANY_SOURCE)
1517 src_traced = (status!=MPI_STATUS_IGNORE) ?
1518 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1520 TRACE_smpi_recv(rank, src_traced, dst_traced);
1530 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1537 //save requests information for tracing
1539 int *srcs = xbt_new0(int, count);
1540 int *dsts = xbt_new0(int, count);
1541 int *recvs = xbt_new0(int, count);
1542 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1544 for (i = 0; i < count; i++) {
1545 MPI_Request req = requests[i]; //already received requests are no longer valid
1549 recvs[i] = req->recv;
1550 comms[i] = req->comm;
1553 int rank_traced = smpi_process_index();
1554 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1555 extra->type = TRACING_WAITANY;
1556 extra->send_size=count;
1557 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1560 *index = smpi_mpi_waitany(count, requests, status);
1562 if(*index!=MPI_UNDEFINED){
1563 int src_traced = srcs[*index];
1564 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1565 int dst_traced = dsts[*index];
1566 int is_wait_for_receive = recvs[*index];
1567 if (is_wait_for_receive) {
1568 if(srcs[*index]==MPI_ANY_SOURCE)
1569 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1570 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1572 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1574 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1586 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1591 //save information from requests
1593 int *srcs = xbt_new0(int, count);
1594 int *dsts = xbt_new0(int, count);
1595 int *recvs = xbt_new0(int, count);
1596 int *valid = xbt_new0(int, count);
1597 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1599 //int valid_count = 0;
1600 for (i = 0; i < count; i++) {
1601 MPI_Request req = requests[i];
1602 if(req!=MPI_REQUEST_NULL){
1605 recvs[i] = req->recv;
1606 comms[i] = req->comm;
1612 int rank_traced = smpi_process_index();
1613 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1614 extra->type = TRACING_WAITALL;
1615 extra->send_size=count;
1616 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1618 int retval = smpi_mpi_waitall(count, requests, status);
1620 for (i = 0; i < count; i++) {
1622 //int src_traced = srcs[*index];
1623 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1624 int src_traced = srcs[i];
1625 int dst_traced = dsts[i];
1626 int is_wait_for_receive = recvs[i];
1627 if (is_wait_for_receive) {
1628 if(src_traced==MPI_ANY_SOURCE)
1629 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1630 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1632 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1636 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1648 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1649 int *indices, MPI_Status status[])
1654 if (outcount == NULL) {
1655 retval = MPI_ERR_ARG;
1657 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1658 retval = MPI_SUCCESS;
1664 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1665 int* indices, MPI_Status status[])
1670 if (outcount == NULL) {
1671 retval = MPI_ERR_ARG;
1673 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1674 retval = MPI_SUCCESS;
1681 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1687 if (comm == MPI_COMM_NULL) {
1688 retval = MPI_ERR_COMM;
1691 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1692 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1694 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1695 extra->type = TRACING_BCAST;
1696 extra->send_size = count;
1697 extra->root = root_traced;
1698 extra->datatype1 = encode_datatype(datatype);
1699 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1702 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1703 retval = MPI_SUCCESS;
1705 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1713 int PMPI_Barrier(MPI_Comm comm)
1719 if (comm == MPI_COMM_NULL) {
1720 retval = MPI_ERR_COMM;
1723 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1724 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1725 extra->type = TRACING_BARRIER;
1726 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1728 mpi_coll_barrier_fun(comm);
1729 retval = MPI_SUCCESS;
1731 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1739 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1740 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1741 int root, MPI_Comm comm)
1747 if (comm == MPI_COMM_NULL) {
1748 retval = MPI_ERR_COMM;
1749 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1750 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1751 retval = MPI_ERR_TYPE;
1752 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1753 ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1754 retval = MPI_ERR_COUNT;
1757 char* sendtmpbuf = (char*) sendbuf;
1758 int sendtmpcount = sendcount;
1759 MPI_Datatype sendtmptype = sendtype;
1760 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1762 sendtmptype=recvtype;
1765 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1766 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1767 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1768 extra->type = TRACING_GATHER;
1769 extra->send_size = sendtmpcount;
1770 extra->recv_size = recvcount;
1771 extra->root = root_traced;
1772 extra->datatype1 = encode_datatype(sendtmptype);
1773 extra->datatype2 = encode_datatype(recvtype);
1775 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1777 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1778 recvtype, root, comm);
1781 retval = MPI_SUCCESS;
1783 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1791 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1792 void *recvbuf, int *recvcounts, int *displs,
1793 MPI_Datatype recvtype, int root, MPI_Comm comm)
1799 if (comm == MPI_COMM_NULL) {
1800 retval = MPI_ERR_COMM;
1801 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1802 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1803 retval = MPI_ERR_TYPE;
1804 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1805 retval = MPI_ERR_COUNT;
1806 } else if (recvcounts == NULL || displs == NULL) {
1807 retval = MPI_ERR_ARG;
1809 char* sendtmpbuf = (char*) sendbuf;
1810 int sendtmpcount = sendcount;
1811 MPI_Datatype sendtmptype = sendtype;
1812 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1814 sendtmptype=recvtype;
1818 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1819 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1821 int size = smpi_comm_size(comm);
1822 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1823 extra->type = TRACING_GATHERV;
1824 extra->send_size = sendtmpcount;
1825 extra->recvcounts= xbt_malloc(size*sizeof(int));
1826 for(i=0; i< size; i++)//copy data to avoid bad free
1827 extra->recvcounts[i] = recvcounts[i];
1828 extra->num_processes = size;
1829 extra->root = root_traced;
1830 extra->datatype1 = encode_datatype(sendtmptype);
1831 extra->datatype2 = encode_datatype(recvtype);
1833 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1835 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1836 displs, recvtype, root, comm);
1837 retval = MPI_SUCCESS;
1839 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1847 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1848 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1855 if (comm == MPI_COMM_NULL) {
1856 retval = MPI_ERR_COMM;
1857 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1858 (recvtype == MPI_DATATYPE_NULL)){
1859 retval = MPI_ERR_TYPE;
1860 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1862 retval = MPI_ERR_COUNT;
1864 if(sendbuf == MPI_IN_PLACE) {
1865 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1866 sendcount=recvcount;
1870 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1871 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1872 extra->type = TRACING_ALLGATHER;
1873 extra->send_size = sendcount;
1874 extra->recv_size = recvcount;
1875 extra->datatype1 = encode_datatype(sendtype);
1876 extra->datatype2 = encode_datatype(recvtype);
1878 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1880 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1882 retval = MPI_SUCCESS;
1885 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1892 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1893 void *recvbuf, int *recvcounts, int *displs,
1894 MPI_Datatype recvtype, MPI_Comm comm)
1900 if (comm == MPI_COMM_NULL) {
1901 retval = MPI_ERR_COMM;
1902 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1903 (recvtype == MPI_DATATYPE_NULL)){
1904 retval = MPI_ERR_TYPE;
1905 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1906 retval = MPI_ERR_COUNT;
1907 } else if (recvcounts == NULL || displs == NULL) {
1908 retval = MPI_ERR_ARG;
1911 if(sendbuf == MPI_IN_PLACE) {
1912 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1913 sendcount=recvcounts[smpi_comm_rank(comm)];
1917 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1919 int size = smpi_comm_size(comm);
1920 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1921 extra->type = TRACING_ALLGATHERV;
1922 extra->send_size = sendcount;
1923 extra->recvcounts= xbt_malloc(size*sizeof(int));
1924 for(i=0; i< size; i++)//copy data to avoid bad free
1925 extra->recvcounts[i] = recvcounts[i];
1926 extra->num_processes = size;
1927 extra->datatype1 = encode_datatype(sendtype);
1928 extra->datatype2 = encode_datatype(recvtype);
1930 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1932 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1933 displs, recvtype, comm);
1934 retval = MPI_SUCCESS;
1936 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1944 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1945 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1946 int root, MPI_Comm comm)
1952 if (comm == MPI_COMM_NULL) {
1953 retval = MPI_ERR_COMM;
1954 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
1955 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
1956 retval = MPI_ERR_TYPE;
1959 if (recvbuf == MPI_IN_PLACE) {
1961 recvcount=sendcount;
1964 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1965 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1966 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1967 extra->type = TRACING_SCATTER;
1968 extra->send_size = sendcount;
1969 extra->recv_size= recvcount;
1970 extra->root = root_traced;
1971 extra->datatype1 = encode_datatype(sendtype);
1972 extra->datatype2 = encode_datatype(recvtype);
1974 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1976 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1977 recvtype, root, comm);
1978 retval = MPI_SUCCESS;
1980 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1988 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
1989 MPI_Datatype sendtype, void *recvbuf, int recvcount,
1990 MPI_Datatype recvtype, int root, MPI_Comm comm)
1996 if (comm == MPI_COMM_NULL) {
1997 retval = MPI_ERR_COMM;
1998 } else if (sendcounts == NULL || displs == NULL) {
1999 retval = MPI_ERR_ARG;
2000 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2001 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2002 retval = MPI_ERR_TYPE;
2004 if (recvbuf == MPI_IN_PLACE) {
2006 recvcount=sendcounts[smpi_comm_rank(comm)];
2009 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2010 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2012 int size = smpi_comm_size(comm);
2013 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2014 extra->type = TRACING_SCATTERV;
2015 extra->recv_size = recvcount;
2016 extra->sendcounts= xbt_malloc(size*sizeof(int));
2017 for(i=0; i< size; i++)//copy data to avoid bad free
2018 extra->sendcounts[i] = sendcounts[i];
2019 extra->num_processes = size;
2020 extra->root = root_traced;
2021 extra->datatype1 = encode_datatype(sendtype);
2022 extra->datatype2 = encode_datatype(recvtype);
2024 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2027 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2028 recvcount, recvtype, root, comm);
2029 retval = MPI_SUCCESS;
2031 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2039 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2040 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2046 if (comm == MPI_COMM_NULL) {
2047 retval = MPI_ERR_COMM;
2048 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2049 retval = MPI_ERR_ARG;
2052 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2053 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2054 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2055 extra->type = TRACING_REDUCE;
2056 extra->send_size = count;
2057 extra->datatype1 = encode_datatype(datatype);
2058 extra->root = root_traced;
2060 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2062 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2064 retval = MPI_SUCCESS;
2066 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2074 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2075 MPI_Datatype datatype, MPI_Op op){
2079 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2080 retval = MPI_ERR_ARG;
2082 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2089 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2090 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2096 if (comm == MPI_COMM_NULL) {
2097 retval = MPI_ERR_COMM;
2098 } else if (!is_datatype_valid(datatype)) {
2099 retval = MPI_ERR_TYPE;
2100 } else if (op == MPI_OP_NULL) {
2101 retval = MPI_ERR_OP;
2104 char* sendtmpbuf = (char*) sendbuf;
2105 if( sendbuf == MPI_IN_PLACE ) {
2106 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2107 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2110 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2111 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2112 extra->type = TRACING_ALLREDUCE;
2113 extra->send_size = count;
2114 extra->datatype1 = encode_datatype(datatype);
2116 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2118 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2120 if( sendbuf == MPI_IN_PLACE ) {
2121 xbt_free(sendtmpbuf);
2124 retval = MPI_SUCCESS;
2126 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2134 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2135 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2141 if (comm == MPI_COMM_NULL) {
2142 retval = MPI_ERR_COMM;
2143 } else if (!is_datatype_valid(datatype)) {
2144 retval = MPI_ERR_TYPE;
2145 } else if (op == MPI_OP_NULL) {
2146 retval = MPI_ERR_OP;
2149 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2150 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2151 extra->type = TRACING_SCAN;
2152 extra->send_size = count;
2153 extra->datatype1 = encode_datatype(datatype);
2155 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2157 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2158 retval = MPI_SUCCESS;
2160 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2168 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2169 MPI_Op op, MPI_Comm comm){
2174 if (comm == MPI_COMM_NULL) {
2175 retval = MPI_ERR_COMM;
2176 } else if (!is_datatype_valid(datatype)) {
2177 retval = MPI_ERR_TYPE;
2178 } else if (op == MPI_OP_NULL) {
2179 retval = MPI_ERR_OP;
2182 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2183 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2184 extra->type = TRACING_EXSCAN;
2185 extra->send_size = count;
2186 extra->datatype1 = encode_datatype(datatype);
2188 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2190 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2191 retval = MPI_SUCCESS;
2193 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2201 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2202 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2207 if (comm == MPI_COMM_NULL) {
2208 retval = MPI_ERR_COMM;
2209 } else if (!is_datatype_valid(datatype)) {
2210 retval = MPI_ERR_TYPE;
2211 } else if (op == MPI_OP_NULL) {
2212 retval = MPI_ERR_OP;
2213 } else if (recvcounts == NULL) {
2214 retval = MPI_ERR_ARG;
2217 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2219 int size = smpi_comm_size(comm);
2220 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2221 extra->type = TRACING_REDUCE_SCATTER;
2222 extra->send_size = 0;
2223 extra->recvcounts= xbt_malloc(size*sizeof(int));
2224 for(i=0; i< size; i++)//copy data to avoid bad free
2225 extra->recvcounts[i] = recvcounts[i];
2226 extra->num_processes = size;
2227 extra->datatype1 = encode_datatype(datatype);
2229 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2231 void* sendtmpbuf=sendbuf;
2232 if(sendbuf==MPI_IN_PLACE){
2236 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2237 datatype, op, comm);
2238 retval = MPI_SUCCESS;
2240 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2248 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2249 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2254 if (comm == MPI_COMM_NULL) {
2255 retval = MPI_ERR_COMM;
2256 } else if (!is_datatype_valid(datatype)) {
2257 retval = MPI_ERR_TYPE;
2258 } else if (op == MPI_OP_NULL) {
2259 retval = MPI_ERR_OP;
2260 } else if (recvcount < 0) {
2261 retval = MPI_ERR_ARG;
2263 int count=smpi_comm_size(comm);
2266 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2267 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2268 extra->type = TRACING_REDUCE_SCATTER;
2269 extra->send_size = 0;
2270 extra->recvcounts= xbt_malloc(count*sizeof(int));
2271 for(i=0; i< count; i++)//copy data to avoid bad free
2272 extra->recvcounts[i] = recvcount;
2273 extra->num_processes = count;
2274 extra->datatype1 = encode_datatype(datatype);
2276 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2278 int* recvcounts=(int*)xbt_malloc(count);
2279 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2280 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2281 datatype, op, comm);
2282 xbt_free(recvcounts);
2283 retval = MPI_SUCCESS;
2285 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2293 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2294 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2301 if (comm == MPI_COMM_NULL) {
2302 retval = MPI_ERR_COMM;
2303 } else if (sendtype == MPI_DATATYPE_NULL
2304 || recvtype == MPI_DATATYPE_NULL) {
2305 retval = MPI_ERR_TYPE;
2308 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2309 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2310 extra->type = TRACING_ALLTOALL;
2311 extra->send_size = sendcount;
2312 extra->recv_size = recvcount;
2313 extra->datatype1 = encode_datatype(sendtype);
2314 extra->datatype2 = encode_datatype(recvtype);
2316 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2318 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2320 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2328 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2329 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2330 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2336 if (comm == MPI_COMM_NULL) {
2337 retval = MPI_ERR_COMM;
2338 } else if (sendtype == MPI_DATATYPE_NULL
2339 || recvtype == MPI_DATATYPE_NULL) {
2340 retval = MPI_ERR_TYPE;
2341 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2342 || recvdisps == NULL) {
2343 retval = MPI_ERR_ARG;
2346 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2348 int size = smpi_comm_size(comm);
2349 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2350 extra->type = TRACING_ALLTOALLV;
2351 extra->send_size = 0;
2352 extra->recv_size = 0;
2353 extra->recvcounts= xbt_malloc(size*sizeof(int));
2354 extra->sendcounts= xbt_malloc(size*sizeof(int));
2356 for(i=0; i< size; i++){//copy data to avoid bad free
2357 extra->send_size += sendcounts[i];
2358 extra->recv_size += recvcounts[i];
2360 extra->sendcounts[i] = sendcounts[i];
2361 extra->recvcounts[i] = recvcounts[i];
2363 extra->num_processes = size;
2365 extra->datatype1 = encode_datatype(sendtype);
2366 extra->datatype2 = encode_datatype(recvtype);
2368 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2371 mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2372 recvbuf, recvcounts, recvdisps, recvtype,
2375 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2384 int PMPI_Get_processor_name(char *name, int *resultlen)
2386 int retval = MPI_SUCCESS;
2388 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2389 strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2390 strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2391 MPI_MAX_PROCESSOR_NAME - 1 );
2394 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2399 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2401 int retval = MPI_SUCCESS;
2404 if (status == NULL || count == NULL) {
2405 retval = MPI_ERR_ARG;
2406 } else if (!is_datatype_valid(datatype)) {
2407 retval = MPI_ERR_TYPE;
2409 size = smpi_datatype_size(datatype);
2412 } else if (status->count % size != 0) {
2413 retval = MPI_UNDEFINED;
2415 *count = smpi_mpi_get_count(status, datatype);
2421 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2424 if (old_type == MPI_DATATYPE_NULL) {
2425 retval = MPI_ERR_TYPE;
2426 } else if (count<0){
2427 retval = MPI_ERR_COUNT;
2429 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2434 int PMPI_Type_commit(MPI_Datatype* datatype) {
2437 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2438 retval = MPI_ERR_TYPE;
2440 smpi_datatype_commit(datatype);
2441 retval = MPI_SUCCESS;
2447 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2450 if (old_type == MPI_DATATYPE_NULL) {
2451 retval = MPI_ERR_TYPE;
2452 } else if (count<0 || blocklen<0){
2453 retval = MPI_ERR_COUNT;
2455 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2460 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2463 if (old_type == MPI_DATATYPE_NULL) {
2464 retval = MPI_ERR_TYPE;
2465 } else if (count<0 || blocklen<0){
2466 retval = MPI_ERR_COUNT;
2468 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2473 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2474 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2477 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2480 if (old_type == MPI_DATATYPE_NULL) {
2481 retval = MPI_ERR_TYPE;
2482 } else if (count<0){
2483 retval = MPI_ERR_COUNT;
2485 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2490 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2493 if (old_type == MPI_DATATYPE_NULL) {
2494 retval = MPI_ERR_TYPE;
2495 } else if (count<0){
2496 retval = MPI_ERR_COUNT;
2498 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2503 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2506 if (old_type == MPI_DATATYPE_NULL) {
2507 retval = MPI_ERR_TYPE;
2508 } else if (count<0){
2509 retval = MPI_ERR_COUNT;
2511 int* blocklens=(int*)xbt_malloc(blocklength*count);
2512 for (i=0; i<count;i++)blocklens[i]=blocklength;
2513 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2514 xbt_free(blocklens);
2520 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2523 if (old_type == MPI_DATATYPE_NULL) {
2524 retval = MPI_ERR_TYPE;
2525 } else if (count<0){
2526 retval = MPI_ERR_COUNT;
2528 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2533 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2534 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2537 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2540 if (old_type == MPI_DATATYPE_NULL) {
2541 retval = MPI_ERR_TYPE;
2542 } else if (count<0){
2543 retval = MPI_ERR_COUNT;
2545 int* blocklens=(int*)xbt_malloc(blocklength*count);
2546 for (i=0; i<count;i++)blocklens[i]=blocklength;
2547 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2548 xbt_free(blocklens);
2554 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2558 retval = MPI_ERR_COUNT;
2560 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2565 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2566 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2570 int PMPI_Error_class(int errorcode, int* errorclass) {
2571 // assume smpi uses only standard mpi error codes
2572 *errorclass=errorcode;
2577 int PMPI_Initialized(int* flag) {
2578 *flag=smpi_process_initialized();
2582 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2583 * will be implemented, not only should we check if the topology is NULL, but
2584 * we should check if it is the good topology type (so we have to add a
2585 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2587 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2590 if (comm_old == MPI_COMM_NULL){
2591 return MPI_ERR_COMM;
2593 else if (ndims < 0 ||
2594 (ndims > 0 && (dims == NULL ||
2595 periodic == NULL)) ||
2596 comm_cart == NULL) {
2599 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2606 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2607 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2608 return MPI_ERR_TOPOLOGY;
2610 if (coords == NULL) {
2613 return smpi_mpi_cart_rank(comm, coords, rank);
2616 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2617 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2618 return MPI_ERR_TOPOLOGY;
2620 if (source == NULL || dest == NULL || direction < 0 ) {
2623 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2626 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2627 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2628 return MPI_ERR_TOPOLOGY;
2630 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2631 return MPI_ERR_RANK;
2636 if(coords == NULL) {
2639 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2642 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2643 if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2644 return MPI_ERR_TOPOLOGY;
2646 if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2649 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2652 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2653 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2654 return MPI_ERR_TOPOLOGY;
2656 if (ndims == NULL) {
2659 return smpi_mpi_cartdim_get(comm, ndims);
2662 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2666 if (ndims < 1 || nnodes < 1) {
2667 return MPI_ERR_DIMS;
2670 return smpi_mpi_dims_create(nnodes, ndims, dims);
2673 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2674 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2675 return MPI_ERR_TOPOLOGY;
2677 if (comm_new == NULL) {
2680 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2684 /* The following calls are not yet implemented and will fail at runtime. */
2685 /* Once implemented, please move them above this notice. */
2687 #define NOT_YET_IMPLEMENTED { \
2688 XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
2689 return MPI_SUCCESS; \
2692 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2696 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
2700 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
2705 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
2710 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
2715 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
2720 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
2724 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
2728 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
2732 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
2736 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
2740 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
2744 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
2748 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
2752 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
2756 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
2760 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
2764 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
2768 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
2772 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
2776 int PMPI_Cancel(MPI_Request* request) {
2780 int PMPI_Buffer_attach(void* buffer, int size) {
2784 int PMPI_Buffer_detach(void* buffer, int* size) {
2788 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
2792 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
2797 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
2802 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
2807 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
2812 int PMPI_Comm_free_keyval(int* keyval) {
2816 int PMPI_Pcontrol(const int level )
2821 int PMPI_Unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
2825 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
2830 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
2835 int PMPI_Type_delete_attr (MPI_Datatype type, int comm_keyval)
2840 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
2845 int PMPI_Type_free_keyval(int* keyval) {
2849 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
2853 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
2857 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2861 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2865 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2869 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
2873 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
2877 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
2881 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
2885 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
2889 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
2893 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2897 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
2901 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
2905 int PMPI_Keyval_free(int* keyval) {
2909 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
2913 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
2917 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
2921 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
2925 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
2929 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
2933 int PMPI_Win_fence( int assert, MPI_Win win){
2937 int PMPI_Win_free( MPI_Win* win){
2941 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2945 int PMPI_Info_create( MPI_Info *info){
2949 int PMPI_Info_set( MPI_Info info, char *key, char *value){
2953 int PMPI_Info_free( MPI_Info *info){
2957 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2958 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2962 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
2963 int *num_addresses, int *num_datatypes, int *combiner){
2967 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
2968 int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
2969 MPI_Datatype* array_of_datatypes){
2973 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
2974 int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
2975 int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
2979 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){
2983 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
2987 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
2988 void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
2993 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
2997 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3001 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3005 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3009 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3013 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3017 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3021 int PMPI_Add_error_class( int *errorclass){
3025 int PMPI_Add_error_code( int errorclass, int *errorcode){
3029 int PMPI_Add_error_string( int errorcode, char *string){
3033 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3037 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3041 int PMPI_Info_delete(MPI_Info info, char *key){
3045 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3049 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3053 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3057 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3061 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){
3065 int PMPI_Grequest_complete( MPI_Request request){
3069 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3073 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3077 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3081 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3085 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3089 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3093 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3097 int PMPI_Open_port( MPI_Info info, char *port_name){
3101 int PMPI_Close_port(char *port_name){
3105 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3109 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){
3113 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3114 int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3115 MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3119 int PMPI_Comm_get_parent( MPI_Comm *parent){