2 /* Copyright (c) 2007-2014. The SimGrid Team.
3 * All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "smpi_mpi_dt_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi,
12 "Logging specific to SMPI (pmpi)");
15 //this function need to be here because of the calls to smpi_bench
16 void TRACE_smpi_set_category(const char *category)
18 //need to end bench otherwise categories for execution tasks are wrong
20 TRACE_internal_smpi_set_category (category);
21 //begin bench after changing process's category
26 /* PMPI User level calls */
28 int PMPI_Init(int *argc, char ***argv)
30 smpi_process_init(argc, argv);
31 smpi_process_mark_as_initialized();
33 int rank = smpi_process_index();
34 TRACE_smpi_init(rank);
35 TRACE_smpi_computing_init(rank);
36 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
37 extra->type = TRACING_INIT;
38 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
39 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
45 int PMPI_Finalize(void)
49 int rank = smpi_process_index();
50 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
51 extra->type = TRACING_FINALIZE;
52 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
54 smpi_process_finalize();
56 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
57 TRACE_smpi_finalize(smpi_process_index());
59 smpi_process_destroy();
63 int PMPI_Finalized(int* flag)
65 *flag=smpi_process_finalized();
69 int PMPI_Get_version (int *version,int *subversion){
70 *version = MPI_VERSION;
71 *subversion= MPI_SUBVERSION;
75 int PMPI_Get_library_version (char *version,int *len){
76 int retval = MPI_SUCCESS;
78 snprintf(version,MPI_MAX_LIBRARY_VERSION_STRING,"SMPI Version %d.%d. Copyright The Simgrid Team 2007-2014",SIMGRID_VERSION_MAJOR,
79 SIMGRID_VERSION_MINOR);
80 *len = strlen(version) > MPI_MAX_LIBRARY_VERSION_STRING ? MPI_MAX_LIBRARY_VERSION_STRING : strlen(version);
85 int PMPI_Init_thread(int *argc, char ***argv, int required, int *provided)
87 if (provided != NULL) {
88 *provided = MPI_THREAD_MULTIPLE;
90 return MPI_Init(argc, argv);
93 int PMPI_Query_thread(int *provided)
97 if (provided == NULL) {
100 *provided = MPI_THREAD_MULTIPLE;
101 retval = MPI_SUCCESS;
106 int PMPI_Is_thread_main(int *flag)
111 retval = MPI_ERR_ARG;
113 *flag = smpi_process_index() == 0;
114 retval = MPI_SUCCESS;
119 int PMPI_Abort(MPI_Comm comm, int errorcode)
122 smpi_process_destroy();
123 // FIXME: should kill all processes in comm instead
124 simcall_process_kill(SIMIX_process_self());
128 double PMPI_Wtime(void)
130 return smpi_mpi_wtime();
133 extern double sg_maxmin_precision;
134 double PMPI_Wtick(void)
136 return sg_maxmin_precision;
139 int PMPI_Address(void *location, MPI_Aint * address)
144 retval = MPI_ERR_ARG;
146 *address = (MPI_Aint) location;
147 retval = MPI_SUCCESS;
152 int PMPI_Get_address(void *location, MPI_Aint * address)
154 return PMPI_Address(location, address);
157 int PMPI_Type_free(MPI_Datatype * datatype)
160 /* Free a predefined datatype is an error according to the standard, and
161 should be checked for */
162 if (*datatype == MPI_DATATYPE_NULL) {
163 retval = MPI_ERR_ARG;
165 smpi_datatype_free(datatype);
166 retval = MPI_SUCCESS;
171 int PMPI_Type_size(MPI_Datatype datatype, int *size)
175 if (datatype == MPI_DATATYPE_NULL) {
176 retval = MPI_ERR_TYPE;
177 } else if (size == NULL) {
178 retval = MPI_ERR_ARG;
180 *size = (int) smpi_datatype_size(datatype);
181 retval = MPI_SUCCESS;
186 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
190 if (datatype == MPI_DATATYPE_NULL) {
191 retval = MPI_ERR_TYPE;
192 } else if (lb == NULL || extent == NULL) {
193 retval = MPI_ERR_ARG;
195 retval = smpi_datatype_extent(datatype, lb, extent);
200 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
202 return PMPI_Type_get_extent(datatype, lb, extent);
205 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
209 if (datatype == MPI_DATATYPE_NULL) {
210 retval = MPI_ERR_TYPE;
211 } else if (extent == NULL) {
212 retval = MPI_ERR_ARG;
214 *extent = smpi_datatype_get_extent(datatype);
215 retval = MPI_SUCCESS;
220 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
224 if (datatype == MPI_DATATYPE_NULL) {
225 retval = MPI_ERR_TYPE;
226 } else if (disp == NULL) {
227 retval = MPI_ERR_ARG;
229 *disp = smpi_datatype_lb(datatype);
230 retval = MPI_SUCCESS;
235 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
239 if (datatype == MPI_DATATYPE_NULL) {
240 retval = MPI_ERR_TYPE;
241 } else if (disp == NULL) {
242 retval = MPI_ERR_ARG;
244 *disp = smpi_datatype_ub(datatype);
245 retval = MPI_SUCCESS;
250 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
253 if (datatype == MPI_DATATYPE_NULL) {
254 retval = MPI_ERR_TYPE;
256 retval = smpi_datatype_dup(datatype, newtype);
261 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
265 if (function == NULL || op == NULL) {
266 retval = MPI_ERR_ARG;
268 *op = smpi_op_new(function, commute);
269 retval = MPI_SUCCESS;
274 int PMPI_Op_free(MPI_Op * op)
279 retval = MPI_ERR_ARG;
280 } else if (*op == MPI_OP_NULL) {
283 smpi_op_destroy(*op);
285 retval = MPI_SUCCESS;
290 int PMPI_Group_free(MPI_Group * group)
295 retval = MPI_ERR_ARG;
297 smpi_group_destroy(*group);
298 *group = MPI_GROUP_NULL;
299 retval = MPI_SUCCESS;
304 int PMPI_Group_size(MPI_Group group, int *size)
308 if (group == MPI_GROUP_NULL) {
309 retval = MPI_ERR_GROUP;
310 } else if (size == NULL) {
311 retval = MPI_ERR_ARG;
313 *size = smpi_group_size(group);
314 retval = MPI_SUCCESS;
319 int PMPI_Group_rank(MPI_Group group, int *rank)
323 if (group == MPI_GROUP_NULL) {
324 retval = MPI_ERR_GROUP;
325 } else if (rank == NULL) {
326 retval = MPI_ERR_ARG;
328 *rank = smpi_group_rank(group, smpi_process_index());
329 retval = MPI_SUCCESS;
334 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
335 MPI_Group group2, int *ranks2)
337 int retval, i, index;
338 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
339 retval = MPI_ERR_GROUP;
341 for (i = 0; i < n; i++) {
342 if(ranks1[i]==MPI_PROC_NULL){
343 ranks2[i]=MPI_PROC_NULL;
345 index = smpi_group_index(group1, ranks1[i]);
346 ranks2[i] = smpi_group_rank(group2, index);
349 retval = MPI_SUCCESS;
354 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
358 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
359 retval = MPI_ERR_GROUP;
360 } else if (result == NULL) {
361 retval = MPI_ERR_ARG;
363 *result = smpi_group_compare(group1, group2);
364 retval = MPI_SUCCESS;
369 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
370 MPI_Group * newgroup)
372 int retval, i, proc1, proc2, size, size2;
374 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
375 retval = MPI_ERR_GROUP;
376 } else if (newgroup == NULL) {
377 retval = MPI_ERR_ARG;
379 size = smpi_group_size(group1);
380 size2 = smpi_group_size(group2);
381 for (i = 0; i < size2; i++) {
382 proc2 = smpi_group_index(group2, i);
383 proc1 = smpi_group_rank(group1, proc2);
384 if (proc1 == MPI_UNDEFINED) {
389 *newgroup = MPI_GROUP_EMPTY;
391 *newgroup = smpi_group_new(size);
392 size2 = smpi_group_size(group1);
393 for (i = 0; i < size2; i++) {
394 proc1 = smpi_group_index(group1, i);
395 smpi_group_set_mapping(*newgroup, proc1, i);
397 for (i = size2; i < size; i++) {
398 proc2 = smpi_group_index(group2, i - size2);
399 smpi_group_set_mapping(*newgroup, proc2, i);
402 retval = MPI_SUCCESS;
407 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
408 MPI_Group * newgroup)
410 int retval, i, proc1, proc2, size;
412 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
413 retval = MPI_ERR_GROUP;
414 } else if (newgroup == NULL) {
415 retval = MPI_ERR_ARG;
417 size = smpi_group_size(group2);
418 for (i = 0; i < size; i++) {
419 proc2 = smpi_group_index(group2, i);
420 proc1 = smpi_group_rank(group1, proc2);
421 if (proc1 == MPI_UNDEFINED) {
426 *newgroup = MPI_GROUP_EMPTY;
428 *newgroup = smpi_group_new(size);
430 for (i = 0; i < smpi_group_size(group2); i++) {
431 proc2 = smpi_group_index(group2, i);
432 proc1 = smpi_group_rank(group1, proc2);
433 if (proc1 != MPI_UNDEFINED) {
434 smpi_group_set_mapping(*newgroup, proc2, j);
439 retval = MPI_SUCCESS;
444 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
446 int retval, i, proc1, proc2, size, size2;
448 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
449 retval = MPI_ERR_GROUP;
450 } else if (newgroup == NULL) {
451 retval = MPI_ERR_ARG;
453 size = size2 = smpi_group_size(group1);
454 for (i = 0; i < size2; i++) {
455 proc1 = smpi_group_index(group1, i);
456 proc2 = smpi_group_rank(group2, proc1);
457 if (proc2 != MPI_UNDEFINED) {
462 *newgroup = MPI_GROUP_EMPTY;
464 *newgroup = smpi_group_new(size);
465 for (i = 0; i < size2; i++) {
466 proc1 = smpi_group_index(group1, i);
467 proc2 = smpi_group_rank(group2, proc1);
468 if (proc2 == MPI_UNDEFINED) {
469 smpi_group_set_mapping(*newgroup, proc1, i);
473 retval = MPI_SUCCESS;
478 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
482 if (group == MPI_GROUP_NULL) {
483 retval = MPI_ERR_GROUP;
484 } else if (newgroup == NULL) {
485 retval = MPI_ERR_ARG;
487 retval = smpi_group_incl(group, n, ranks, newgroup);
492 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
494 int retval, i, j, newsize, oldsize, index;
496 if (group == MPI_GROUP_NULL) {
497 retval = MPI_ERR_GROUP;
498 } else if (newgroup == NULL) {
499 retval = MPI_ERR_ARG;
503 if(group!= smpi_comm_group(MPI_COMM_WORLD)
504 && group != MPI_GROUP_NULL
505 && group != smpi_comm_group(MPI_COMM_SELF)
506 && group != MPI_GROUP_EMPTY)
507 smpi_group_use(group);
508 } else if (n == smpi_group_size(group)) {
509 *newgroup = MPI_GROUP_EMPTY;
511 oldsize=smpi_group_size(group);
512 newsize = oldsize - n;
513 *newgroup = smpi_group_new(newsize);
515 int* to_exclude=xbt_new0(int, smpi_group_size(group));
516 for(i=0; i<oldsize; i++)
519 to_exclude[ranks[i]]=1;
522 for(i=0; i<oldsize; i++){
523 if(to_exclude[i]==0){
524 index = smpi_group_index(group, i);
525 smpi_group_set_mapping(*newgroup, index, j);
530 xbt_free(to_exclude);
532 retval = MPI_SUCCESS;
537 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
538 MPI_Group * newgroup)
540 int retval, i, j, rank, size, index;
542 if (group == MPI_GROUP_NULL) {
543 retval = MPI_ERR_GROUP;
544 } else if (newgroup == NULL) {
545 retval = MPI_ERR_ARG;
548 *newgroup = MPI_GROUP_EMPTY;
551 for (i = 0; i < n; i++) {
552 for (rank = ranges[i][0]; /* First */
553 rank >= 0 && rank < smpi_group_size(group); /* Last */
556 if(rank == ranges[i][1]){/*already last ?*/
559 rank += ranges[i][2]; /* Stride */
560 if (ranges[i][0]<ranges[i][1]){
561 if(rank > ranges[i][1])
564 if(rank < ranges[i][1])
570 *newgroup = smpi_group_new(size);
572 for (i = 0; i < n; i++) {
573 for (rank = ranges[i][0]; /* First */
574 rank >= 0 && rank < smpi_group_size(group); /* Last */
576 index = smpi_group_index(group, rank);
577 smpi_group_set_mapping(*newgroup, index, j);
579 if(rank == ranges[i][1]){/*already last ?*/
582 rank += ranges[i][2]; /* Stride */
583 if (ranges[i][0]<ranges[i][1]){
584 if(rank > ranges[i][1])
587 if(rank < ranges[i][1])
593 retval = MPI_SUCCESS;
598 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
599 MPI_Group * newgroup)
601 int retval, i, rank, newrank,oldrank, size, index, add;
603 if (group == MPI_GROUP_NULL) {
604 retval = MPI_ERR_GROUP;
605 } else if (newgroup == NULL) {
606 retval = MPI_ERR_ARG;
610 if(group!= smpi_comm_group(MPI_COMM_WORLD)
611 && group != MPI_GROUP_NULL
612 && group != smpi_comm_group(MPI_COMM_SELF)
613 && group != MPI_GROUP_EMPTY)
614 smpi_group_use(group);
616 size = smpi_group_size(group);
617 for (i = 0; i < n; i++) {
618 for (rank = ranges[i][0]; /* First */
619 rank >= 0 && rank < smpi_group_size(group); /* Last */
622 if(rank == ranges[i][1]){/*already last ?*/
625 rank += ranges[i][2]; /* Stride */
626 if (ranges[i][0]<ranges[i][1]){
627 if(rank > ranges[i][1])
630 if(rank < ranges[i][1])
636 *newgroup = MPI_GROUP_EMPTY;
638 *newgroup = smpi_group_new(size);
641 while (newrank < size) {
643 for (i = 0; i < n; i++) {
644 for (rank = ranges[i][0];
645 rank >= 0 && rank < smpi_group_size(group);
651 if(rank == ranges[i][1]){/*already last ?*/
654 rank += ranges[i][2]; /* Stride */
655 if (ranges[i][0]<ranges[i][1]){
656 if(rank > ranges[i][1])
659 if(rank < ranges[i][1])
665 index = smpi_group_index(group, oldrank);
666 smpi_group_set_mapping(*newgroup, index, newrank);
674 retval = MPI_SUCCESS;
679 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
682 if (comm == MPI_COMM_NULL) {
683 retval = MPI_ERR_COMM;
684 } else if (rank == NULL) {
685 retval = MPI_ERR_ARG;
687 *rank = smpi_comm_rank(comm);
688 retval = MPI_SUCCESS;
693 int PMPI_Comm_size(MPI_Comm comm, int *size)
696 if (comm == MPI_COMM_NULL) {
697 retval = MPI_ERR_COMM;
698 } else if (size == NULL) {
699 retval = MPI_ERR_ARG;
701 *size = smpi_comm_size(comm);
702 retval = MPI_SUCCESS;
707 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
711 if (comm == MPI_COMM_NULL) {
712 retval = MPI_ERR_COMM;
713 } else if (name == NULL || len == NULL) {
714 retval = MPI_ERR_ARG;
716 smpi_comm_get_name(comm, name, len);
717 retval = MPI_SUCCESS;
722 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
726 if (comm == MPI_COMM_NULL) {
727 retval = MPI_ERR_COMM;
728 } else if (group == NULL) {
729 retval = MPI_ERR_ARG;
731 *group = smpi_comm_group(comm);
732 if(*group!= smpi_comm_group(MPI_COMM_WORLD)
733 && *group != MPI_GROUP_NULL
734 && *group != smpi_comm_group(MPI_COMM_SELF)
735 && *group != MPI_GROUP_EMPTY)
736 smpi_group_use(*group);
737 retval = MPI_SUCCESS;
742 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
746 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
747 retval = MPI_ERR_COMM;
748 } else if (result == NULL) {
749 retval = MPI_ERR_ARG;
751 if (comm1 == comm2) { /* Same communicators means same groups */
755 smpi_group_compare(smpi_comm_group(comm1),
756 smpi_comm_group(comm2));
757 if (*result == MPI_IDENT) {
758 *result = MPI_CONGRUENT;
761 retval = MPI_SUCCESS;
766 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
770 if (comm == MPI_COMM_NULL) {
771 retval = MPI_ERR_COMM;
772 } else if (newcomm == NULL) {
773 retval = MPI_ERR_ARG;
775 retval = smpi_comm_dup(comm, newcomm);
780 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
784 if (comm == MPI_COMM_NULL) {
785 retval = MPI_ERR_COMM;
786 } else if (group == MPI_GROUP_NULL) {
787 retval = MPI_ERR_GROUP;
788 } else if (newcomm == NULL) {
789 retval = MPI_ERR_ARG;
790 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
791 *newcomm= MPI_COMM_NULL;
792 retval = MPI_SUCCESS;
795 *newcomm = smpi_comm_new(group, NULL);
796 retval = MPI_SUCCESS;
801 int PMPI_Comm_free(MPI_Comm * comm)
806 retval = MPI_ERR_ARG;
807 } else if (*comm == MPI_COMM_NULL) {
808 retval = MPI_ERR_COMM;
810 smpi_comm_destroy(*comm);
811 *comm = MPI_COMM_NULL;
812 retval = MPI_SUCCESS;
817 int PMPI_Comm_disconnect(MPI_Comm * comm)
819 /* TODO: wait until all communication in comm are done */
823 retval = MPI_ERR_ARG;
824 } else if (*comm == MPI_COMM_NULL) {
825 retval = MPI_ERR_COMM;
827 smpi_comm_destroy(*comm);
828 *comm = MPI_COMM_NULL;
829 retval = MPI_SUCCESS;
834 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
839 if (comm_out == NULL) {
840 retval = MPI_ERR_ARG;
841 } else if (comm == MPI_COMM_NULL) {
842 retval = MPI_ERR_COMM;
844 *comm_out = smpi_comm_split(comm, color, key);
845 retval = MPI_SUCCESS;
852 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
853 int tag, MPI_Comm comm, MPI_Request * request)
858 if (request == NULL) {
859 retval = MPI_ERR_ARG;
860 } else if (comm == MPI_COMM_NULL) {
861 retval = MPI_ERR_COMM;
862 } else if (!is_datatype_valid(datatype)) {
863 retval = MPI_ERR_TYPE;
864 } else if (dst == MPI_PROC_NULL) {
865 retval = MPI_SUCCESS;
867 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
868 retval = MPI_SUCCESS;
871 if (retval != MPI_SUCCESS && request)
872 *request = MPI_REQUEST_NULL;
876 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
877 int tag, MPI_Comm comm, MPI_Request * request)
882 if (request == NULL) {
883 retval = MPI_ERR_ARG;
884 } else if (comm == MPI_COMM_NULL) {
885 retval = MPI_ERR_COMM;
886 } else if (!is_datatype_valid(datatype)) {
887 retval = MPI_ERR_TYPE;
888 } else if (src == MPI_PROC_NULL) {
889 retval = MPI_SUCCESS;
891 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
892 retval = MPI_SUCCESS;
895 if (retval != MPI_SUCCESS && request)
896 *request = MPI_REQUEST_NULL;
900 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
901 int dst, int tag, MPI_Comm comm, MPI_Request* request)
906 if (request == NULL) {
907 retval = MPI_ERR_ARG;
908 } else if (comm == MPI_COMM_NULL) {
909 retval = MPI_ERR_COMM;
910 } else if (!is_datatype_valid(datatype)) {
911 retval = MPI_ERR_TYPE;
912 } else if (dst == MPI_PROC_NULL) {
913 retval = MPI_SUCCESS;
915 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
916 retval = MPI_SUCCESS;
919 if (retval != MPI_SUCCESS && request)
920 *request = MPI_REQUEST_NULL;
924 int PMPI_Start(MPI_Request * request)
929 if (request == NULL || *request == MPI_REQUEST_NULL) {
930 retval = MPI_ERR_REQUEST;
932 smpi_mpi_start(*request);
933 retval = MPI_SUCCESS;
939 int PMPI_Startall(int count, MPI_Request * requests)
944 if (requests == NULL) {
945 retval = MPI_ERR_ARG;
947 retval = MPI_SUCCESS;
948 for (i = 0 ; i < count ; i++) {
949 if(requests[i] == MPI_REQUEST_NULL) {
950 retval = MPI_ERR_REQUEST;
953 if(retval != MPI_ERR_REQUEST) {
954 smpi_mpi_startall(count, requests);
961 int PMPI_Request_free(MPI_Request * request)
966 if (*request == MPI_REQUEST_NULL) {
967 retval = MPI_ERR_ARG;
969 smpi_mpi_request_free(request);
970 retval = MPI_SUCCESS;
976 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
977 int tag, MPI_Comm comm, MPI_Request * request)
983 if (request == NULL) {
984 retval = MPI_ERR_ARG;
985 } else if (comm == MPI_COMM_NULL) {
986 retval = MPI_ERR_COMM;
987 } else if (src == MPI_PROC_NULL) {
988 *request = MPI_REQUEST_NULL;
989 retval = MPI_SUCCESS;
990 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
991 retval = MPI_ERR_RANK;
992 } else if (count < 0) {
993 retval = MPI_ERR_COUNT;
994 } else if (buf==NULL && count > 0) {
995 retval = MPI_ERR_COUNT;
996 } else if (!is_datatype_valid(datatype)) {
997 retval = MPI_ERR_TYPE;
998 } else if(tag<0 && tag != MPI_ANY_TAG){
999 retval = MPI_ERR_TAG;
1003 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1004 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1006 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1007 extra->type = TRACING_IRECV;
1008 extra->src = src_traced;
1011 extra->datatype1 = encode_datatype(datatype, &known);
1012 int dt_size_send = 1;
1014 dt_size_send = smpi_datatype_size(datatype);
1015 extra->send_size = count*dt_size_send;
1016 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1019 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1020 retval = MPI_SUCCESS;
1023 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1024 (*request)->recv = 1;
1029 if (retval != MPI_SUCCESS && request)
1030 *request = MPI_REQUEST_NULL;
1035 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1036 int tag, MPI_Comm comm, MPI_Request * request)
1041 if (request == NULL) {
1042 retval = MPI_ERR_ARG;
1043 } else if (comm == MPI_COMM_NULL) {
1044 retval = MPI_ERR_COMM;
1045 } else if (dst == MPI_PROC_NULL) {
1046 *request = MPI_REQUEST_NULL;
1047 retval = MPI_SUCCESS;
1048 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1049 retval = MPI_ERR_RANK;
1050 } else if (count < 0) {
1051 retval = MPI_ERR_COUNT;
1052 } else if (buf==NULL && count > 0) {
1053 retval = MPI_ERR_COUNT;
1054 } else if (!is_datatype_valid(datatype)) {
1055 retval = MPI_ERR_TYPE;
1056 } else if(tag<0 && tag != MPI_ANY_TAG){
1057 retval = MPI_ERR_TAG;
1061 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1062 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;
1066 extra->dst = dst_traced;
1068 extra->datatype1 = encode_datatype(datatype, &known);
1069 int dt_size_send = 1;
1071 dt_size_send = smpi_datatype_size(datatype);
1072 extra->send_size = count*dt_size_send;
1073 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1074 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1077 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1078 retval = MPI_SUCCESS;
1081 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1082 (*request)->send = 1;
1087 if (retval != MPI_SUCCESS && request)
1088 *request = MPI_REQUEST_NULL;
1092 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1093 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1098 if (request == NULL) {
1099 retval = MPI_ERR_ARG;
1100 } else if (comm == MPI_COMM_NULL) {
1101 retval = MPI_ERR_COMM;
1102 } else if (dst == MPI_PROC_NULL) {
1103 *request = MPI_REQUEST_NULL;
1104 retval = MPI_SUCCESS;
1105 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1106 retval = MPI_ERR_RANK;
1107 } else if (count < 0) {
1108 retval = MPI_ERR_COUNT;
1109 } else if (buf==NULL && count > 0) {
1110 retval = MPI_ERR_COUNT;
1111 } else if (!is_datatype_valid(datatype)) {
1112 retval = MPI_ERR_TYPE;
1113 } else if(tag<0 && tag != MPI_ANY_TAG){
1114 retval = MPI_ERR_TAG;
1118 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1119 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1120 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1121 extra->type = TRACING_ISSEND;
1123 extra->dst = dst_traced;
1125 extra->datatype1 = encode_datatype(datatype, &known);
1126 int dt_size_send = 1;
1128 dt_size_send = smpi_datatype_size(datatype);
1129 extra->send_size = count*dt_size_send;
1130 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1131 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1134 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1135 retval = MPI_SUCCESS;
1138 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1139 (*request)->send = 1;
1144 if (retval != MPI_SUCCESS && request)
1145 *request = MPI_REQUEST_NULL;
1149 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1150 MPI_Comm comm, MPI_Status * status)
1155 if (comm == MPI_COMM_NULL) {
1156 retval = MPI_ERR_COMM;
1157 } else if (src == MPI_PROC_NULL) {
1158 smpi_empty_status(status);
1159 status->MPI_SOURCE = MPI_PROC_NULL;
1160 retval = MPI_SUCCESS;
1161 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1162 retval = MPI_ERR_RANK;
1163 } else if (count < 0) {
1164 retval = MPI_ERR_COUNT;
1165 } else if (buf==NULL && count > 0) {
1166 retval = MPI_ERR_COUNT;
1167 } else if (!is_datatype_valid(datatype)) {
1168 retval = MPI_ERR_TYPE;
1169 } else if(tag<0 && tag != MPI_ANY_TAG){
1170 retval = MPI_ERR_TAG;
1173 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1174 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1175 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1176 extra->type = TRACING_RECV;
1177 extra->src = src_traced;
1180 extra->datatype1 = encode_datatype(datatype, &known);
1181 int dt_size_send = 1;
1183 dt_size_send = smpi_datatype_size(datatype);
1184 extra->send_size = count*dt_size_send;
1185 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1188 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1189 retval = MPI_SUCCESS;
1192 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1193 if(status!=MPI_STATUS_IGNORE){
1194 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1195 TRACE_smpi_recv(rank, src_traced, rank);
1197 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1205 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1212 if (comm == MPI_COMM_NULL) {
1213 retval = MPI_ERR_COMM;
1214 } else if (dst == MPI_PROC_NULL) {
1215 retval = MPI_SUCCESS;
1216 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1217 retval = MPI_ERR_RANK;
1218 } else if (count < 0) {
1219 retval = MPI_ERR_COUNT;
1220 } else if (buf==NULL && count > 0) {
1221 retval = MPI_ERR_COUNT;
1222 } else if (!is_datatype_valid(datatype)) {
1223 retval = MPI_ERR_TYPE;
1224 } else if(tag<0 && tag != MPI_ANY_TAG){
1225 retval = MPI_ERR_TAG;
1229 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1230 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1231 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1232 extra->type = TRACING_SEND;
1234 extra->dst = dst_traced;
1236 extra->datatype1 = encode_datatype(datatype, &known);
1237 int dt_size_send = 1;
1239 dt_size_send = smpi_datatype_size(datatype);
1240 extra->send_size = count*dt_size_send;
1241 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1242 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1245 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1246 retval = MPI_SUCCESS;
1249 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1259 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1264 if (comm == MPI_COMM_NULL) {
1265 retval = MPI_ERR_COMM;
1266 } else if (dst == MPI_PROC_NULL) {
1267 retval = MPI_SUCCESS;
1268 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1269 retval = MPI_ERR_RANK;
1270 } else if (count < 0) {
1271 retval = MPI_ERR_COUNT;
1272 } else if (buf==NULL && count > 0) {
1273 retval = MPI_ERR_COUNT;
1274 } else if (!is_datatype_valid(datatype)){
1275 retval = MPI_ERR_TYPE;
1276 } else if(tag<0 && tag != MPI_ANY_TAG){
1277 retval = MPI_ERR_TAG;
1281 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1282 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1283 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1284 extra->type = TRACING_SSEND;
1286 extra->dst = dst_traced;
1288 extra->datatype1 = encode_datatype(datatype, &known);
1289 int dt_size_send = 1;
1291 dt_size_send = smpi_datatype_size(datatype);
1292 extra->send_size = count*dt_size_send;
1293 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra); TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1296 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1297 retval = MPI_SUCCESS;
1300 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1308 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1309 int dst, int sendtag, void *recvbuf, int recvcount,
1310 MPI_Datatype recvtype, int src, int recvtag,
1311 MPI_Comm comm, MPI_Status * status)
1317 if (comm == MPI_COMM_NULL) {
1318 retval = MPI_ERR_COMM;
1319 } else if (!is_datatype_valid(sendtype)
1320 || !is_datatype_valid(recvtype)) {
1321 retval = MPI_ERR_TYPE;
1322 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1323 smpi_empty_status(status);
1324 status->MPI_SOURCE = MPI_PROC_NULL;
1325 retval = MPI_SUCCESS;
1326 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1327 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1328 retval = MPI_ERR_RANK;
1329 } else if (sendcount < 0 || recvcount<0) {
1330 retval = MPI_ERR_COUNT;
1331 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1332 retval = MPI_ERR_COUNT;
1333 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1334 retval = MPI_ERR_TAG;
1338 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1339 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1340 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1341 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1342 extra->type = TRACING_SENDRECV;
1343 extra->src = src_traced;
1344 extra->dst = dst_traced;
1346 extra->datatype1 = encode_datatype(sendtype, &known);
1347 int dt_size_send = 1;
1349 dt_size_send = smpi_datatype_size(sendtype);
1350 extra->send_size = sendcount*dt_size_send;
1351 extra->datatype2 = encode_datatype(recvtype, &known);
1352 int dt_size_recv = 1;
1354 dt_size_recv = smpi_datatype_size(recvtype);
1355 extra->recv_size = recvcount*dt_size_recv;
1357 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1358 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1362 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1363 recvcount, recvtype, src, recvtag, comm, status);
1364 retval = MPI_SUCCESS;
1367 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1368 TRACE_smpi_recv(rank, src_traced, rank);
1377 int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
1378 int dst, int sendtag, int src, int recvtag,
1379 MPI_Comm comm, MPI_Status * status)
1381 //TODO: suboptimal implementation
1384 if (!is_datatype_valid(datatype)) {
1385 retval = MPI_ERR_TYPE;
1386 } else if (count < 0) {
1387 retval = MPI_ERR_COUNT;
1389 int size = smpi_datatype_get_extent(datatype) * count;
1390 recvbuf = xbt_new0(char, size);
1392 MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
1393 datatype, src, recvtag, comm, status);
1394 if(retval==MPI_SUCCESS){
1395 smpi_datatype_copy(recvbuf, count, datatype, buf, count, datatype);
1403 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
1407 if (request == NULL || flag == NULL) {
1408 retval = MPI_ERR_ARG;
1409 } else if (*request == MPI_REQUEST_NULL) {
1411 smpi_empty_status(status);
1412 retval = MPI_SUCCESS;
1415 int rank = request && (*request)->comm != MPI_COMM_NULL
1416 ? smpi_process_index()
1419 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1420 extra->type = TRACING_TEST;
1421 TRACE_smpi_testing_in(rank, extra);
1423 *flag = smpi_mpi_test(request, status);
1425 TRACE_smpi_testing_out(rank);
1427 retval = MPI_SUCCESS;
1433 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1434 MPI_Status * status)
1439 if (index == NULL || flag == NULL) {
1440 retval = MPI_ERR_ARG;
1442 *flag = smpi_mpi_testany(count, requests, index, status);
1443 retval = MPI_SUCCESS;
1449 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1455 retval = MPI_ERR_ARG;
1457 *flag = smpi_mpi_testall(count, requests, statuses);
1458 retval = MPI_SUCCESS;
1464 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1468 if (status == NULL) {
1469 retval = MPI_ERR_ARG;
1470 } else if (comm == MPI_COMM_NULL) {
1471 retval = MPI_ERR_COMM;
1472 } else if (source == MPI_PROC_NULL) {
1473 smpi_empty_status(status);
1474 status->MPI_SOURCE = MPI_PROC_NULL;
1475 retval = MPI_SUCCESS;
1477 smpi_mpi_probe(source, tag, comm, status);
1478 retval = MPI_SUCCESS;
1485 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1490 retval = MPI_ERR_ARG;
1491 } else if (status == NULL) {
1492 retval = MPI_ERR_ARG;
1493 } else if (comm == MPI_COMM_NULL) {
1494 retval = MPI_ERR_COMM;
1495 } else if (source == MPI_PROC_NULL) {
1497 smpi_empty_status(status);
1498 status->MPI_SOURCE = MPI_PROC_NULL;
1499 retval = MPI_SUCCESS;
1501 smpi_mpi_iprobe(source, tag, comm, flag, status);
1502 retval = MPI_SUCCESS;
1508 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1514 smpi_empty_status(status);
1516 if (request == NULL) {
1517 retval = MPI_ERR_ARG;
1518 } else if (*request == MPI_REQUEST_NULL) {
1519 retval = MPI_SUCCESS;
1523 int rank = request && (*request)->comm != MPI_COMM_NULL
1524 ? smpi_process_index()
1527 int src_traced = (*request)->src;
1528 int dst_traced = (*request)->dst;
1529 MPI_Comm comm = (*request)->comm;
1530 int is_wait_for_receive = (*request)->recv;
1531 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1532 extra->type = TRACING_WAIT;
1533 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1536 smpi_mpi_wait(request, status);
1537 retval = MPI_SUCCESS;
1540 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1541 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1542 if (is_wait_for_receive) {
1543 if(src_traced==MPI_ANY_SOURCE)
1544 src_traced = (status!=MPI_STATUS_IGNORE) ?
1545 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1547 TRACE_smpi_recv(rank, src_traced, dst_traced);
1557 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1564 //save requests information for tracing
1566 int *srcs = xbt_new0(int, count);
1567 int *dsts = xbt_new0(int, count);
1568 int *recvs = xbt_new0(int, count);
1569 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1571 for (i = 0; i < count; i++) {
1572 MPI_Request req = requests[i]; //already received requests are no longer valid
1576 recvs[i] = req->recv;
1577 comms[i] = req->comm;
1580 int rank_traced = smpi_process_index();
1581 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1582 extra->type = TRACING_WAITANY;
1583 extra->send_size=count;
1584 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1587 *index = smpi_mpi_waitany(count, requests, status);
1589 if(*index!=MPI_UNDEFINED){
1590 int src_traced = srcs[*index];
1591 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1592 int dst_traced = dsts[*index];
1593 int is_wait_for_receive = recvs[*index];
1594 if (is_wait_for_receive) {
1595 if(srcs[*index]==MPI_ANY_SOURCE)
1596 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1597 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1599 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1601 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1613 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1618 //save information from requests
1620 int *srcs = xbt_new0(int, count);
1621 int *dsts = xbt_new0(int, count);
1622 int *recvs = xbt_new0(int, count);
1623 int *valid = xbt_new0(int, count);
1624 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1626 //int valid_count = 0;
1627 for (i = 0; i < count; i++) {
1628 MPI_Request req = requests[i];
1629 if(req!=MPI_REQUEST_NULL){
1632 recvs[i] = req->recv;
1633 comms[i] = req->comm;
1639 int rank_traced = smpi_process_index();
1640 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1641 extra->type = TRACING_WAITALL;
1642 extra->send_size=count;
1643 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1645 int retval = smpi_mpi_waitall(count, requests, status);
1647 for (i = 0; i < count; i++) {
1649 //int src_traced = srcs[*index];
1650 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1651 int src_traced = srcs[i];
1652 int dst_traced = dsts[i];
1653 int is_wait_for_receive = recvs[i];
1654 if (is_wait_for_receive) {
1655 if(src_traced==MPI_ANY_SOURCE)
1656 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1657 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1659 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1663 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1675 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1676 int *indices, MPI_Status status[])
1681 if (outcount == NULL) {
1682 retval = MPI_ERR_ARG;
1684 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1685 retval = MPI_SUCCESS;
1691 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1692 int* indices, MPI_Status status[])
1697 if (outcount == NULL) {
1698 retval = MPI_ERR_ARG;
1700 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1701 retval = MPI_SUCCESS;
1708 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1714 if (comm == MPI_COMM_NULL) {
1715 retval = MPI_ERR_COMM;
1716 } else if (!is_datatype_valid(datatype)) {
1717 retval = MPI_ERR_ARG;
1720 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1721 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1723 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1724 extra->type = TRACING_BCAST;
1725 extra->root = root_traced;
1727 extra->datatype1 = encode_datatype(datatype, &known);
1728 int dt_size_send = 1;
1730 dt_size_send = smpi_datatype_size(datatype);
1731 extra->send_size = count*dt_size_send;
1732 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1735 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1736 retval = MPI_SUCCESS;
1738 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1746 int PMPI_Barrier(MPI_Comm comm)
1752 if (comm == MPI_COMM_NULL) {
1753 retval = MPI_ERR_COMM;
1756 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1757 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1758 extra->type = TRACING_BARRIER;
1759 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1761 mpi_coll_barrier_fun(comm);
1762 retval = MPI_SUCCESS;
1764 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1772 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1773 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1774 int root, MPI_Comm comm)
1780 if (comm == MPI_COMM_NULL) {
1781 retval = MPI_ERR_COMM;
1782 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1783 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1784 retval = MPI_ERR_TYPE;
1785 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1786 ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1787 retval = MPI_ERR_COUNT;
1790 char* sendtmpbuf = (char*) sendbuf;
1791 int sendtmpcount = sendcount;
1792 MPI_Datatype sendtmptype = sendtype;
1793 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1795 sendtmptype=recvtype;
1798 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1799 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1800 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1801 extra->type = TRACING_GATHER;
1802 extra->root = root_traced;
1804 extra->datatype1 = encode_datatype(sendtmptype, &known);
1805 int dt_size_send = 1;
1807 dt_size_send = smpi_datatype_size(sendtmptype);
1808 extra->send_size = sendtmpcount*dt_size_send;
1809 extra->datatype2 = encode_datatype(recvtype, &known);
1810 int dt_size_recv = 1;
1811 if((smpi_comm_rank(comm)==root) && !known)
1812 dt_size_recv = smpi_datatype_size(recvtype);
1813 extra->recv_size = recvcount*dt_size_recv;
1815 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1817 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1818 recvtype, root, comm);
1821 retval = MPI_SUCCESS;
1823 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1831 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1832 void *recvbuf, int *recvcounts, int *displs,
1833 MPI_Datatype recvtype, int root, MPI_Comm comm)
1839 if (comm == MPI_COMM_NULL) {
1840 retval = MPI_ERR_COMM;
1841 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1842 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1843 retval = MPI_ERR_TYPE;
1844 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1845 retval = MPI_ERR_COUNT;
1846 } else if (recvcounts == NULL || displs == NULL) {
1847 retval = MPI_ERR_ARG;
1849 char* sendtmpbuf = (char*) sendbuf;
1850 int sendtmpcount = sendcount;
1851 MPI_Datatype sendtmptype = sendtype;
1852 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1854 sendtmptype=recvtype;
1858 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1859 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1861 int size = smpi_comm_size(comm);
1862 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1863 extra->type = TRACING_GATHERV;
1864 extra->num_processes = size;
1865 extra->root = root_traced;
1867 extra->datatype1 = encode_datatype(sendtmptype, &known);
1868 int dt_size_send = 1;
1870 dt_size_send = smpi_datatype_size(sendtype);
1871 extra->send_size = sendtmpcount*dt_size_send;
1872 extra->datatype2 = encode_datatype(recvtype, &known);
1873 int dt_size_recv = 1;
1875 dt_size_recv = smpi_datatype_size(recvtype);
1876 extra->recvcounts= xbt_malloc(size*sizeof(int));
1877 for(i=0; i< size; i++)//copy data to avoid bad free
1878 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1880 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1882 smpi_mpi_gatherv(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcounts,
1883 displs, recvtype, root, comm);
1884 retval = MPI_SUCCESS;
1886 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1894 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1895 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1902 if (comm == MPI_COMM_NULL) {
1903 retval = MPI_ERR_COMM;
1904 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1905 (recvtype == MPI_DATATYPE_NULL)){
1906 retval = MPI_ERR_TYPE;
1907 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1909 retval = MPI_ERR_COUNT;
1911 if(sendbuf == MPI_IN_PLACE) {
1912 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1913 sendcount=recvcount;
1917 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1918 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1919 extra->type = TRACING_ALLGATHER;
1921 extra->datatype1 = encode_datatype(sendtype, &known);
1922 int dt_size_send = 1;
1924 dt_size_send = smpi_datatype_size(sendtype);
1925 extra->send_size = sendcount*dt_size_send;
1926 extra->datatype2 = encode_datatype(recvtype, &known);
1927 int dt_size_recv = 1;
1929 dt_size_recv = smpi_datatype_size(recvtype);
1930 extra->recv_size = recvcount*dt_size_recv;
1932 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1934 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1936 retval = MPI_SUCCESS;
1939 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1946 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1947 void *recvbuf, int *recvcounts, int *displs,
1948 MPI_Datatype recvtype, MPI_Comm comm)
1954 if (comm == MPI_COMM_NULL) {
1955 retval = MPI_ERR_COMM;
1956 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1957 (recvtype == MPI_DATATYPE_NULL)){
1958 retval = MPI_ERR_TYPE;
1959 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1960 retval = MPI_ERR_COUNT;
1961 } else if (recvcounts == NULL || displs == NULL) {
1962 retval = MPI_ERR_ARG;
1965 if(sendbuf == MPI_IN_PLACE) {
1966 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1967 sendcount=recvcounts[smpi_comm_rank(comm)];
1971 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1973 int size = smpi_comm_size(comm);
1974 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1975 extra->type = TRACING_ALLGATHERV;
1976 extra->num_processes = size;
1978 extra->datatype1 = encode_datatype(sendtype, &known);
1979 int dt_size_send = 1;
1981 dt_size_send = smpi_datatype_size(sendtype);
1982 extra->send_size = sendcount*dt_size_send;
1983 extra->datatype2 = encode_datatype(recvtype, &known);
1984 int dt_size_recv = 1;
1986 dt_size_recv = smpi_datatype_size(recvtype);
1987 extra->recvcounts= xbt_malloc(size*sizeof(int));
1988 for(i=0; i< size; i++)//copy data to avoid bad free
1989 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1991 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1993 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1994 displs, recvtype, comm);
1995 retval = MPI_SUCCESS;
1997 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2005 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2006 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2007 int root, MPI_Comm comm)
2013 if (comm == MPI_COMM_NULL) {
2014 retval = MPI_ERR_COMM;
2015 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
2016 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
2017 retval = MPI_ERR_TYPE;
2018 } else if ((sendbuf == recvbuf) ||
2019 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
2020 retval = MPI_ERR_BUFFER;
2023 if (recvbuf == MPI_IN_PLACE) {
2025 recvcount=sendcount;
2028 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2029 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2030 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2031 extra->type = TRACING_SCATTER;
2032 extra->root = root_traced;
2034 extra->datatype1 = encode_datatype(sendtype, &known);
2035 int dt_size_send = 1;
2036 if((smpi_comm_rank(comm)==root) && !known)
2037 dt_size_send = smpi_datatype_size(sendtype);
2038 extra->send_size = sendcount*dt_size_send;
2039 extra->datatype2 = encode_datatype(recvtype, &known);
2040 int dt_size_recv = 1;
2042 dt_size_recv = smpi_datatype_size(recvtype);
2043 extra->recv_size = recvcount*dt_size_recv;
2044 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2046 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
2047 recvtype, root, comm);
2048 retval = MPI_SUCCESS;
2050 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2058 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
2059 MPI_Datatype sendtype, void *recvbuf, int recvcount,
2060 MPI_Datatype recvtype, int root, MPI_Comm comm)
2066 if (comm == MPI_COMM_NULL) {
2067 retval = MPI_ERR_COMM;
2068 } else if (sendcounts == NULL || displs == NULL) {
2069 retval = MPI_ERR_ARG;
2070 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2071 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2072 retval = MPI_ERR_TYPE;
2074 if (recvbuf == MPI_IN_PLACE) {
2076 recvcount=sendcounts[smpi_comm_rank(comm)];
2079 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2080 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2082 int size = smpi_comm_size(comm);
2083 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2084 extra->type = TRACING_SCATTERV;
2085 extra->num_processes = size;
2086 extra->root = root_traced;
2088 extra->datatype1 = encode_datatype(sendtype, &known);
2089 int dt_size_send = 1;
2091 dt_size_send = smpi_datatype_size(sendtype);
2092 extra->sendcounts= xbt_malloc(size*sizeof(int));
2093 for(i=0; i< size; i++)//copy data to avoid bad free
2094 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2095 extra->datatype2 = encode_datatype(recvtype, &known);
2096 int dt_size_recv = 1;
2098 dt_size_recv = smpi_datatype_size(recvtype);
2099 extra->recv_size = recvcount*dt_size_recv;
2100 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2103 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2104 recvcount, recvtype, root, comm);
2105 retval = MPI_SUCCESS;
2107 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2115 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2116 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2122 if (comm == MPI_COMM_NULL) {
2123 retval = MPI_ERR_COMM;
2124 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2125 retval = MPI_ERR_ARG;
2128 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2129 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2130 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2131 extra->type = TRACING_REDUCE;
2133 extra->datatype1 = encode_datatype(datatype, &known);
2134 int dt_size_send = 1;
2136 dt_size_send = smpi_datatype_size(datatype);
2137 extra->send_size = count*dt_size_send;
2138 extra->root = root_traced;
2140 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2142 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2144 retval = MPI_SUCCESS;
2146 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2154 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2155 MPI_Datatype datatype, MPI_Op op){
2159 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2160 retval = MPI_ERR_ARG;
2162 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2169 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2170 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2176 if (comm == MPI_COMM_NULL) {
2177 retval = MPI_ERR_COMM;
2178 } else if (!is_datatype_valid(datatype)) {
2179 retval = MPI_ERR_TYPE;
2180 } else if (op == MPI_OP_NULL) {
2181 retval = MPI_ERR_OP;
2184 char* sendtmpbuf = (char*) sendbuf;
2185 if( sendbuf == MPI_IN_PLACE ) {
2186 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2187 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
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_ALLREDUCE;
2194 extra->datatype1 = encode_datatype(datatype, &known);
2195 int dt_size_send = 1;
2197 dt_size_send = smpi_datatype_size(datatype);
2198 extra->send_size = count*dt_size_send;
2200 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2202 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2204 if( sendbuf == MPI_IN_PLACE ) {
2205 xbt_free(sendtmpbuf);
2208 retval = MPI_SUCCESS;
2210 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2218 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2219 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2225 if (comm == MPI_COMM_NULL) {
2226 retval = MPI_ERR_COMM;
2227 } else if (!is_datatype_valid(datatype)) {
2228 retval = MPI_ERR_TYPE;
2229 } else if (op == MPI_OP_NULL) {
2230 retval = MPI_ERR_OP;
2233 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2234 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2235 extra->type = TRACING_SCAN;
2237 extra->datatype1 = encode_datatype(datatype, &known);
2238 int dt_size_send = 1;
2240 dt_size_send = smpi_datatype_size(datatype);
2241 extra->send_size = count*dt_size_send;
2243 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2245 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2246 retval = MPI_SUCCESS;
2248 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2256 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2257 MPI_Op op, MPI_Comm comm){
2262 if (comm == MPI_COMM_NULL) {
2263 retval = MPI_ERR_COMM;
2264 } else if (!is_datatype_valid(datatype)) {
2265 retval = MPI_ERR_TYPE;
2266 } else if (op == MPI_OP_NULL) {
2267 retval = MPI_ERR_OP;
2270 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2271 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2272 extra->type = TRACING_EXSCAN;
2274 extra->datatype1 = encode_datatype(datatype, &known);
2275 int dt_size_send = 1;
2277 dt_size_send = smpi_datatype_size(datatype);
2278 extra->send_size = count*dt_size_send;
2279 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2281 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2282 retval = MPI_SUCCESS;
2284 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2292 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2293 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2298 if (comm == MPI_COMM_NULL) {
2299 retval = MPI_ERR_COMM;
2300 } else if (!is_datatype_valid(datatype)) {
2301 retval = MPI_ERR_TYPE;
2302 } else if (op == MPI_OP_NULL) {
2303 retval = MPI_ERR_OP;
2304 } else if (recvcounts == NULL) {
2305 retval = MPI_ERR_ARG;
2308 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2310 int size = smpi_comm_size(comm);
2311 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2312 extra->type = TRACING_REDUCE_SCATTER;
2313 extra->num_processes = size;
2315 extra->datatype1 = encode_datatype(datatype, &known);
2316 int dt_size_send = 1;
2318 dt_size_send = smpi_datatype_size(datatype);
2319 extra->send_size = 0;
2320 extra->recvcounts= xbt_malloc(size*sizeof(int));
2321 for(i=0; i< size; i++)//copy data to avoid bad free
2322 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2323 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2325 void* sendtmpbuf=sendbuf;
2326 if(sendbuf==MPI_IN_PLACE){
2330 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2331 datatype, op, comm);
2332 retval = MPI_SUCCESS;
2334 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2342 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2343 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2348 if (comm == MPI_COMM_NULL) {
2349 retval = MPI_ERR_COMM;
2350 } else if (!is_datatype_valid(datatype)) {
2351 retval = MPI_ERR_TYPE;
2352 } else if (op == MPI_OP_NULL) {
2353 retval = MPI_ERR_OP;
2354 } else if (recvcount < 0) {
2355 retval = MPI_ERR_ARG;
2357 int count=smpi_comm_size(comm);
2360 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2361 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2362 extra->type = TRACING_REDUCE_SCATTER;
2363 extra->num_processes = count;
2365 extra->datatype1 = encode_datatype(datatype, &known);
2366 int dt_size_send = 1;
2368 dt_size_send = smpi_datatype_size(datatype);
2369 extra->send_size = 0;
2370 extra->recvcounts= xbt_malloc(count*sizeof(int));
2371 for(i=0; i< count; i++)//copy data to avoid bad free
2372 extra->recvcounts[i] = recvcount*dt_size_send;
2374 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2376 int* recvcounts=(int*)xbt_malloc(count);
2377 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2378 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2379 datatype, op, comm);
2380 xbt_free(recvcounts);
2381 retval = MPI_SUCCESS;
2383 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2391 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2392 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2399 if (comm == MPI_COMM_NULL) {
2400 retval = MPI_ERR_COMM;
2401 } else if (sendtype == MPI_DATATYPE_NULL
2402 || recvtype == MPI_DATATYPE_NULL) {
2403 retval = MPI_ERR_TYPE;
2406 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2407 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2408 extra->type = TRACING_ALLTOALL;
2410 extra->datatype1 = encode_datatype(sendtype, &known);
2412 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2414 extra->send_size = sendcount;
2415 extra->datatype2 = encode_datatype(recvtype, &known);
2417 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2419 extra->recv_size = recvcount;
2420 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2422 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2424 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2432 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2433 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2434 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2440 if (comm == MPI_COMM_NULL) {
2441 retval = MPI_ERR_COMM;
2442 } else if (sendtype == MPI_DATATYPE_NULL
2443 || recvtype == MPI_DATATYPE_NULL) {
2444 retval = MPI_ERR_TYPE;
2445 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2446 || recvdisps == NULL) {
2447 retval = MPI_ERR_ARG;
2450 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2452 int size = smpi_comm_size(comm);
2453 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2454 extra->type = TRACING_ALLTOALLV;
2455 extra->send_size = 0;
2456 extra->recv_size = 0;
2457 extra->recvcounts= xbt_malloc(size*sizeof(int));
2458 extra->sendcounts= xbt_malloc(size*sizeof(int));
2460 extra->datatype1 = encode_datatype(sendtype, &known);
2461 int dt_size_send = 1;
2463 dt_size_send = smpi_datatype_size(sendtype);
2464 int dt_size_recv = 1;
2465 extra->datatype2 = encode_datatype(recvtype, &known);
2467 dt_size_recv = smpi_datatype_size(recvtype);
2468 for(i=0; i< size; i++){//copy data to avoid bad free
2469 extra->send_size += sendcounts[i]*dt_size_send;
2470 extra->recv_size += recvcounts[i]*dt_size_recv;
2472 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2473 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2475 extra->num_processes = size;
2476 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2479 mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2480 recvbuf, recvcounts, recvdisps, recvtype,
2483 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2492 int PMPI_Get_processor_name(char *name, int *resultlen)
2494 int retval = MPI_SUCCESS;
2496 strncpy(name, SIMIX_host_get_name(SIMIX_host_self()),
2497 strlen(SIMIX_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2498 strlen(SIMIX_host_get_name(SIMIX_host_self())) +1 :
2499 MPI_MAX_PROCESSOR_NAME - 1 );
2502 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2507 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2509 int retval = MPI_SUCCESS;
2512 if (status == NULL || count == NULL) {
2513 retval = MPI_ERR_ARG;
2514 } else if (!is_datatype_valid(datatype)) {
2515 retval = MPI_ERR_TYPE;
2517 size = smpi_datatype_size(datatype);
2520 } else if (status->count % size != 0) {
2521 retval = MPI_UNDEFINED;
2523 *count = smpi_mpi_get_count(status, datatype);
2529 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2532 if (old_type == MPI_DATATYPE_NULL) {
2533 retval = MPI_ERR_TYPE;
2534 } else if (count<0){
2535 retval = MPI_ERR_COUNT;
2537 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2542 int PMPI_Type_commit(MPI_Datatype* datatype) {
2545 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2546 retval = MPI_ERR_TYPE;
2548 smpi_datatype_commit(datatype);
2549 retval = MPI_SUCCESS;
2555 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2558 if (old_type == MPI_DATATYPE_NULL) {
2559 retval = MPI_ERR_TYPE;
2560 } else if (count<0 || blocklen<0){
2561 retval = MPI_ERR_COUNT;
2563 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2568 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2571 if (old_type == MPI_DATATYPE_NULL) {
2572 retval = MPI_ERR_TYPE;
2573 } else if (count<0 || blocklen<0){
2574 retval = MPI_ERR_COUNT;
2576 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2581 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2582 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2585 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2588 if (old_type == MPI_DATATYPE_NULL) {
2589 retval = MPI_ERR_TYPE;
2590 } else if (count<0){
2591 retval = MPI_ERR_COUNT;
2593 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2598 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2601 if (old_type == MPI_DATATYPE_NULL) {
2602 retval = MPI_ERR_TYPE;
2603 } else if (count<0){
2604 retval = MPI_ERR_COUNT;
2606 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2611 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2614 if (old_type == MPI_DATATYPE_NULL) {
2615 retval = MPI_ERR_TYPE;
2616 } else if (count<0){
2617 retval = MPI_ERR_COUNT;
2619 int* blocklens=(int*)xbt_malloc(blocklength*count);
2620 for (i=0; i<count;i++)blocklens[i]=blocklength;
2621 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2622 xbt_free(blocklens);
2628 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2631 if (old_type == MPI_DATATYPE_NULL) {
2632 retval = MPI_ERR_TYPE;
2633 } else if (count<0){
2634 retval = MPI_ERR_COUNT;
2636 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2641 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2642 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2645 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2648 if (old_type == MPI_DATATYPE_NULL) {
2649 retval = MPI_ERR_TYPE;
2650 } else if (count<0){
2651 retval = MPI_ERR_COUNT;
2653 int* blocklens=(int*)xbt_malloc(blocklength*count);
2654 for (i=0; i<count;i++)blocklens[i]=blocklength;
2655 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2656 xbt_free(blocklens);
2662 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2666 retval = MPI_ERR_COUNT;
2668 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2673 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2674 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2678 int PMPI_Error_class(int errorcode, int* errorclass) {
2679 // assume smpi uses only standard mpi error codes
2680 *errorclass=errorcode;
2685 int PMPI_Initialized(int* flag) {
2686 *flag=smpi_process_initialized();
2690 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2691 * will be implemented, not only should we check if the topology is NULL, but
2692 * we should check if it is the good topology type (so we have to add a
2693 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2695 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2697 if (comm_old == MPI_COMM_NULL){
2698 retval = MPI_ERR_COMM;
2699 } else if (ndims < 0 ||
2700 (ndims > 0 && (dims == NULL ||
2701 periodic == NULL)) ||
2702 comm_cart == NULL) {
2703 retval = MPI_ERR_ARG;
2705 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2710 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2711 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2712 return MPI_ERR_TOPOLOGY;
2714 if (coords == NULL) {
2717 return smpi_mpi_cart_rank(comm, coords, rank);
2720 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2721 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2722 return MPI_ERR_TOPOLOGY;
2724 if (source == NULL || dest == NULL || direction < 0 ) {
2727 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2730 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2731 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2732 return MPI_ERR_TOPOLOGY;
2734 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2735 return MPI_ERR_RANK;
2740 if(coords == NULL) {
2743 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2746 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2747 if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2748 return MPI_ERR_TOPOLOGY;
2750 if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2753 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2756 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2757 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2758 return MPI_ERR_TOPOLOGY;
2760 if (ndims == NULL) {
2763 return smpi_mpi_cartdim_get(comm, ndims);
2766 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2770 if (ndims < 1 || nnodes < 1) {
2771 return MPI_ERR_DIMS;
2774 return smpi_mpi_dims_create(nnodes, ndims, dims);
2777 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2778 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2779 return MPI_ERR_TOPOLOGY;
2781 if (comm_new == NULL) {
2784 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2787 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2788 if(oldtype == MPI_DATATYPE_NULL) {
2789 return MPI_ERR_TYPE;
2791 int blocks[3] = { 1, 1, 1 };
2792 MPI_Aint disps[3] = { lb, 0, lb+extent };
2793 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2795 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks,
2800 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2802 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2808 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2811 if (comm == MPI_COMM_NULL) {
2812 retval= MPI_ERR_COMM;
2813 }else if ((base == NULL && size != 0)
2814 || disp_unit <= 0 || size < 0 ){
2815 retval= MPI_ERR_OTHER;
2817 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2818 retval = MPI_SUCCESS;
2824 int PMPI_Win_free( MPI_Win* win){
2827 if (win == NULL || *win == MPI_WIN_NULL) {
2828 retval = MPI_ERR_WIN;
2830 retval=smpi_mpi_win_free(win);
2836 int PMPI_Win_set_name(MPI_Win win, char * name)
2839 if (win == MPI_WIN_NULL) {
2840 retval = MPI_ERR_TYPE;
2841 } else if (name == NULL) {
2842 retval = MPI_ERR_ARG;
2844 smpi_mpi_win_set_name(win, name);
2845 retval = MPI_SUCCESS;
2850 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2852 int retval = MPI_SUCCESS;
2854 if (win == MPI_WIN_NULL) {
2855 retval = MPI_ERR_WIN;
2856 } else if (name == NULL) {
2857 retval = MPI_ERR_ARG;
2859 smpi_mpi_win_get_name(win, name, len);
2864 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2865 int retval = MPI_SUCCESS;
2866 if (win == MPI_WIN_NULL) {
2867 retval = MPI_ERR_WIN;
2869 smpi_mpi_win_get_group(win, group);
2875 int PMPI_Win_fence( int assert, MPI_Win win){
2878 if (win == MPI_WIN_NULL) {
2879 retval = MPI_ERR_WIN;
2882 int rank = smpi_process_index();
2883 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2885 retval = smpi_mpi_win_fence(assert, win);
2887 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2895 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2896 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2899 if (win == MPI_WIN_NULL) {
2900 retval = MPI_ERR_WIN;
2901 } else if (target_rank == MPI_PROC_NULL) {
2902 retval = MPI_SUCCESS;
2903 } else if (target_rank <0){
2904 retval = MPI_ERR_RANK;
2905 } else if (target_disp <0){
2906 retval = MPI_ERR_ARG;
2907 } else if (origin_count < 0 || target_count < 0) {
2908 retval = MPI_ERR_COUNT;
2909 } else if (origin_addr==NULL && origin_count > 0){
2910 retval = MPI_ERR_COUNT;
2911 } else if ((!is_datatype_valid(origin_datatype)) ||
2912 (!is_datatype_valid(target_datatype))) {
2913 retval = MPI_ERR_TYPE;
2916 int rank = smpi_process_index();
2918 smpi_mpi_win_get_group(win, &group);
2919 int src_traced = smpi_group_index(group, target_rank);
2920 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2923 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2926 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2933 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2934 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2937 if (win == MPI_WIN_NULL) {
2938 retval = MPI_ERR_WIN;
2939 } else if (target_rank == MPI_PROC_NULL) {
2940 retval = MPI_SUCCESS;
2941 } else if (target_rank <0){
2942 retval = MPI_ERR_RANK;
2943 } else if (target_disp <0){
2944 retval = MPI_ERR_ARG;
2945 } else if (origin_count < 0 || target_count < 0) {
2946 retval = MPI_ERR_COUNT;
2947 } else if (origin_addr==NULL && origin_count > 0){
2948 retval = MPI_ERR_COUNT;
2949 } else if ((!is_datatype_valid(origin_datatype)) ||
2950 (!is_datatype_valid(target_datatype))) {
2951 retval = MPI_ERR_TYPE;
2954 int rank = smpi_process_index();
2956 smpi_mpi_win_get_group(win, &group);
2957 int dst_traced = smpi_group_index(group, target_rank);
2958 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, NULL);
2959 TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2962 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2965 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2974 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2975 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2978 if (win == MPI_WIN_NULL) {
2979 retval = MPI_ERR_WIN;
2980 } else if (target_rank == MPI_PROC_NULL) {
2981 retval = MPI_SUCCESS;
2982 } else if (target_rank <0){
2983 retval = MPI_ERR_RANK;
2984 } else if (target_disp <0){
2985 retval = MPI_ERR_ARG;
2986 } else if (origin_count < 0 || target_count < 0) {
2987 retval = MPI_ERR_COUNT;
2988 } else if (origin_addr==NULL && origin_count > 0){
2989 retval = MPI_ERR_COUNT;
2990 } else if ((!is_datatype_valid(origin_datatype)) ||
2991 (!is_datatype_valid(target_datatype))) {
2992 retval = MPI_ERR_TYPE;
2993 } else if (op == MPI_OP_NULL) {
2994 retval = MPI_ERR_OP;
2997 int rank = smpi_process_index();
2999 smpi_mpi_win_get_group(win, &group);
3000 int src_traced = smpi_group_index(group, target_rank);
3001 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
3004 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, op, win);
3007 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
3016 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
3017 void *ptr = xbt_malloc(size);
3019 return MPI_ERR_NO_MEM;
3021 *(void **)baseptr = ptr;
3026 int PMPI_Free_mem(void *baseptr){
3031 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
3034 if (datatype == MPI_DATATYPE_NULL) {
3035 retval = MPI_ERR_TYPE;
3036 } else if (name == NULL) {
3037 retval = MPI_ERR_ARG;
3039 smpi_datatype_set_name(datatype, name);
3040 retval = MPI_SUCCESS;
3045 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
3049 if (datatype == MPI_DATATYPE_NULL) {
3050 retval = MPI_ERR_TYPE;
3051 } else if (name == NULL) {
3052 retval = MPI_ERR_ARG;
3054 smpi_datatype_get_name(datatype, name, len);
3055 retval = MPI_SUCCESS;
3061 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
3062 return smpi_type_f2c(datatype);
3065 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
3066 return smpi_type_c2f( datatype);
3069 MPI_Group PMPI_Group_f2c(MPI_Fint group){
3070 return smpi_group_f2c( group);
3073 MPI_Fint PMPI_Group_c2f(MPI_Group group){
3074 return smpi_group_c2f(group);
3077 MPI_Request PMPI_Request_f2c(MPI_Fint request){
3078 return smpi_request_f2c(request);
3081 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
3082 return smpi_request_c2f(request);
3085 MPI_Win PMPI_Win_f2c(MPI_Fint win){
3086 return smpi_win_f2c(win);
3089 MPI_Fint PMPI_Win_c2f(MPI_Win win){
3090 return smpi_win_c2f(win);
3093 MPI_Op PMPI_Op_f2c(MPI_Fint op){
3094 return smpi_op_f2c(op);
3097 MPI_Fint PMPI_Op_c2f(MPI_Op op){
3098 return smpi_op_c2f(op);
3101 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
3102 return smpi_comm_f2c(comm);
3105 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
3106 return smpi_comm_c2f(comm);
3109 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3110 return smpi_info_f2c(info);
3113 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3114 return smpi_info_c2f(info);
3117 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3118 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3121 int PMPI_Keyval_free(int* keyval) {
3122 return smpi_comm_keyval_free(keyval);
3125 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3126 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3127 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3128 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3130 else if (comm==MPI_COMM_NULL)
3131 return MPI_ERR_COMM;
3133 return smpi_comm_attr_delete(comm, keyval);
3136 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3137 if (comm==MPI_COMM_NULL){
3139 return MPI_ERR_COMM;
3140 } else if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3141 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3142 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE){
3144 //FIXME : not ideal and leaky, but should not be called too much
3145 int* res = xbt_new(int, 1);
3147 *(int**)attr_value=res;
3150 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3153 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3154 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3155 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3156 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3158 else if (comm==MPI_COMM_NULL)
3159 return MPI_ERR_COMM;
3161 return smpi_comm_attr_put(comm, keyval, attr_value);
3164 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3166 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3169 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3171 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3174 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3176 return PMPI_Attr_delete(comm, comm_keyval);
3179 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3181 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3184 int PMPI_Comm_free_keyval(int* keyval) {
3185 return PMPI_Keyval_free(keyval);
3189 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3191 if (type==MPI_DATATYPE_NULL)
3192 return MPI_ERR_TYPE;
3194 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3197 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3199 if (type==MPI_DATATYPE_NULL)
3200 return MPI_ERR_TYPE;
3202 return smpi_type_attr_put(type, type_keyval, attribute_val);
3205 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3207 if (type==MPI_DATATYPE_NULL)
3208 return MPI_ERR_TYPE;
3210 return smpi_type_attr_delete(type, type_keyval);
3213 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3215 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3218 int PMPI_Type_free_keyval(int* keyval) {
3219 return smpi_type_keyval_free(keyval);
3222 int PMPI_Info_create( MPI_Info *info){
3225 *info = xbt_new(s_smpi_mpi_info_t, 1);
3226 (*info)->info_dict= xbt_dict_new_homogeneous(NULL);
3227 (*info)->refcount=1;
3231 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3232 if (info == NULL || key == NULL || value == NULL)
3235 xbt_dict_set(info->info_dict, key, (void*)value, NULL);
3239 int PMPI_Info_free( MPI_Info *info){
3240 if (info == NULL || *info==NULL)
3242 (*info)->refcount--;
3243 if((*info)->refcount==0){
3244 xbt_dict_free(&((*info)->info_dict));
3247 *info=MPI_INFO_NULL;
3251 int PMPI_Info_get(MPI_Info info,char *key,int valuelen, char *value, int *flag){
3252 if (info == NULL || key == NULL || valuelen <0)
3255 return MPI_ERR_INFO_VALUE;
3257 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3259 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < valuelen) ?
3260 strlen(tmpvalue) + 1 : valuelen);
3266 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3267 if (info == NULL || newinfo==NULL)
3269 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3270 (*newinfo)->info_dict= xbt_dict_new_homogeneous(NULL);
3271 xbt_dict_cursor_t cursor = NULL;
3274 xbt_dict_foreach(info->info_dict,cursor,key,data){
3275 xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
3280 int PMPI_Info_delete(MPI_Info info, char *key){
3282 if (info == NULL || key==NULL)
3285 xbt_dict_remove(info->info_dict, key);
3288 return MPI_ERR_INFO_NOKEY;
3293 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3294 if (info == NULL || nkeys==NULL)
3296 *nkeys=xbt_dict_size(info->info_dict);
3300 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3301 if (info == NULL || key==NULL || n<0 || n> MPI_MAX_INFO_KEY)
3304 xbt_dict_cursor_t cursor = NULL;
3308 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3318 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3319 if (info == NULL || key == NULL || valuelen <0)
3322 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3324 *valuelen=strlen(tmpvalue);
3330 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3331 if(incount<0 || outcount < 0 || inbuf==NULL || outbuf==NULL)
3333 if(!is_datatype_valid(type))
3334 return MPI_ERR_TYPE;
3335 if(comm==MPI_COMM_NULL)
3336 return MPI_ERR_COMM;
3337 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3340 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3341 if(incount<0 || outcount < 0|| inbuf==NULL || outbuf==NULL)
3343 if(!is_datatype_valid(type))
3344 return MPI_ERR_TYPE;
3345 if(comm==MPI_COMM_NULL)
3346 return MPI_ERR_COMM;
3347 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3350 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3353 if(!is_datatype_valid(datatype))
3354 return MPI_ERR_TYPE;
3355 if(comm==MPI_COMM_NULL)
3356 return MPI_ERR_COMM;
3358 *size=incount*smpi_datatype_size(datatype);
3364 /* The following calls are not yet implemented and will fail at runtime. */
3365 /* Once implemented, please move them above this notice. */
3367 #define NOT_YET_IMPLEMENTED { \
3368 XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
3369 return MPI_SUCCESS; \
3372 MPI_Errhandler PMPI_Errhandler_f2c(MPI_Fint errhandler){
3376 MPI_Fint PMPI_Errhandler_c2f(MPI_Errhandler errhandler){
3380 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
3384 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
3388 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
3392 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
3396 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
3400 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
3404 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
3408 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
3412 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
3416 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
3420 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
3424 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
3428 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
3432 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
3436 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
3440 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
3444 int PMPI_Cancel(MPI_Request* request) {
3448 int PMPI_Buffer_attach(void* buffer, int size) {
3452 int PMPI_Buffer_detach(void* buffer, int* size) {
3456 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
3460 int PMPI_Pcontrol(const int level )
3466 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
3470 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3474 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3478 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3482 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3486 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3490 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3494 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3498 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3502 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3506 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3512 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3516 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
3520 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
3524 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3530 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
3531 int *num_addresses, int *num_datatypes, int *combiner){
3535 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
3536 int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
3537 MPI_Datatype* array_of_datatypes){
3541 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
3542 int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
3543 int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
3547 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){
3551 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3555 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3556 void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
3561 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3565 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3569 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3573 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3577 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3581 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3585 int PMPI_Add_error_class( int *errorclass){
3589 int PMPI_Add_error_code( int errorclass, int *errorcode){
3593 int PMPI_Add_error_string( int errorcode, char *string){
3597 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3601 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3605 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){
3609 int PMPI_Grequest_complete( MPI_Request request){
3613 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3617 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3621 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3625 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3629 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3633 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3637 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3641 int PMPI_Open_port( MPI_Info info, char *port_name){
3645 int PMPI_Close_port(char *port_name){
3649 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3653 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){
3657 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3658 int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3659 MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3663 int PMPI_Comm_get_parent( MPI_Comm *parent){
3667 int PMPI_Win_complete(MPI_Win win){
3671 int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win) {
3675 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
3679 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
3683 int PMPI_Win_test(MPI_Win win, int *flag){
3687 int PMPI_Win_unlock(int rank, MPI_Win win){
3691 int PMPI_Win_wait(MPI_Win win){