2 /* Copyright (c) 2007-2015. 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)");
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
24 /* PMPI User level calls */
26 int PMPI_Init(int *argc, char ***argv)
28 // PMPI_Init is call only one time by only by SMPI process
30 MPI_Initialized(&already_init);
32 smpi_process_init(argc, argv);
33 smpi_process_mark_as_initialized();
34 int rank = smpi_process_index();
35 TRACE_smpi_init(rank);
36 TRACE_smpi_computing_init(rank);
37 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
38 extra->type = TRACING_INIT;
39 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
40 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
46 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());
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-2015",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_SINGLE;
89 return MPI_Init(argc, argv);
92 int PMPI_Query_thread(int *provided)
96 if (provided == NULL) {
99 *provided = MPI_THREAD_SINGLE;
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)
129 return smpi_mpi_wtime();
132 extern double sg_maxmin_precision;
133 double PMPI_Wtick(void)
135 return sg_maxmin_precision;
138 int PMPI_Address(void *location, MPI_Aint * address)
143 retval = MPI_ERR_ARG;
145 *address = (MPI_Aint) location;
146 retval = MPI_SUCCESS;
151 int PMPI_Get_address(void *location, MPI_Aint * address)
153 return PMPI_Address(location, address);
156 int PMPI_Type_free(MPI_Datatype * datatype)
159 /* Free a predefined datatype is an error according to the standard, and
160 should be checked for */
161 if (*datatype == MPI_DATATYPE_NULL) {
162 retval = MPI_ERR_ARG;
164 smpi_datatype_free(datatype);
165 retval = MPI_SUCCESS;
170 int PMPI_Type_size(MPI_Datatype datatype, int *size)
174 if (datatype == MPI_DATATYPE_NULL) {
175 retval = MPI_ERR_TYPE;
176 } else if (size == NULL) {
177 retval = MPI_ERR_ARG;
179 *size = (int) smpi_datatype_size(datatype);
180 retval = MPI_SUCCESS;
185 int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
189 if (datatype == MPI_DATATYPE_NULL) {
190 retval = MPI_ERR_TYPE;
191 } else if (lb == NULL || extent == NULL) {
192 retval = MPI_ERR_ARG;
194 retval = smpi_datatype_extent(datatype, lb, extent);
199 int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent)
201 return PMPI_Type_get_extent(datatype, lb, extent);
204 int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent)
208 if (datatype == MPI_DATATYPE_NULL) {
209 retval = MPI_ERR_TYPE;
210 } else if (extent == NULL) {
211 retval = MPI_ERR_ARG;
213 *extent = smpi_datatype_get_extent(datatype);
214 retval = MPI_SUCCESS;
219 int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp)
223 if (datatype == MPI_DATATYPE_NULL) {
224 retval = MPI_ERR_TYPE;
225 } else if (disp == NULL) {
226 retval = MPI_ERR_ARG;
228 *disp = smpi_datatype_lb(datatype);
229 retval = MPI_SUCCESS;
234 int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp)
238 if (datatype == MPI_DATATYPE_NULL) {
239 retval = MPI_ERR_TYPE;
240 } else if (disp == NULL) {
241 retval = MPI_ERR_ARG;
243 *disp = smpi_datatype_ub(datatype);
244 retval = MPI_SUCCESS;
249 int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){
252 if (datatype == MPI_DATATYPE_NULL) {
253 retval = MPI_ERR_TYPE;
255 retval = smpi_datatype_dup(datatype, newtype);
260 int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op)
264 if (function == NULL || op == NULL) {
265 retval = MPI_ERR_ARG;
267 *op = smpi_op_new(function, commute);
268 retval = MPI_SUCCESS;
273 int PMPI_Op_free(MPI_Op * op)
278 retval = MPI_ERR_ARG;
279 } else if (*op == MPI_OP_NULL) {
282 smpi_op_destroy(*op);
284 retval = MPI_SUCCESS;
289 int PMPI_Group_free(MPI_Group * group)
294 retval = MPI_ERR_ARG;
296 smpi_group_destroy(*group);
297 *group = MPI_GROUP_NULL;
298 retval = MPI_SUCCESS;
303 int PMPI_Group_size(MPI_Group group, int *size)
307 if (group == MPI_GROUP_NULL) {
308 retval = MPI_ERR_GROUP;
309 } else if (size == NULL) {
310 retval = MPI_ERR_ARG;
312 *size = smpi_group_size(group);
313 retval = MPI_SUCCESS;
318 int PMPI_Group_rank(MPI_Group group, int *rank)
322 if (group == MPI_GROUP_NULL) {
323 retval = MPI_ERR_GROUP;
324 } else if (rank == NULL) {
325 retval = MPI_ERR_ARG;
327 *rank = smpi_group_rank(group, smpi_process_index());
328 retval = MPI_SUCCESS;
333 int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1,
334 MPI_Group group2, int *ranks2)
336 int retval, i, index;
337 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
338 retval = MPI_ERR_GROUP;
340 for (i = 0; i < n; i++) {
341 if(ranks1[i]==MPI_PROC_NULL){
342 ranks2[i]=MPI_PROC_NULL;
344 index = smpi_group_index(group1, ranks1[i]);
345 ranks2[i] = smpi_group_rank(group2, index);
348 retval = MPI_SUCCESS;
353 int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
357 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
358 retval = MPI_ERR_GROUP;
359 } else if (result == NULL) {
360 retval = MPI_ERR_ARG;
362 *result = smpi_group_compare(group1, group2);
363 retval = MPI_SUCCESS;
368 int PMPI_Group_union(MPI_Group group1, MPI_Group group2,
369 MPI_Group * newgroup)
371 int retval, i, proc1, proc2, size, size2;
373 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
374 retval = MPI_ERR_GROUP;
375 } else if (newgroup == NULL) {
376 retval = MPI_ERR_ARG;
378 size = smpi_group_size(group1);
379 size2 = smpi_group_size(group2);
380 for (i = 0; i < size2; i++) {
381 proc2 = smpi_group_index(group2, i);
382 proc1 = smpi_group_rank(group1, proc2);
383 if (proc1 == MPI_UNDEFINED) {
388 *newgroup = MPI_GROUP_EMPTY;
390 *newgroup = smpi_group_new(size);
391 size2 = smpi_group_size(group1);
392 for (i = 0; i < size2; i++) {
393 proc1 = smpi_group_index(group1, i);
394 smpi_group_set_mapping(*newgroup, proc1, i);
396 for (i = size2; i < size; i++) {
397 proc2 = smpi_group_index(group2, i - size2);
398 smpi_group_set_mapping(*newgroup, proc2, i);
401 retval = MPI_SUCCESS;
406 int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2,
407 MPI_Group * newgroup)
409 int retval, i, proc1, proc2, size;
411 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
412 retval = MPI_ERR_GROUP;
413 } else if (newgroup == NULL) {
414 retval = MPI_ERR_ARG;
416 size = smpi_group_size(group2);
417 for (i = 0; i < size; i++) {
418 proc2 = smpi_group_index(group2, i);
419 proc1 = smpi_group_rank(group1, proc2);
420 if (proc1 == MPI_UNDEFINED) {
425 *newgroup = MPI_GROUP_EMPTY;
427 *newgroup = smpi_group_new(size);
429 for (i = 0; i < smpi_group_size(group2); i++) {
430 proc2 = smpi_group_index(group2, i);
431 proc1 = smpi_group_rank(group1, proc2);
432 if (proc1 != MPI_UNDEFINED) {
433 smpi_group_set_mapping(*newgroup, proc2, j);
438 retval = MPI_SUCCESS;
443 int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
445 int retval, i, proc1, proc2, size, size2;
447 if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
448 retval = MPI_ERR_GROUP;
449 } else if (newgroup == NULL) {
450 retval = MPI_ERR_ARG;
452 size = size2 = smpi_group_size(group1);
453 for (i = 0; i < size2; i++) {
454 proc1 = smpi_group_index(group1, i);
455 proc2 = smpi_group_rank(group2, proc1);
456 if (proc2 != MPI_UNDEFINED) {
461 *newgroup = MPI_GROUP_EMPTY;
463 *newgroup = smpi_group_new(size);
464 for (i = 0; i < size2; i++) {
465 proc1 = smpi_group_index(group1, i);
466 proc2 = smpi_group_rank(group2, proc1);
467 if (proc2 == MPI_UNDEFINED) {
468 smpi_group_set_mapping(*newgroup, proc1, i);
472 retval = MPI_SUCCESS;
477 int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
481 if (group == MPI_GROUP_NULL) {
482 retval = MPI_ERR_GROUP;
483 } else if (newgroup == NULL) {
484 retval = MPI_ERR_ARG;
486 retval = smpi_group_incl(group, n, ranks, newgroup);
491 int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
493 int retval, i, j, newsize, oldsize, index;
495 if (group == MPI_GROUP_NULL) {
496 retval = MPI_ERR_GROUP;
497 } else if (newgroup == NULL) {
498 retval = MPI_ERR_ARG;
502 if(group!= smpi_comm_group(MPI_COMM_WORLD)
503 && group != MPI_GROUP_NULL
504 && group != smpi_comm_group(MPI_COMM_SELF)
505 && group != MPI_GROUP_EMPTY)
506 smpi_group_use(group);
507 } else if (n == smpi_group_size(group)) {
508 *newgroup = MPI_GROUP_EMPTY;
510 oldsize=smpi_group_size(group);
511 newsize = oldsize - n;
512 *newgroup = smpi_group_new(newsize);
514 int* to_exclude=xbt_new0(int, smpi_group_size(group));
515 for(i=0; i<oldsize; i++)
518 to_exclude[ranks[i]]=1;
521 for(i=0; i<oldsize; i++){
522 if(to_exclude[i]==0){
523 index = smpi_group_index(group, i);
524 smpi_group_set_mapping(*newgroup, index, j);
529 xbt_free(to_exclude);
531 retval = MPI_SUCCESS;
536 int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3],
537 MPI_Group * newgroup)
539 int retval, i, j, rank, size, index;
541 if (group == MPI_GROUP_NULL) {
542 retval = MPI_ERR_GROUP;
543 } else if (newgroup == NULL) {
544 retval = MPI_ERR_ARG;
547 *newgroup = MPI_GROUP_EMPTY;
550 for (i = 0; i < n; i++) {
551 for (rank = ranges[i][0]; /* First */
552 rank >= 0 && rank < smpi_group_size(group); /* Last */
555 if(rank == ranges[i][1]){/*already last ?*/
558 rank += ranges[i][2]; /* Stride */
559 if (ranges[i][0]<ranges[i][1]){
560 if(rank > ranges[i][1])
563 if(rank < ranges[i][1])
569 *newgroup = smpi_group_new(size);
571 for (i = 0; i < n; i++) {
572 for (rank = ranges[i][0]; /* First */
573 rank >= 0 && rank < smpi_group_size(group); /* Last */
575 index = smpi_group_index(group, rank);
576 smpi_group_set_mapping(*newgroup, index, j);
578 if(rank == ranges[i][1]){/*already last ?*/
581 rank += ranges[i][2]; /* Stride */
582 if (ranges[i][0]<ranges[i][1]){
583 if(rank > ranges[i][1])
586 if(rank < ranges[i][1])
592 retval = MPI_SUCCESS;
597 int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3],
598 MPI_Group * newgroup)
600 int retval, i, rank, newrank,oldrank, size, index, add;
602 if (group == MPI_GROUP_NULL) {
603 retval = MPI_ERR_GROUP;
604 } else if (newgroup == NULL) {
605 retval = MPI_ERR_ARG;
609 if(group!= smpi_comm_group(MPI_COMM_WORLD)
610 && group != MPI_GROUP_NULL
611 && group != smpi_comm_group(MPI_COMM_SELF)
612 && group != MPI_GROUP_EMPTY)
613 smpi_group_use(group);
615 size = smpi_group_size(group);
616 for (i = 0; i < n; i++) {
617 for (rank = ranges[i][0]; /* First */
618 rank >= 0 && rank < smpi_group_size(group); /* Last */
621 if(rank == ranges[i][1]){/*already last ?*/
624 rank += ranges[i][2]; /* Stride */
625 if (ranges[i][0]<ranges[i][1]){
626 if(rank > ranges[i][1])
629 if(rank < ranges[i][1])
635 *newgroup = MPI_GROUP_EMPTY;
637 *newgroup = smpi_group_new(size);
640 while (newrank < size) {
642 for (i = 0; i < n; i++) {
643 for (rank = ranges[i][0];
644 rank >= 0 && rank < smpi_group_size(group);
650 if(rank == ranges[i][1]){/*already last ?*/
653 rank += ranges[i][2]; /* Stride */
654 if (ranges[i][0]<ranges[i][1]){
655 if(rank > ranges[i][1])
658 if(rank < ranges[i][1])
664 index = smpi_group_index(group, oldrank);
665 smpi_group_set_mapping(*newgroup, index, newrank);
673 retval = MPI_SUCCESS;
678 int PMPI_Comm_rank(MPI_Comm comm, int *rank)
681 if (comm == MPI_COMM_NULL) {
682 retval = MPI_ERR_COMM;
683 } else if (rank == NULL) {
684 retval = MPI_ERR_ARG;
686 *rank = smpi_comm_rank(comm);
687 retval = MPI_SUCCESS;
692 int PMPI_Comm_size(MPI_Comm comm, int *size)
695 if (comm == MPI_COMM_NULL) {
696 retval = MPI_ERR_COMM;
697 } else if (size == NULL) {
698 retval = MPI_ERR_ARG;
700 *size = smpi_comm_size(comm);
701 retval = MPI_SUCCESS;
706 int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len)
710 if (comm == MPI_COMM_NULL) {
711 retval = MPI_ERR_COMM;
712 } else if (name == NULL || len == NULL) {
713 retval = MPI_ERR_ARG;
715 smpi_comm_get_name(comm, name, len);
716 retval = MPI_SUCCESS;
721 int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
725 if (comm == MPI_COMM_NULL) {
726 retval = MPI_ERR_COMM;
727 } else if (group == NULL) {
728 retval = MPI_ERR_ARG;
730 *group = smpi_comm_group(comm);
731 if(*group!= smpi_comm_group(MPI_COMM_WORLD)
732 && *group != MPI_GROUP_NULL
733 && *group != smpi_comm_group(MPI_COMM_SELF)
734 && *group != MPI_GROUP_EMPTY)
735 smpi_group_use(*group);
736 retval = MPI_SUCCESS;
741 int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
745 if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
746 retval = MPI_ERR_COMM;
747 } else if (result == NULL) {
748 retval = MPI_ERR_ARG;
750 if (comm1 == comm2) { /* Same communicators means same groups */
754 smpi_group_compare(smpi_comm_group(comm1),
755 smpi_comm_group(comm2));
756 if (*result == MPI_IDENT) {
757 *result = MPI_CONGRUENT;
760 retval = MPI_SUCCESS;
765 int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm)
769 if (comm == MPI_COMM_NULL) {
770 retval = MPI_ERR_COMM;
771 } else if (newcomm == NULL) {
772 retval = MPI_ERR_ARG;
774 retval = smpi_comm_dup(comm, newcomm);
779 int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
783 if (comm == MPI_COMM_NULL) {
784 retval = MPI_ERR_COMM;
785 } else if (group == MPI_GROUP_NULL) {
786 retval = MPI_ERR_GROUP;
787 } else if (newcomm == NULL) {
788 retval = MPI_ERR_ARG;
789 } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
790 *newcomm= MPI_COMM_NULL;
791 retval = MPI_SUCCESS;
794 *newcomm = smpi_comm_new(group, NULL);
795 retval = MPI_SUCCESS;
800 int PMPI_Comm_free(MPI_Comm * comm)
805 retval = MPI_ERR_ARG;
806 } else if (*comm == MPI_COMM_NULL) {
807 retval = MPI_ERR_COMM;
809 smpi_comm_destroy(*comm);
810 *comm = MPI_COMM_NULL;
811 retval = MPI_SUCCESS;
816 int PMPI_Comm_disconnect(MPI_Comm * comm)
818 /* TODO: wait until all communication in comm are done */
822 retval = MPI_ERR_ARG;
823 } else if (*comm == MPI_COMM_NULL) {
824 retval = MPI_ERR_COMM;
826 smpi_comm_destroy(*comm);
827 *comm = MPI_COMM_NULL;
828 retval = MPI_SUCCESS;
833 int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
838 if (comm_out == NULL) {
839 retval = MPI_ERR_ARG;
840 } else if (comm == MPI_COMM_NULL) {
841 retval = MPI_ERR_COMM;
843 *comm_out = smpi_comm_split(comm, color, key);
844 retval = MPI_SUCCESS;
851 int PMPI_Send_init(void *buf, int count, MPI_Datatype datatype, int dst,
852 int tag, MPI_Comm comm, MPI_Request * request)
857 if (request == NULL) {
858 retval = MPI_ERR_ARG;
859 } else if (comm == MPI_COMM_NULL) {
860 retval = MPI_ERR_COMM;
861 } else if (!is_datatype_valid(datatype)) {
862 retval = MPI_ERR_TYPE;
863 } else if (dst == MPI_PROC_NULL) {
864 retval = MPI_SUCCESS;
866 *request = smpi_mpi_send_init(buf, count, datatype, dst, tag, comm);
867 retval = MPI_SUCCESS;
870 if (retval != MPI_SUCCESS && request)
871 *request = MPI_REQUEST_NULL;
875 int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src,
876 int tag, MPI_Comm comm, MPI_Request * request)
881 if (request == NULL) {
882 retval = MPI_ERR_ARG;
883 } else if (comm == MPI_COMM_NULL) {
884 retval = MPI_ERR_COMM;
885 } else if (!is_datatype_valid(datatype)) {
886 retval = MPI_ERR_TYPE;
887 } else if (src == MPI_PROC_NULL) {
888 retval = MPI_SUCCESS;
890 *request = smpi_mpi_recv_init(buf, count, datatype, src, tag, comm);
891 retval = MPI_SUCCESS;
894 if (retval != MPI_SUCCESS && request)
895 *request = MPI_REQUEST_NULL;
899 int PMPI_Ssend_init(void* buf, int count, MPI_Datatype datatype,
900 int dst, int tag, MPI_Comm comm, MPI_Request* request)
905 if (request == NULL) {
906 retval = MPI_ERR_ARG;
907 } else if (comm == MPI_COMM_NULL) {
908 retval = MPI_ERR_COMM;
909 } else if (!is_datatype_valid(datatype)) {
910 retval = MPI_ERR_TYPE;
911 } else if (dst == MPI_PROC_NULL) {
912 retval = MPI_SUCCESS;
914 *request = smpi_mpi_ssend_init(buf, count, datatype, dst, tag, comm);
915 retval = MPI_SUCCESS;
918 if (retval != MPI_SUCCESS && request)
919 *request = MPI_REQUEST_NULL;
923 int PMPI_Start(MPI_Request * request)
928 if (request == NULL || *request == MPI_REQUEST_NULL) {
929 retval = MPI_ERR_REQUEST;
931 smpi_mpi_start(*request);
932 retval = MPI_SUCCESS;
938 int PMPI_Startall(int count, MPI_Request * requests)
943 if (requests == NULL) {
944 retval = MPI_ERR_ARG;
946 retval = MPI_SUCCESS;
947 for (i = 0 ; i < count ; i++) {
948 if(requests[i] == MPI_REQUEST_NULL) {
949 retval = MPI_ERR_REQUEST;
952 if(retval != MPI_ERR_REQUEST) {
953 smpi_mpi_startall(count, requests);
960 int PMPI_Request_free(MPI_Request * request)
965 if (*request == MPI_REQUEST_NULL) {
966 retval = MPI_ERR_ARG;
968 smpi_mpi_request_free(request);
969 retval = MPI_SUCCESS;
975 int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src,
976 int tag, MPI_Comm comm, MPI_Request * request)
982 if (request == NULL) {
983 retval = MPI_ERR_ARG;
984 } else if (comm == MPI_COMM_NULL) {
985 retval = MPI_ERR_COMM;
986 } else if (src == MPI_PROC_NULL) {
987 *request = MPI_REQUEST_NULL;
988 retval = MPI_SUCCESS;
989 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
990 retval = MPI_ERR_RANK;
991 } else if (count < 0) {
992 retval = MPI_ERR_COUNT;
993 } else if (buf==NULL && count > 0) {
994 retval = MPI_ERR_COUNT;
995 } else if (!is_datatype_valid(datatype)) {
996 retval = MPI_ERR_TYPE;
997 } else if(tag<0 && tag != MPI_ANY_TAG){
998 retval = MPI_ERR_TAG;
1001 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1002 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1004 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1005 extra->type = TRACING_IRECV;
1006 extra->src = src_traced;
1009 extra->datatype1 = encode_datatype(datatype, &known);
1010 int dt_size_send = 1;
1012 dt_size_send = smpi_datatype_size(datatype);
1013 extra->send_size = count*dt_size_send;
1014 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1016 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
1017 retval = MPI_SUCCESS;
1019 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1020 (*request)->recv = 1;
1024 if (retval != MPI_SUCCESS && request)
1025 *request = MPI_REQUEST_NULL;
1030 int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst,
1031 int tag, MPI_Comm comm, MPI_Request * request)
1036 if (request == NULL) {
1037 retval = MPI_ERR_ARG;
1038 } else if (comm == MPI_COMM_NULL) {
1039 retval = MPI_ERR_COMM;
1040 } else if (dst == MPI_PROC_NULL) {
1041 *request = MPI_REQUEST_NULL;
1042 retval = MPI_SUCCESS;
1043 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1044 retval = MPI_ERR_RANK;
1045 } else if (count < 0) {
1046 retval = MPI_ERR_COUNT;
1047 } else if (buf==NULL && count > 0) {
1048 retval = MPI_ERR_COUNT;
1049 } else if (!is_datatype_valid(datatype)) {
1050 retval = MPI_ERR_TYPE;
1051 } else if(tag<0 && tag != MPI_ANY_TAG){
1052 retval = MPI_ERR_TAG;
1055 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1056 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1057 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1058 extra->type = TRACING_ISEND;
1060 extra->dst = dst_traced;
1062 extra->datatype1 = encode_datatype(datatype, &known);
1063 int dt_size_send = 1;
1065 dt_size_send = smpi_datatype_size(datatype);
1066 extra->send_size = count*dt_size_send;
1067 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1068 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1070 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
1071 retval = MPI_SUCCESS;
1073 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1074 (*request)->send = 1;
1078 if (retval != MPI_SUCCESS && request)
1079 *request = MPI_REQUEST_NULL;
1083 int PMPI_Issend(void* buf, int count, MPI_Datatype datatype,
1084 int dst, int tag, MPI_Comm comm, MPI_Request* request)
1089 if (request == NULL) {
1090 retval = MPI_ERR_ARG;
1091 } else if (comm == MPI_COMM_NULL) {
1092 retval = MPI_ERR_COMM;
1093 } else if (dst == MPI_PROC_NULL) {
1094 *request = MPI_REQUEST_NULL;
1095 retval = MPI_SUCCESS;
1096 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1097 retval = MPI_ERR_RANK;
1098 } else if (count < 0) {
1099 retval = MPI_ERR_COUNT;
1100 } else if (buf==NULL && count > 0) {
1101 retval = MPI_ERR_COUNT;
1102 } else if (!is_datatype_valid(datatype)) {
1103 retval = MPI_ERR_TYPE;
1104 } else if(tag<0 && tag != MPI_ANY_TAG){
1105 retval = MPI_ERR_TAG;
1108 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1109 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1110 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1111 extra->type = TRACING_ISSEND;
1113 extra->dst = dst_traced;
1115 extra->datatype1 = encode_datatype(datatype, &known);
1116 int dt_size_send = 1;
1118 dt_size_send = smpi_datatype_size(datatype);
1119 extra->send_size = count*dt_size_send;
1120 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1121 TRACE_smpi_send(rank, rank, dst_traced, count*smpi_datatype_size(datatype));
1123 *request = smpi_mpi_issend(buf, count, datatype, dst, tag, comm);
1124 retval = MPI_SUCCESS;
1126 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1127 (*request)->send = 1;
1131 if (retval != MPI_SUCCESS && request)
1132 *request = MPI_REQUEST_NULL;
1136 int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag,
1137 MPI_Comm comm, MPI_Status * status)
1142 if (comm == MPI_COMM_NULL) {
1143 retval = MPI_ERR_COMM;
1144 } else if (src == MPI_PROC_NULL) {
1145 smpi_empty_status(status);
1146 status->MPI_SOURCE = MPI_PROC_NULL;
1147 retval = MPI_SUCCESS;
1148 } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
1149 retval = MPI_ERR_RANK;
1150 } else if (count < 0) {
1151 retval = MPI_ERR_COUNT;
1152 } else if (buf==NULL && count > 0) {
1153 retval = MPI_ERR_COUNT;
1154 } else if (!is_datatype_valid(datatype)) {
1155 retval = MPI_ERR_TYPE;
1156 } else if(tag<0 && tag != MPI_ANY_TAG){
1157 retval = MPI_ERR_TAG;
1159 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1160 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1161 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1162 extra->type = TRACING_RECV;
1163 extra->src = src_traced;
1166 extra->datatype1 = encode_datatype(datatype, &known);
1167 int dt_size_send = 1;
1169 dt_size_send = smpi_datatype_size(datatype);
1170 extra->send_size = count*dt_size_send;
1171 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra);
1173 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
1174 retval = MPI_SUCCESS;
1176 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1177 if(status!=MPI_STATUS_IGNORE){
1178 src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
1179 if (!TRACE_smpi_view_internals()) {
1180 TRACE_smpi_recv(rank, src_traced, rank);
1183 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
1190 int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag,
1197 if (comm == MPI_COMM_NULL) {
1198 retval = MPI_ERR_COMM;
1199 } else if (dst == MPI_PROC_NULL) {
1200 retval = MPI_SUCCESS;
1201 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1202 retval = MPI_ERR_RANK;
1203 } else if (count < 0) {
1204 retval = MPI_ERR_COUNT;
1205 } else if (buf==NULL && count > 0) {
1206 retval = MPI_ERR_COUNT;
1207 } else if (!is_datatype_valid(datatype)) {
1208 retval = MPI_ERR_TYPE;
1209 } else if(tag<0 && tag != MPI_ANY_TAG){
1210 retval = MPI_ERR_TAG;
1213 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1214 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1215 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1216 extra->type = TRACING_SEND;
1218 extra->dst = dst_traced;
1220 extra->datatype1 = encode_datatype(datatype, &known);
1221 int dt_size_send = 1;
1223 dt_size_send = smpi_datatype_size(datatype);
1224 extra->send_size = count*dt_size_send;
1225 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra);
1226 if (!TRACE_smpi_view_internals()) {
1227 TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1230 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
1231 retval = MPI_SUCCESS;
1233 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1242 int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
1247 if (comm == MPI_COMM_NULL) {
1248 retval = MPI_ERR_COMM;
1249 } else if (dst == MPI_PROC_NULL) {
1250 retval = MPI_SUCCESS;
1251 } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
1252 retval = MPI_ERR_RANK;
1253 } else if (count < 0) {
1254 retval = MPI_ERR_COUNT;
1255 } else if (buf==NULL && count > 0) {
1256 retval = MPI_ERR_COUNT;
1257 } else if (!is_datatype_valid(datatype)){
1258 retval = MPI_ERR_TYPE;
1259 } else if(tag<0 && tag != MPI_ANY_TAG){
1260 retval = MPI_ERR_TAG;
1263 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1264 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1265 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1266 extra->type = TRACING_SSEND;
1268 extra->dst = dst_traced;
1270 extra->datatype1 = encode_datatype(datatype, &known);
1271 int dt_size_send = 1;
1273 dt_size_send = smpi_datatype_size(datatype);
1274 extra->send_size = count*dt_size_send;
1275 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, extra); TRACE_smpi_send(rank, rank, dst_traced,count*smpi_datatype_size(datatype));
1277 smpi_mpi_ssend(buf, count, datatype, dst, tag, comm);
1278 retval = MPI_SUCCESS;
1280 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
1287 int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1288 int dst, int sendtag, void *recvbuf, int recvcount,
1289 MPI_Datatype recvtype, int src, int recvtag,
1290 MPI_Comm comm, MPI_Status * status)
1296 if (comm == MPI_COMM_NULL) {
1297 retval = MPI_ERR_COMM;
1298 } else if (!is_datatype_valid(sendtype)
1299 || !is_datatype_valid(recvtype)) {
1300 retval = MPI_ERR_TYPE;
1301 } else if (src == MPI_PROC_NULL || dst == MPI_PROC_NULL) {
1302 smpi_empty_status(status);
1303 status->MPI_SOURCE = MPI_PROC_NULL;
1304 retval = MPI_SUCCESS;
1305 }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
1306 (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
1307 retval = MPI_ERR_RANK;
1308 } else if (sendcount < 0 || recvcount<0) {
1309 retval = MPI_ERR_COUNT;
1310 } else if ((sendbuf==NULL && sendcount > 0)||(recvbuf==NULL && recvcount>0)) {
1311 retval = MPI_ERR_COUNT;
1312 } else if((sendtag<0 && sendtag != MPI_ANY_TAG)||(recvtag<0 && recvtag != MPI_ANY_TAG)){
1313 retval = MPI_ERR_TAG;
1316 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1317 int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
1318 int src_traced = smpi_group_index(smpi_comm_group(comm), src);
1319 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1320 extra->type = TRACING_SENDRECV;
1321 extra->src = src_traced;
1322 extra->dst = dst_traced;
1324 extra->datatype1 = encode_datatype(sendtype, &known);
1325 int dt_size_send = 1;
1327 dt_size_send = smpi_datatype_size(sendtype);
1328 extra->send_size = sendcount*dt_size_send;
1329 extra->datatype2 = encode_datatype(recvtype, &known);
1330 int dt_size_recv = 1;
1332 dt_size_recv = smpi_datatype_size(recvtype);
1333 extra->recv_size = recvcount*dt_size_recv;
1335 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1336 TRACE_smpi_send(rank, rank, dst_traced,sendcount*smpi_datatype_size(sendtype));
1338 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf,
1339 recvcount, recvtype, src, recvtag, comm, status);
1340 retval = MPI_SUCCESS;
1342 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1343 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_SUCCESS;
1387 int rank = request && (*request)->comm != MPI_COMM_NULL
1388 ? smpi_process_index()
1391 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1392 extra->type = TRACING_TEST;
1393 TRACE_smpi_testing_in(rank, extra);
1395 *flag = smpi_mpi_test(request, status);
1397 TRACE_smpi_testing_out(rank);
1398 retval = MPI_SUCCESS;
1404 int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag,
1405 MPI_Status * status)
1410 if (index == NULL || flag == NULL) {
1411 retval = MPI_ERR_ARG;
1413 *flag = smpi_mpi_testany(count, requests, index, status);
1414 retval = MPI_SUCCESS;
1420 int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* statuses)
1426 retval = MPI_ERR_ARG;
1428 *flag = smpi_mpi_testall(count, requests, statuses);
1429 retval = MPI_SUCCESS;
1435 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
1439 if (status == NULL) {
1440 retval = MPI_ERR_ARG;
1441 } else if (comm == MPI_COMM_NULL) {
1442 retval = MPI_ERR_COMM;
1443 } else if (source == MPI_PROC_NULL) {
1444 smpi_empty_status(status);
1445 status->MPI_SOURCE = MPI_PROC_NULL;
1446 retval = MPI_SUCCESS;
1448 smpi_mpi_probe(source, tag, comm, status);
1449 retval = MPI_SUCCESS;
1456 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
1461 retval = MPI_ERR_ARG;
1462 } else if (status == NULL) {
1463 retval = MPI_ERR_ARG;
1464 } else if (comm == MPI_COMM_NULL) {
1465 retval = MPI_ERR_COMM;
1466 } else if (source == MPI_PROC_NULL) {
1468 smpi_empty_status(status);
1469 status->MPI_SOURCE = MPI_PROC_NULL;
1470 retval = MPI_SUCCESS;
1472 smpi_mpi_iprobe(source, tag, comm, flag, status);
1473 retval = MPI_SUCCESS;
1479 int PMPI_Wait(MPI_Request * request, MPI_Status * status)
1485 smpi_empty_status(status);
1487 if (request == NULL) {
1488 retval = MPI_ERR_ARG;
1489 } else if (*request == MPI_REQUEST_NULL) {
1490 retval = MPI_SUCCESS;
1493 int rank = request && (*request)->comm != MPI_COMM_NULL
1494 ? smpi_process_index()
1497 int src_traced = (*request)->src;
1498 int dst_traced = (*request)->dst;
1499 MPI_Comm comm = (*request)->comm;
1500 int is_wait_for_receive = (*request)->recv;
1501 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1502 extra->type = TRACING_WAIT;
1503 TRACE_smpi_ptp_in(rank, src_traced, dst_traced, __FUNCTION__, extra);
1505 smpi_mpi_wait(request, status);
1506 retval = MPI_SUCCESS;
1508 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1509 TRACE_smpi_ptp_out(rank, src_traced, dst_traced, __FUNCTION__);
1510 if (is_wait_for_receive) {
1511 if(src_traced==MPI_ANY_SOURCE)
1512 src_traced = (status!=MPI_STATUS_IGNORE) ?
1513 smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
1515 TRACE_smpi_recv(rank, src_traced, dst_traced);
1523 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
1529 //save requests information for tracing
1531 int *srcs = xbt_new0(int, count);
1532 int *dsts = xbt_new0(int, count);
1533 int *recvs = xbt_new0(int, count);
1534 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1536 for (i = 0; i < count; i++) {
1537 MPI_Request req = requests[i]; //already received requests are no longer valid
1541 recvs[i] = req->recv;
1542 comms[i] = req->comm;
1545 int rank_traced = smpi_process_index();
1546 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1547 extra->type = TRACING_WAITANY;
1548 extra->send_size=count;
1549 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1551 *index = smpi_mpi_waitany(count, requests, status);
1553 if(*index!=MPI_UNDEFINED){
1554 int src_traced = srcs[*index];
1555 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1556 int dst_traced = dsts[*index];
1557 int is_wait_for_receive = recvs[*index];
1558 if (is_wait_for_receive) {
1559 if(srcs[*index]==MPI_ANY_SOURCE)
1560 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1561 smpi_group_rank(smpi_comm_group(comms[*index]), status->MPI_SOURCE) :
1563 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1565 TRACE_smpi_ptp_out(rank_traced, src_traced, dst_traced, __FUNCTION__);
1576 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
1580 //save information from requests
1582 int *srcs = xbt_new0(int, count);
1583 int *dsts = xbt_new0(int, count);
1584 int *recvs = xbt_new0(int, count);
1585 int *valid = xbt_new0(int, count);
1586 MPI_Comm *comms = xbt_new0(MPI_Comm, count);
1588 //int valid_count = 0;
1589 for (i = 0; i < count; i++) {
1590 MPI_Request req = requests[i];
1591 if(req!=MPI_REQUEST_NULL){
1594 recvs[i] = req->recv;
1595 comms[i] = req->comm;
1601 int rank_traced = smpi_process_index();
1602 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1603 extra->type = TRACING_WAITALL;
1604 extra->send_size=count;
1605 TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra);
1607 int retval = smpi_mpi_waitall(count, requests, status);
1609 for (i = 0; i < count; i++) {
1611 //int src_traced = srcs[*index];
1612 //the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
1613 int src_traced = srcs[i];
1614 int dst_traced = dsts[i];
1615 int is_wait_for_receive = recvs[i];
1616 if (is_wait_for_receive) {
1617 if(src_traced==MPI_ANY_SOURCE)
1618 src_traced = (status!=MPI_STATUSES_IGNORE) ?
1619 smpi_group_rank(smpi_comm_group(comms[i]), status[i].MPI_SOURCE) :
1621 TRACE_smpi_recv(rank_traced, src_traced, dst_traced);
1625 TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__);
1636 int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount,
1637 int *indices, MPI_Status status[])
1642 if (outcount == NULL) {
1643 retval = MPI_ERR_ARG;
1645 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
1646 retval = MPI_SUCCESS;
1652 int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount,
1653 int* indices, MPI_Status status[])
1658 if (outcount == NULL) {
1659 retval = MPI_ERR_ARG;
1661 *outcount = smpi_mpi_testsome(incount, requests, indices, status);
1662 retval = MPI_SUCCESS;
1669 int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
1675 if (comm == MPI_COMM_NULL) {
1676 retval = MPI_ERR_COMM;
1677 } else if (!is_datatype_valid(datatype)) {
1678 retval = MPI_ERR_ARG;
1680 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1681 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1683 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1684 extra->type = TRACING_BCAST;
1685 extra->root = root_traced;
1687 extra->datatype1 = encode_datatype(datatype, &known);
1688 int dt_size_send = 1;
1690 dt_size_send = smpi_datatype_size(datatype);
1691 extra->send_size = count*dt_size_send;
1692 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1694 mpi_coll_bcast_fun(buf, count, datatype, root, comm);
1695 retval = MPI_SUCCESS;
1697 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1704 int PMPI_Barrier(MPI_Comm comm)
1710 if (comm == MPI_COMM_NULL) {
1711 retval = MPI_ERR_COMM;
1713 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1714 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1715 extra->type = TRACING_BARRIER;
1716 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1718 mpi_coll_barrier_fun(comm);
1719 retval = MPI_SUCCESS;
1721 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1728 int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1729 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1730 int root, MPI_Comm comm)
1736 if (comm == MPI_COMM_NULL) {
1737 retval = MPI_ERR_COMM;
1738 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1739 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1740 retval = MPI_ERR_TYPE;
1741 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1742 ((smpi_comm_rank(comm) == root) && (recvcount <0))){
1743 retval = MPI_ERR_COUNT;
1746 char* sendtmpbuf = (char*) sendbuf;
1747 int sendtmpcount = sendcount;
1748 MPI_Datatype sendtmptype = sendtype;
1749 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1751 sendtmptype=recvtype;
1753 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1754 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1755 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1756 extra->type = TRACING_GATHER;
1757 extra->root = root_traced;
1759 extra->datatype1 = encode_datatype(sendtmptype, &known);
1760 int dt_size_send = 1;
1762 dt_size_send = smpi_datatype_size(sendtmptype);
1763 extra->send_size = sendtmpcount*dt_size_send;
1764 extra->datatype2 = encode_datatype(recvtype, &known);
1765 int dt_size_recv = 1;
1766 if((smpi_comm_rank(comm)==root) && !known)
1767 dt_size_recv = smpi_datatype_size(recvtype);
1768 extra->recv_size = recvcount*dt_size_recv;
1770 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__, extra);
1772 mpi_coll_gather_fun(sendtmpbuf, sendtmpcount, sendtmptype, recvbuf, recvcount,
1773 recvtype, root, comm);
1776 retval = MPI_SUCCESS;
1777 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1784 int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1785 void *recvbuf, int *recvcounts, int *displs,
1786 MPI_Datatype recvtype, int root, MPI_Comm comm)
1792 if (comm == MPI_COMM_NULL) {
1793 retval = MPI_ERR_COMM;
1794 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1795 ((smpi_comm_rank(comm) == root) && (recvtype == MPI_DATATYPE_NULL))){
1796 retval = MPI_ERR_TYPE;
1797 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1798 retval = MPI_ERR_COUNT;
1799 } else if (recvcounts == NULL || displs == NULL) {
1800 retval = MPI_ERR_ARG;
1802 char* sendtmpbuf = (char*) sendbuf;
1803 int sendtmpcount = sendcount;
1804 MPI_Datatype sendtmptype = sendtype;
1805 if( (smpi_comm_rank(comm) == root) && (sendbuf == MPI_IN_PLACE )) {
1807 sendtmptype=recvtype;
1810 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1811 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1813 int size = smpi_comm_size(comm);
1814 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1815 extra->type = TRACING_GATHERV;
1816 extra->num_processes = size;
1817 extra->root = root_traced;
1819 extra->datatype1 = encode_datatype(sendtmptype, &known);
1820 int dt_size_send = 1;
1822 dt_size_send = smpi_datatype_size(sendtype);
1823 extra->send_size = sendtmpcount*dt_size_send;
1824 extra->datatype2 = encode_datatype(recvtype, &known);
1825 int dt_size_recv = 1;
1827 dt_size_recv = smpi_datatype_size(recvtype);
1828 if((smpi_comm_rank(comm)==root)){
1829 extra->recvcounts= xbt_new(int,size);
1830 for(i=0; i< size; i++)//copy data to avoid bad free
1831 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
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;
1838 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1845 int PMPI_Allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1846 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1853 if (comm == MPI_COMM_NULL) {
1854 retval = MPI_ERR_COMM;
1855 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1856 (recvtype == MPI_DATATYPE_NULL)){
1857 retval = MPI_ERR_TYPE;
1858 } else if ((( sendbuf != MPI_IN_PLACE) && (sendcount <0)) ||
1860 retval = MPI_ERR_COUNT;
1862 if(sendbuf == MPI_IN_PLACE) {
1863 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*recvcount*smpi_comm_rank(comm);
1864 sendcount=recvcount;
1867 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1868 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1869 extra->type = TRACING_ALLGATHER;
1871 extra->datatype1 = encode_datatype(sendtype, &known);
1872 int dt_size_send = 1;
1874 dt_size_send = smpi_datatype_size(sendtype);
1875 extra->send_size = sendcount*dt_size_send;
1876 extra->datatype2 = encode_datatype(recvtype, &known);
1877 int dt_size_recv = 1;
1879 dt_size_recv = smpi_datatype_size(recvtype);
1880 extra->recv_size = recvcount*dt_size_recv;
1882 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, extra);
1884 mpi_coll_allgather_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1886 retval = MPI_SUCCESS;
1887 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1893 int PMPI_Allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1894 void *recvbuf, int *recvcounts, int *displs,
1895 MPI_Datatype recvtype, MPI_Comm comm)
1901 if (comm == MPI_COMM_NULL) {
1902 retval = MPI_ERR_COMM;
1903 } else if ((( sendbuf != MPI_IN_PLACE) && (sendtype == MPI_DATATYPE_NULL)) ||
1904 (recvtype == MPI_DATATYPE_NULL)){
1905 retval = MPI_ERR_TYPE;
1906 } else if (( sendbuf != MPI_IN_PLACE) && (sendcount <0)){
1907 retval = MPI_ERR_COUNT;
1908 } else if (recvcounts == NULL || displs == NULL) {
1909 retval = MPI_ERR_ARG;
1912 if(sendbuf == MPI_IN_PLACE) {
1913 sendbuf=((char*)recvbuf)+smpi_datatype_get_extent(recvtype)*displs[smpi_comm_rank(comm)];
1914 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->num_processes = size;
1924 extra->datatype1 = encode_datatype(sendtype, &known);
1925 int dt_size_send = 1;
1927 dt_size_send = smpi_datatype_size(sendtype);
1928 extra->send_size = sendcount*dt_size_send;
1929 extra->datatype2 = encode_datatype(recvtype, &known);
1930 int dt_size_recv = 1;
1932 dt_size_recv = smpi_datatype_size(recvtype);
1933 extra->recvcounts= xbt_new(int, size);
1934 for(i=0; i< size; i++)//copy data to avoid bad free
1935 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
1937 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
1939 mpi_coll_allgatherv_fun(sendbuf, sendcount, sendtype, recvbuf, recvcounts,
1940 displs, recvtype, comm);
1941 retval = MPI_SUCCESS;
1942 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
1949 int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1950 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1951 int root, MPI_Comm comm)
1957 if (comm == MPI_COMM_NULL) {
1958 retval = MPI_ERR_COMM;
1959 } else if (((smpi_comm_rank(comm)==root) && (!is_datatype_valid(sendtype)))
1960 || ((recvbuf !=MPI_IN_PLACE) && (!is_datatype_valid(recvtype)))){
1961 retval = MPI_ERR_TYPE;
1962 } else if ((sendbuf == recvbuf) ||
1963 ((smpi_comm_rank(comm)==root) && sendcount>0 && (sendbuf == NULL))){
1964 retval = MPI_ERR_BUFFER;
1967 if (recvbuf == MPI_IN_PLACE) {
1969 recvcount=sendcount;
1971 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
1972 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
1973 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
1974 extra->type = TRACING_SCATTER;
1975 extra->root = root_traced;
1977 extra->datatype1 = encode_datatype(sendtype, &known);
1978 int dt_size_send = 1;
1979 if((smpi_comm_rank(comm)==root) && !known)
1980 dt_size_send = smpi_datatype_size(sendtype);
1981 extra->send_size = sendcount*dt_size_send;
1982 extra->datatype2 = encode_datatype(recvtype, &known);
1983 int dt_size_recv = 1;
1985 dt_size_recv = smpi_datatype_size(recvtype);
1986 extra->recv_size = recvcount*dt_size_recv;
1987 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
1989 mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
1990 recvtype, root, comm);
1991 retval = MPI_SUCCESS;
1992 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
1999 int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
2000 MPI_Datatype sendtype, void *recvbuf, int recvcount,
2001 MPI_Datatype recvtype, int root, MPI_Comm comm)
2007 if (comm == MPI_COMM_NULL) {
2008 retval = MPI_ERR_COMM;
2009 } else if (sendcounts == NULL || displs == NULL) {
2010 retval = MPI_ERR_ARG;
2011 } else if (((smpi_comm_rank(comm)==root) && (sendtype == MPI_DATATYPE_NULL))
2012 || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
2013 retval = MPI_ERR_TYPE;
2015 if (recvbuf == MPI_IN_PLACE) {
2017 recvcount=sendcounts[smpi_comm_rank(comm)];
2019 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2020 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2022 int size = smpi_comm_size(comm);
2023 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2024 extra->type = TRACING_SCATTERV;
2025 extra->num_processes = size;
2026 extra->root = root_traced;
2028 extra->datatype1 = encode_datatype(sendtype, &known);
2029 int dt_size_send = 1;
2031 dt_size_send = smpi_datatype_size(sendtype);
2032 if((smpi_comm_rank(comm)==root)){
2033 extra->sendcounts= xbt_new(int, size);
2034 for(i=0; i< size; i++)//copy data to avoid bad free
2035 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2037 extra->datatype2 = encode_datatype(recvtype, &known);
2038 int dt_size_recv = 1;
2040 dt_size_recv = smpi_datatype_size(recvtype);
2041 extra->recv_size = recvcount*dt_size_recv;
2042 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2044 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
2045 recvcount, recvtype, root, comm);
2047 retval = MPI_SUCCESS;
2048 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2055 int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
2056 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
2062 if (comm == MPI_COMM_NULL) {
2063 retval = MPI_ERR_COMM;
2064 } else if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2065 retval = MPI_ERR_ARG;
2067 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2068 int root_traced = smpi_group_index(smpi_comm_group(comm), root);
2069 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2070 extra->type = TRACING_REDUCE;
2072 extra->datatype1 = encode_datatype(datatype, &known);
2073 int dt_size_send = 1;
2075 dt_size_send = smpi_datatype_size(datatype);
2076 extra->send_size = count*dt_size_send;
2077 extra->root = root_traced;
2079 TRACE_smpi_collective_in(rank, root_traced, __FUNCTION__,extra);
2081 mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
2083 retval = MPI_SUCCESS;
2084 TRACE_smpi_collective_out(rank, root_traced, __FUNCTION__);
2091 int PMPI_Reduce_local(void *inbuf, void *inoutbuf, int count,
2092 MPI_Datatype datatype, MPI_Op op){
2096 if (!is_datatype_valid(datatype) || op == MPI_OP_NULL) {
2097 retval = MPI_ERR_ARG;
2099 smpi_op_apply(op, inbuf, inoutbuf, &count, &datatype);
2106 int PMPI_Allreduce(void *sendbuf, void *recvbuf, int count,
2107 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2113 if (comm == MPI_COMM_NULL) {
2114 retval = MPI_ERR_COMM;
2115 } else if (!is_datatype_valid(datatype)) {
2116 retval = MPI_ERR_TYPE;
2117 } else if (op == MPI_OP_NULL) {
2118 retval = MPI_ERR_OP;
2121 char* sendtmpbuf = (char*) sendbuf;
2122 if( sendbuf == MPI_IN_PLACE ) {
2123 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
2124 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
2126 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2127 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2128 extra->type = TRACING_ALLREDUCE;
2130 extra->datatype1 = encode_datatype(datatype, &known);
2131 int dt_size_send = 1;
2133 dt_size_send = smpi_datatype_size(datatype);
2134 extra->send_size = count*dt_size_send;
2136 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2138 mpi_coll_allreduce_fun(sendtmpbuf, recvbuf, count, datatype, op, comm);
2140 if( sendbuf == MPI_IN_PLACE )
2141 xbt_free(sendtmpbuf);
2143 retval = MPI_SUCCESS;
2144 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2151 int PMPI_Scan(void *sendbuf, void *recvbuf, int count,
2152 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2158 if (comm == MPI_COMM_NULL) {
2159 retval = MPI_ERR_COMM;
2160 } else if (!is_datatype_valid(datatype)) {
2161 retval = MPI_ERR_TYPE;
2162 } else if (op == MPI_OP_NULL) {
2163 retval = MPI_ERR_OP;
2165 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2166 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2167 extra->type = TRACING_SCAN;
2169 extra->datatype1 = encode_datatype(datatype, &known);
2170 int dt_size_send = 1;
2172 dt_size_send = smpi_datatype_size(datatype);
2173 extra->send_size = count*dt_size_send;
2175 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2177 smpi_mpi_scan(sendbuf, recvbuf, count, datatype, op, comm);
2179 retval = MPI_SUCCESS;
2180 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2187 int PMPI_Exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
2188 MPI_Op op, MPI_Comm comm){
2193 if (comm == MPI_COMM_NULL) {
2194 retval = MPI_ERR_COMM;
2195 } else if (!is_datatype_valid(datatype)) {
2196 retval = MPI_ERR_TYPE;
2197 } else if (op == MPI_OP_NULL) {
2198 retval = MPI_ERR_OP;
2200 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2201 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2202 extra->type = TRACING_EXSCAN;
2204 extra->datatype1 = encode_datatype(datatype, &known);
2205 int dt_size_send = 1;
2207 dt_size_send = smpi_datatype_size(datatype);
2208 extra->send_size = count*dt_size_send;
2209 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2211 smpi_mpi_exscan(sendbuf, recvbuf, count, datatype, op, comm);
2212 retval = MPI_SUCCESS;
2213 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2220 int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
2221 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2226 if (comm == MPI_COMM_NULL) {
2227 retval = MPI_ERR_COMM;
2228 } else if (!is_datatype_valid(datatype)) {
2229 retval = MPI_ERR_TYPE;
2230 } else if (op == MPI_OP_NULL) {
2231 retval = MPI_ERR_OP;
2232 } else if (recvcounts == NULL) {
2233 retval = MPI_ERR_ARG;
2235 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2237 int size = smpi_comm_size(comm);
2238 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2239 extra->type = TRACING_REDUCE_SCATTER;
2240 extra->num_processes = size;
2242 extra->datatype1 = encode_datatype(datatype, &known);
2243 int dt_size_send = 1;
2245 dt_size_send = smpi_datatype_size(datatype);
2246 extra->send_size = 0;
2247 extra->recvcounts= xbt_new(int, size);
2248 for(i=0; i< size; i++)//copy data to avoid bad free
2249 extra->recvcounts[i] = recvcounts[i]*dt_size_send;
2250 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2252 void* sendtmpbuf=sendbuf;
2253 if(sendbuf==MPI_IN_PLACE)
2256 mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts,
2257 datatype, op, comm);
2258 retval = MPI_SUCCESS;
2259 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2266 int PMPI_Reduce_scatter_block(void *sendbuf, void *recvbuf, int recvcount,
2267 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
2272 if (comm == MPI_COMM_NULL) {
2273 retval = MPI_ERR_COMM;
2274 } else if (!is_datatype_valid(datatype)) {
2275 retval = MPI_ERR_TYPE;
2276 } else if (op == MPI_OP_NULL) {
2277 retval = MPI_ERR_OP;
2278 } else if (recvcount < 0) {
2279 retval = MPI_ERR_ARG;
2281 int count=smpi_comm_size(comm);
2283 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2284 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2285 extra->type = TRACING_REDUCE_SCATTER;
2286 extra->num_processes = count;
2288 extra->datatype1 = encode_datatype(datatype, &known);
2289 int dt_size_send = 1;
2291 dt_size_send = smpi_datatype_size(datatype);
2292 extra->send_size = 0;
2293 extra->recvcounts= xbt_new(int, count);
2294 for(i=0; i< count; i++)//copy data to avoid bad free
2295 extra->recvcounts[i] = recvcount*dt_size_send;
2297 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2299 int* recvcounts=(int*)xbt_malloc(count);
2300 for (i=0; i<count;i++)recvcounts[i]=recvcount;
2301 mpi_coll_reduce_scatter_fun(sendbuf, recvbuf, recvcounts,
2302 datatype, op, comm);
2303 xbt_free(recvcounts);
2304 retval = MPI_SUCCESS;
2306 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2313 int PMPI_Alltoall(void *sendbuf, int sendcount, MPI_Datatype sendtype,
2314 void *recvbuf, int recvcount, MPI_Datatype recvtype,
2321 if (comm == MPI_COMM_NULL) {
2322 retval = MPI_ERR_COMM;
2323 } else if (sendtype == MPI_DATATYPE_NULL
2324 || recvtype == MPI_DATATYPE_NULL) {
2325 retval = MPI_ERR_TYPE;
2327 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2328 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2329 extra->type = TRACING_ALLTOALL;
2331 extra->datatype1 = encode_datatype(sendtype, &known);
2333 extra->send_size = sendcount*smpi_datatype_size(sendtype);
2335 extra->send_size = sendcount;
2336 extra->datatype2 = encode_datatype(recvtype, &known);
2338 extra->recv_size = recvcount*smpi_datatype_size(recvtype);
2340 extra->recv_size = recvcount;
2341 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2343 retval = mpi_coll_alltoall_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
2345 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2352 int PMPI_Alltoallv(void *sendbuf, int *sendcounts, int *senddisps,
2353 MPI_Datatype sendtype, void *recvbuf, int *recvcounts,
2354 int *recvdisps, MPI_Datatype recvtype, MPI_Comm comm)
2360 if (comm == MPI_COMM_NULL) {
2361 retval = MPI_ERR_COMM;
2362 } else if (sendtype == MPI_DATATYPE_NULL
2363 || recvtype == MPI_DATATYPE_NULL) {
2364 retval = MPI_ERR_TYPE;
2365 } else if (sendcounts == NULL || senddisps == NULL || recvcounts == NULL
2366 || recvdisps == NULL) {
2367 retval = MPI_ERR_ARG;
2369 int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
2371 int size = smpi_comm_size(comm);
2372 instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
2373 extra->type = TRACING_ALLTOALLV;
2374 extra->send_size = 0;
2375 extra->recv_size = 0;
2376 extra->recvcounts= xbt_new(int, size);
2377 extra->sendcounts= xbt_new(int, size);
2379 extra->datatype1 = encode_datatype(sendtype, &known);
2380 int dt_size_send = 1;
2382 dt_size_send = smpi_datatype_size(sendtype);
2383 int dt_size_recv = 1;
2384 extra->datatype2 = encode_datatype(recvtype, &known);
2386 dt_size_recv = smpi_datatype_size(recvtype);
2387 for(i=0; i< size; i++){//copy data to avoid bad free
2388 extra->send_size += sendcounts[i]*dt_size_send;
2389 extra->recv_size += recvcounts[i]*dt_size_recv;
2391 extra->sendcounts[i] = sendcounts[i]*dt_size_send;
2392 extra->recvcounts[i] = recvcounts[i]*dt_size_recv;
2394 extra->num_processes = size;
2395 TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
2398 mpi_coll_alltoallv_fun(sendbuf, sendcounts, senddisps, sendtype,
2399 recvbuf, recvcounts, recvdisps, recvtype,
2401 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2409 int PMPI_Get_processor_name(char *name, int *resultlen)
2411 int retval = MPI_SUCCESS;
2413 strncpy(name, sg_host_get_name(SIMIX_host_self()),
2414 strlen(sg_host_get_name(SIMIX_host_self())) < MPI_MAX_PROCESSOR_NAME - 1 ?
2415 strlen(sg_host_get_name(SIMIX_host_self())) +1 :
2416 MPI_MAX_PROCESSOR_NAME - 1 );
2419 MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
2424 int PMPI_Get_count(MPI_Status * status, MPI_Datatype datatype, int *count)
2426 int retval = MPI_SUCCESS;
2429 if (status == NULL || count == NULL) {
2430 retval = MPI_ERR_ARG;
2431 } else if (!is_datatype_valid(datatype)) {
2432 retval = MPI_ERR_TYPE;
2434 size = smpi_datatype_size(datatype);
2437 } else if (status->count % size != 0) {
2438 retval = MPI_UNDEFINED;
2440 *count = smpi_mpi_get_count(status, datatype);
2446 int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) {
2449 if (old_type == MPI_DATATYPE_NULL) {
2450 retval = MPI_ERR_TYPE;
2451 } else if (count<0){
2452 retval = MPI_ERR_COUNT;
2454 retval = smpi_datatype_contiguous(count, old_type, new_type, 0);
2459 int PMPI_Type_commit(MPI_Datatype* datatype) {
2462 if (datatype == NULL || *datatype == MPI_DATATYPE_NULL) {
2463 retval = MPI_ERR_TYPE;
2465 smpi_datatype_commit(datatype);
2466 retval = MPI_SUCCESS;
2472 int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2475 if (old_type == MPI_DATATYPE_NULL) {
2476 retval = MPI_ERR_TYPE;
2477 } else if (count<0 || blocklen<0){
2478 retval = MPI_ERR_COUNT;
2480 retval = smpi_datatype_vector(count, blocklen, stride, old_type, new_type);
2485 int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2488 if (old_type == MPI_DATATYPE_NULL) {
2489 retval = MPI_ERR_TYPE;
2490 } else if (count<0 || blocklen<0){
2491 retval = MPI_ERR_COUNT;
2493 retval = smpi_datatype_hvector(count, blocklen, stride, old_type, new_type);
2498 int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) {
2499 return MPI_Type_hvector(count, blocklen, stride, old_type, new_type);
2502 int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2505 if (old_type == MPI_DATATYPE_NULL) {
2506 retval = MPI_ERR_TYPE;
2507 } else if (count<0){
2508 retval = MPI_ERR_COUNT;
2510 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2515 int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2518 if (old_type == MPI_DATATYPE_NULL) {
2519 retval = MPI_ERR_TYPE;
2520 } else if (count<0){
2521 retval = MPI_ERR_COUNT;
2523 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2528 int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2531 if (old_type == MPI_DATATYPE_NULL) {
2532 retval = MPI_ERR_TYPE;
2533 } else if (count<0){
2534 retval = MPI_ERR_COUNT;
2536 int* blocklens=(int*)xbt_malloc(blocklength*count);
2537 for (i=0; i<count;i++)blocklens[i]=blocklength;
2538 retval = smpi_datatype_indexed(count, blocklens, indices, old_type, new_type);
2539 xbt_free(blocklens);
2545 int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2548 if (old_type == MPI_DATATYPE_NULL) {
2549 retval = MPI_ERR_TYPE;
2550 } else if (count<0){
2551 retval = MPI_ERR_COUNT;
2553 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2558 int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2559 return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type);
2562 int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) {
2565 if (old_type == MPI_DATATYPE_NULL) {
2566 retval = MPI_ERR_TYPE;
2567 } else if (count<0){
2568 retval = MPI_ERR_COUNT;
2570 int* blocklens=(int*)xbt_malloc(blocklength*count);
2571 for (i=0; i<count;i++)blocklens[i]=blocklength;
2572 retval = smpi_datatype_hindexed(count, blocklens, indices, old_type, new_type);
2573 xbt_free(blocklens);
2579 int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2583 retval = MPI_ERR_COUNT;
2585 retval = smpi_datatype_struct(count, blocklens, indices, old_types, new_type);
2590 int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type) {
2591 return PMPI_Type_struct(count, blocklens, indices, old_types, new_type);
2595 int PMPI_Error_class(int errorcode, int* errorclass) {
2596 // assume smpi uses only standard mpi error codes
2597 *errorclass=errorcode;
2602 int PMPI_Initialized(int* flag) {
2603 *flag=smpi_process_initialized();
2607 /* The topo part of MPI_COMM_WORLD should always be NULL. When other topologies
2608 * will be implemented, not only should we check if the topology is NULL, but
2609 * we should check if it is the good topology type (so we have to add a
2610 * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/
2612 int PMPI_Cart_create(MPI_Comm comm_old, int ndims, int* dims, int* periodic, int reorder, MPI_Comm* comm_cart) {
2614 if (comm_old == MPI_COMM_NULL){
2615 retval = MPI_ERR_COMM;
2616 } else if (ndims < 0 ||
2617 (ndims > 0 && (dims == NULL ||
2618 periodic == NULL)) ||
2619 comm_cart == NULL) {
2620 retval = MPI_ERR_ARG;
2622 retval = smpi_mpi_cart_create(comm_old, ndims, dims, periodic, reorder, comm_cart);
2627 int PMPI_Cart_rank(MPI_Comm comm, int* coords, int* rank) {
2628 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2629 return MPI_ERR_TOPOLOGY;
2631 if (coords == NULL) {
2634 return smpi_mpi_cart_rank(comm, coords, rank);
2637 int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) {
2638 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2639 return MPI_ERR_TOPOLOGY;
2641 if (source == NULL || dest == NULL || direction < 0 ) {
2644 return smpi_mpi_cart_shift(comm, direction, displ, source, dest);
2647 int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) {
2648 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2649 return MPI_ERR_TOPOLOGY;
2651 if (rank < 0 || rank >= smpi_comm_size(comm)) {
2652 return MPI_ERR_RANK;
2657 if(coords == NULL) {
2660 return smpi_mpi_cart_coords(comm, rank, maxdims, coords);
2663 int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coords) {
2664 if(comm == NULL || smpi_comm_topo(comm) == NULL) {
2665 return MPI_ERR_TOPOLOGY;
2667 if(maxdims <= 0 || dims == NULL || periods == NULL || coords == NULL) {
2670 return smpi_mpi_cart_get(comm, maxdims, dims, periods, coords);
2673 int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) {
2674 if (comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2675 return MPI_ERR_TOPOLOGY;
2677 if (ndims == NULL) {
2680 return smpi_mpi_cartdim_get(comm, ndims);
2683 int PMPI_Dims_create(int nnodes, int ndims, int* dims) {
2687 if (ndims < 1 || nnodes < 1) {
2688 return MPI_ERR_DIMS;
2691 return smpi_mpi_dims_create(nnodes, ndims, dims);
2694 int PMPI_Cart_sub(MPI_Comm comm, int* remain_dims, MPI_Comm* comm_new) {
2695 if(comm == MPI_COMM_NULL || smpi_comm_topo(comm) == NULL) {
2696 return MPI_ERR_TOPOLOGY;
2698 if (comm_new == NULL) {
2701 return smpi_mpi_cart_sub(comm, remain_dims, comm_new);
2704 int PMPI_Type_create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
2705 if(oldtype == MPI_DATATYPE_NULL) {
2706 return MPI_ERR_TYPE;
2708 int blocks[3] = { 1, 1, 1 };
2709 MPI_Aint disps[3] = { lb, 0, lb+extent };
2710 MPI_Datatype types[3] = { MPI_LB, oldtype, MPI_UB };
2712 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocks,
2717 smpi_datatype_create(newtype,oldtype->size, lb, lb + extent, 1 , subtype, DT_FLAG_VECTOR);
2719 (*newtype)->flags &= ~DT_FLAG_COMMITED;
2725 int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){
2728 if (comm == MPI_COMM_NULL) {
2729 retval= MPI_ERR_COMM;
2730 }else if ((base == NULL && size != 0)
2731 || disp_unit <= 0 || size < 0 ){
2732 retval= MPI_ERR_OTHER;
2734 *win = smpi_mpi_win_create( base, size, disp_unit, info, comm);
2735 retval = MPI_SUCCESS;
2741 int PMPI_Win_free( MPI_Win* win){
2744 if (win == NULL || *win == MPI_WIN_NULL) {
2745 retval = MPI_ERR_WIN;
2747 retval=smpi_mpi_win_free(win);
2753 int PMPI_Win_set_name(MPI_Win win, char * name)
2756 if (win == MPI_WIN_NULL) {
2757 retval = MPI_ERR_TYPE;
2758 } else if (name == NULL) {
2759 retval = MPI_ERR_ARG;
2761 smpi_mpi_win_set_name(win, name);
2762 retval = MPI_SUCCESS;
2767 int PMPI_Win_get_name(MPI_Win win, char * name, int* len)
2769 int retval = MPI_SUCCESS;
2771 if (win == MPI_WIN_NULL) {
2772 retval = MPI_ERR_WIN;
2773 } else if (name == NULL) {
2774 retval = MPI_ERR_ARG;
2776 smpi_mpi_win_get_name(win, name, len);
2781 int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){
2782 int retval = MPI_SUCCESS;
2783 if (win == MPI_WIN_NULL) {
2784 retval = MPI_ERR_WIN;
2786 smpi_mpi_win_get_group(win, group);
2792 int PMPI_Win_fence( int assert, MPI_Win win){
2795 if (win == MPI_WIN_NULL) {
2796 retval = MPI_ERR_WIN;
2798 int rank = smpi_process_index();
2799 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2800 retval = smpi_mpi_win_fence(assert, win);
2801 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2808 int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2809 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2812 if (win == MPI_WIN_NULL) {
2813 retval = MPI_ERR_WIN;
2814 } else if (target_rank == MPI_PROC_NULL) {
2815 retval = MPI_SUCCESS;
2816 } else if (target_rank <0){
2817 retval = MPI_ERR_RANK;
2818 } else if (target_disp <0){
2819 retval = MPI_ERR_ARG;
2820 } else if (origin_count < 0 || target_count < 0) {
2821 retval = MPI_ERR_COUNT;
2822 } else if (origin_addr==NULL && origin_count > 0){
2823 retval = MPI_ERR_COUNT;
2824 } else if ((!is_datatype_valid(origin_datatype)) ||
2825 (!is_datatype_valid(target_datatype))) {
2826 retval = MPI_ERR_TYPE;
2828 int rank = smpi_process_index();
2830 smpi_mpi_win_get_group(win, &group);
2831 int src_traced = smpi_group_index(group, target_rank);
2832 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2834 retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2836 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2842 int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2843 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){
2846 if (win == MPI_WIN_NULL) {
2847 retval = MPI_ERR_WIN;
2848 } else if (target_rank == MPI_PROC_NULL) {
2849 retval = MPI_SUCCESS;
2850 } else if (target_rank <0){
2851 retval = MPI_ERR_RANK;
2852 } else if (target_disp <0){
2853 retval = MPI_ERR_ARG;
2854 } else if (origin_count < 0 || target_count < 0) {
2855 retval = MPI_ERR_COUNT;
2856 } else if (origin_addr==NULL && origin_count > 0){
2857 retval = MPI_ERR_COUNT;
2858 } else if ((!is_datatype_valid(origin_datatype)) ||
2859 (!is_datatype_valid(target_datatype))) {
2860 retval = MPI_ERR_TYPE;
2862 int rank = smpi_process_index();
2864 smpi_mpi_win_get_group(win, &group);
2865 int dst_traced = smpi_group_index(group, target_rank);
2866 TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, NULL);
2867 TRACE_smpi_send(rank, rank, dst_traced, origin_count*smpi_datatype_size(origin_datatype));
2869 retval = smpi_mpi_put( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win);
2871 TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__);
2878 int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
2879 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
2882 if (win == MPI_WIN_NULL) {
2883 retval = MPI_ERR_WIN;
2884 } else if (target_rank == MPI_PROC_NULL) {
2885 retval = MPI_SUCCESS;
2886 } else if (target_rank <0){
2887 retval = MPI_ERR_RANK;
2888 } else if (target_disp <0){
2889 retval = MPI_ERR_ARG;
2890 } else if (origin_count < 0 || target_count < 0) {
2891 retval = MPI_ERR_COUNT;
2892 } else if (origin_addr==NULL && origin_count > 0){
2893 retval = MPI_ERR_COUNT;
2894 } else if ((!is_datatype_valid(origin_datatype)) ||
2895 (!is_datatype_valid(target_datatype))) {
2896 retval = MPI_ERR_TYPE;
2897 } else if (op == MPI_OP_NULL) {
2898 retval = MPI_ERR_OP;
2900 int rank = smpi_process_index();
2902 smpi_mpi_win_get_group(win, &group);
2903 int src_traced = smpi_group_index(group, target_rank);
2904 TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, NULL);
2906 retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, op, win);
2908 TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__);
2915 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
2918 if (win == MPI_WIN_NULL) {
2919 retval = MPI_ERR_WIN;
2920 } else if (group==MPI_GROUP_NULL){
2921 retval = MPI_ERR_GROUP;
2924 int rank = smpi_process_index();
2925 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2926 retval = smpi_mpi_win_post(group,assert,win);
2927 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2933 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
2936 if (win == MPI_WIN_NULL) {
2937 retval = MPI_ERR_WIN;
2938 } else if (group==MPI_GROUP_NULL){
2939 retval = MPI_ERR_GROUP;
2942 int rank = smpi_process_index();
2943 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2944 retval = smpi_mpi_win_start(group,assert,win);
2945 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2952 int PMPI_Win_complete(MPI_Win win){
2955 if (win == MPI_WIN_NULL) {
2956 retval = MPI_ERR_WIN;
2959 int rank = smpi_process_index();
2960 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2962 retval = smpi_mpi_win_complete(win);
2964 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2970 int PMPI_Win_wait(MPI_Win win){
2973 if (win == MPI_WIN_NULL) {
2974 retval = MPI_ERR_WIN;
2977 int rank = smpi_process_index();
2978 TRACE_smpi_collective_in(rank, -1, __FUNCTION__, NULL);
2980 retval = smpi_mpi_win_wait(win);
2982 TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
2988 int PMPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr){
2989 void *ptr = xbt_malloc(size);
2991 return MPI_ERR_NO_MEM;
2993 *(void **)baseptr = ptr;
2998 int PMPI_Free_mem(void *baseptr){
3003 int PMPI_Type_set_name(MPI_Datatype datatype, char * name)
3006 if (datatype == MPI_DATATYPE_NULL) {
3007 retval = MPI_ERR_TYPE;
3008 } else if (name == NULL) {
3009 retval = MPI_ERR_ARG;
3011 smpi_datatype_set_name(datatype, name);
3012 retval = MPI_SUCCESS;
3017 int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len)
3021 if (datatype == MPI_DATATYPE_NULL) {
3022 retval = MPI_ERR_TYPE;
3023 } else if (name == NULL) {
3024 retval = MPI_ERR_ARG;
3026 smpi_datatype_get_name(datatype, name, len);
3027 retval = MPI_SUCCESS;
3033 MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){
3034 return smpi_type_f2c(datatype);
3037 MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){
3038 return smpi_type_c2f( datatype);
3041 MPI_Group PMPI_Group_f2c(MPI_Fint group){
3042 return smpi_group_f2c( group);
3045 MPI_Fint PMPI_Group_c2f(MPI_Group group){
3046 return smpi_group_c2f(group);
3049 MPI_Request PMPI_Request_f2c(MPI_Fint request){
3050 return smpi_request_f2c(request);
3053 MPI_Fint PMPI_Request_c2f(MPI_Request request) {
3054 return smpi_request_c2f(request);
3057 MPI_Win PMPI_Win_f2c(MPI_Fint win){
3058 return smpi_win_f2c(win);
3061 MPI_Fint PMPI_Win_c2f(MPI_Win win){
3062 return smpi_win_c2f(win);
3065 MPI_Op PMPI_Op_f2c(MPI_Fint op){
3066 return smpi_op_f2c(op);
3069 MPI_Fint PMPI_Op_c2f(MPI_Op op){
3070 return smpi_op_c2f(op);
3073 MPI_Comm PMPI_Comm_f2c(MPI_Fint comm){
3074 return smpi_comm_f2c(comm);
3077 MPI_Fint PMPI_Comm_c2f(MPI_Comm comm){
3078 return smpi_comm_c2f(comm);
3081 MPI_Info PMPI_Info_f2c(MPI_Fint info){
3082 return smpi_info_f2c(info);
3085 MPI_Fint PMPI_Info_c2f(MPI_Info info){
3086 return smpi_info_c2f(info);
3089 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
3090 return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3093 int PMPI_Keyval_free(int* keyval) {
3094 return smpi_comm_keyval_free(keyval);
3097 int PMPI_Attr_delete(MPI_Comm comm, int keyval) {
3098 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3099 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3100 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3102 else if (comm==MPI_COMM_NULL)
3103 return MPI_ERR_COMM;
3105 return smpi_comm_attr_delete(comm, keyval);
3108 int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) {
3110 static int zero = 0;
3111 static int tag_ub = 1000000;
3112 static int last_used_code = MPI_ERR_LASTCODE;
3114 if (comm==MPI_COMM_NULL){
3116 return MPI_ERR_COMM;
3124 *(int**)attr_value = &zero;
3127 case MPI_UNIVERSE_SIZE:
3129 *(int**)attr_value = &smpi_universe_size;
3132 case MPI_LASTUSEDCODE:
3134 *(int**)attr_value = &last_used_code;
3139 *(int**)attr_value = &tag_ub;
3142 case MPI_WTIME_IS_GLOBAL:
3144 *(int**)attr_value = &one;
3148 return smpi_comm_attr_get(comm, keyval, attr_value, flag);
3152 int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) {
3153 if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO
3154 ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM
3155 ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE)
3157 else if (comm==MPI_COMM_NULL)
3158 return MPI_ERR_COMM;
3160 return smpi_comm_attr_put(comm, keyval, attr_value);
3163 int PMPI_Comm_get_attr (MPI_Comm comm, int comm_keyval, void *attribute_val, int *flag)
3165 return PMPI_Attr_get(comm, comm_keyval, attribute_val,flag);
3168 int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val)
3170 return PMPI_Attr_put(comm, comm_keyval, attribute_val);
3173 int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval)
3175 return PMPI_Attr_delete(comm, comm_keyval);
3178 int PMPI_Comm_create_keyval(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3180 return PMPI_Keyval_create(copy_fn, delete_fn, keyval, extra_state);
3183 int PMPI_Comm_free_keyval(int* keyval) {
3184 return PMPI_Keyval_free(keyval);
3188 int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag)
3190 if (type==MPI_DATATYPE_NULL)
3191 return MPI_ERR_TYPE;
3193 return smpi_type_attr_get(type, type_keyval, attribute_val, flag);
3196 int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val)
3198 if (type==MPI_DATATYPE_NULL)
3199 return MPI_ERR_TYPE;
3201 return smpi_type_attr_put(type, type_keyval, attribute_val);
3204 int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
3206 if (type==MPI_DATATYPE_NULL)
3207 return MPI_ERR_TYPE;
3209 return smpi_type_attr_delete(type, type_keyval);
3212 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state)
3214 return smpi_type_keyval_create(copy_fn, delete_fn, keyval, extra_state);
3217 int PMPI_Type_free_keyval(int* keyval) {
3218 return smpi_type_keyval_free(keyval);
3221 int PMPI_Info_create( MPI_Info *info){
3224 *info = xbt_new(s_smpi_mpi_info_t, 1);
3225 (*info)->info_dict= xbt_dict_new_homogeneous(NULL);
3226 (*info)->refcount=1;
3230 int PMPI_Info_set( MPI_Info info, char *key, char *value){
3231 if (info == NULL || key == NULL || value == NULL)
3234 xbt_dict_set(info->info_dict, key, (void*)value, NULL);
3238 int PMPI_Info_free( MPI_Info *info){
3239 if (info == NULL || *info==NULL)
3241 (*info)->refcount--;
3242 if((*info)->refcount==0){
3243 xbt_dict_free(&((*info)->info_dict));
3246 *info=MPI_INFO_NULL;
3250 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;
3256 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3258 memcpy(value,tmpvalue, (strlen(tmpvalue) + 1 < static_cast<size_t>(valuelen)) ?
3259 strlen(tmpvalue) + 1 : valuelen);
3265 int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){
3266 if (info == NULL || newinfo==NULL)
3268 *newinfo = xbt_new(s_smpi_mpi_info_t, 1);
3269 (*newinfo)->info_dict= xbt_dict_new_homogeneous(NULL);
3270 xbt_dict_cursor_t cursor = NULL;
3273 xbt_dict_foreach(info->info_dict,cursor,key,data){
3274 xbt_dict_set((*newinfo)->info_dict, (char*)key, data, NULL);
3279 int PMPI_Info_delete(MPI_Info info, char *key){
3281 if (info == NULL || key==NULL)
3284 xbt_dict_remove(info->info_dict, key);
3287 return MPI_ERR_INFO_NOKEY;
3292 int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){
3293 if (info == NULL || nkeys==NULL)
3295 *nkeys=xbt_dict_size(info->info_dict);
3299 int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){
3300 if (info == NULL || key==NULL || n<0 || n> MPI_MAX_INFO_KEY)
3303 xbt_dict_cursor_t cursor = NULL;
3307 xbt_dict_foreach(info->info_dict,cursor,keyn,data){
3317 int PMPI_Info_get_valuelen( MPI_Info info, char *key, int *valuelen, int *flag){
3319 if (info == NULL || key == NULL || valuelen==NULL || *valuelen <0)
3321 char* tmpvalue=(char*)xbt_dict_get_or_null(info->info_dict, key);
3323 *valuelen=strlen(tmpvalue);
3329 int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) {
3330 if(incount<0 || outcount < 0 || inbuf==NULL || outbuf==NULL)
3332 if(!is_datatype_valid(type))
3333 return MPI_ERR_TYPE;
3334 if(comm==MPI_COMM_NULL)
3335 return MPI_ERR_COMM;
3336 return smpi_mpi_unpack(inbuf, incount, position, outbuf,outcount,type, comm);
3339 int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) {
3340 if(incount<0 || outcount < 0|| inbuf==NULL || outbuf==NULL)
3342 if(!is_datatype_valid(type))
3343 return MPI_ERR_TYPE;
3344 if(comm==MPI_COMM_NULL)
3345 return MPI_ERR_COMM;
3346 return smpi_mpi_pack(inbuf, incount, type, outbuf,outcount,position, comm);
3349 int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) {
3352 if(!is_datatype_valid(datatype))
3353 return MPI_ERR_TYPE;
3354 if(comm==MPI_COMM_NULL)
3355 return MPI_ERR_COMM;
3357 *size=incount*smpi_datatype_size(datatype);
3363 /* The following calls are not yet implemented and will fail at runtime. */
3364 /* Once implemented, please move them above this notice. */
3366 #define NOT_YET_IMPLEMENTED { \
3367 XBT_WARN("Not yet implemented : %s. Please contact the Simgrid team if support is needed", __FUNCTION__); \
3368 return MPI_SUCCESS; \
3371 MPI_Errhandler PMPI_Errhandler_f2c(MPI_Fint errhandler){
3375 MPI_Fint PMPI_Errhandler_c2f(MPI_Errhandler errhandler){
3379 int PMPI_Cart_map(MPI_Comm comm_old, int ndims, int* dims, int* periods, int* newrank) {
3383 int PMPI_Graph_create(MPI_Comm comm_old, int nnodes, int* index, int* edges, int reorder, MPI_Comm* comm_graph) {
3387 int PMPI_Graph_get(MPI_Comm comm, int maxindex, int maxedges, int* index, int* edges) {
3391 int PMPI_Graph_map(MPI_Comm comm_old, int nnodes, int* index, int* edges, int* newrank) {
3395 int PMPI_Graph_neighbors(MPI_Comm comm, int rank, int maxneighbors, int* neighbors) {
3399 int PMPI_Graph_neighbors_count(MPI_Comm comm, int rank, int* nneighbors) {
3403 int PMPI_Graphdims_get(MPI_Comm comm, int* nnodes, int* nedges) {
3407 int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
3411 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
3415 int PMPI_Errhandler_free(MPI_Errhandler* errhandler) {
3419 int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler) {
3423 int PMPI_Error_string(int errorcode, char* string, int* resultlen) {
3427 int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler) {
3431 int PMPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler) {
3435 int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler) {
3439 int PMPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler* errhandler) {
3443 int PMPI_Cancel(MPI_Request* request) {
3447 int PMPI_Buffer_attach(void* buffer, int size) {
3451 int PMPI_Buffer_detach(void* buffer, int* size) {
3455 int PMPI_Comm_test_inter(MPI_Comm comm, int* flag) {
3459 int PMPI_Pcontrol(const int level )
3465 int PMPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm* comm_out) {
3469 int PMPI_Intercomm_merge(MPI_Comm comm, int high, MPI_Comm* comm_out) {
3473 int PMPI_Bsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3477 int PMPI_Bsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3481 int PMPI_Ibsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3485 int PMPI_Comm_remote_group(MPI_Comm comm, MPI_Group* group) {
3489 int PMPI_Comm_remote_size(MPI_Comm comm, int* size) {
3493 int PMPI_Rsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) {
3497 int PMPI_Rsend_init(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3501 int PMPI_Irsend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) {
3505 int PMPI_Test_cancelled(MPI_Status* status, int* flag) {
3511 int PMPI_Pack_external_size(char *datarep, int incount, MPI_Datatype datatype, MPI_Aint *size){
3515 int PMPI_Pack_external(char *datarep, void *inbuf, int incount, MPI_Datatype datatype, void *outbuf, MPI_Aint outcount, MPI_Aint *position){
3519 int PMPI_Unpack_external( char *datarep, void *inbuf, MPI_Aint insize, MPI_Aint *position, void *outbuf, int outcount, MPI_Datatype datatype){
3523 int PMPI_Get_elements(MPI_Status* status, MPI_Datatype datatype, int* elements) {
3529 int PMPI_Type_get_envelope( MPI_Datatype datatype, int *num_integers,
3530 int *num_addresses, int *num_datatypes, int *combiner){
3534 int PMPI_Type_get_contents(MPI_Datatype datatype, int max_integers, int max_addresses,
3535 int max_datatypes, int* array_of_integers, MPI_Aint* array_of_addresses,
3536 MPI_Datatype* array_of_datatypes){
3540 int PMPI_Type_create_darray(int size, int rank, int ndims, int* array_of_gsizes,
3541 int* array_of_distribs, int* array_of_dargs, int* array_of_psizes,
3542 int order, MPI_Datatype oldtype, MPI_Datatype *newtype) {
3546 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){
3550 int PMPI_Type_match_size(int typeclass,int size,MPI_Datatype *datatype){
3554 int PMPI_Alltoallw( void *sendbuf, int *sendcnts, int *sdispls, MPI_Datatype *sendtypes,
3555 void *recvbuf, int *recvcnts, int *rdispls, MPI_Datatype *recvtypes,
3560 int PMPI_Comm_set_name(MPI_Comm comm, char* name){
3564 int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm){
3568 int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm){
3572 int PMPI_Comm_set_info (MPI_Comm comm, MPI_Info info){
3576 int PMPI_Comm_get_info (MPI_Comm comm, MPI_Info* info){
3580 int PMPI_Comm_create_errhandler( MPI_Comm_errhandler_fn *function, MPI_Errhandler *errhandler){
3584 int PMPI_Add_error_class( int *errorclass){
3588 int PMPI_Add_error_code( int errorclass, int *errorcode){
3592 int PMPI_Add_error_string( int errorcode, char *string){
3596 int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){
3600 int PMPI_Request_get_status( MPI_Request request, int *flag, MPI_Status *status){
3604 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){
3608 int PMPI_Grequest_complete( MPI_Request request){
3612 int PMPI_Status_set_cancelled(MPI_Status *status,int flag){
3616 int PMPI_Status_set_elements( MPI_Status *status, MPI_Datatype datatype, int count){
3620 int PMPI_Comm_connect( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3624 int PMPI_Publish_name( char *service_name, MPI_Info info, char *port_name){
3628 int PMPI_Unpublish_name( char *service_name, MPI_Info info, char *port_name){
3632 int PMPI_Lookup_name( char *service_name, MPI_Info info, char *port_name){
3636 int PMPI_Comm_join( int fd, MPI_Comm *intercomm){
3640 int PMPI_Open_port( MPI_Info info, char *port_name){
3644 int PMPI_Close_port(char *port_name){
3648 int PMPI_Comm_accept( char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm){
3652 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){
3656 int PMPI_Comm_spawn_multiple( int count, char **array_of_commands, char*** array_of_argv,
3657 int* array_of_maxprocs, MPI_Info* array_of_info, int root,
3658 MPI_Comm comm, MPI_Comm *intercomm, int* array_of_errcodes){
3662 int PMPI_Comm_get_parent( MPI_Comm *parent){
3666 int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win) {
3670 int PMPI_Win_test(MPI_Win win, int *flag){
3674 int PMPI_Win_unlock(int rank, MPI_Win win){