4 #include "smpi_coll_private.h"
5 #include "smpi_mpi_dt_private.h"
7 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi, smpi,
8 "Logging specific to SMPI (mpi)");
10 /* MPI User level calls */
12 int MPI_Init(int* argc, char*** argv) {
13 smpi_process_init(argc, argv);
14 smpi_bench_begin(NULL);
18 int MPI_Finalize(void) {
20 smpi_process_destroy();
24 int MPI_Init_thread(int* argc, char*** argv, int required, int* provided) {
25 if(provided != NULL) {
26 *provided = MPI_THREAD_MULTIPLE;
28 return MPI_Init(argc, argv);
31 int MPI_Query_thread(int* provided) {
35 if(provided == NULL) {
38 *provided = MPI_THREAD_MULTIPLE;
41 smpi_bench_begin("MPI_Query_thread");
45 int MPI_Is_thread_main(int* flag) {
52 *flag = smpi_process_index() == 0;
55 smpi_bench_begin("MPI_Is_thread_main");
59 int MPI_Abort(MPI_Comm comm, int errorcode) {
61 smpi_process_destroy();
62 // FIXME: should kill all processes in comm instead
63 SIMIX_process_kill(SIMIX_process_self());
67 double MPI_Wtime(void) {
71 time = SIMIX_get_clock();
72 smpi_bench_begin("MPI_Wtime");
76 int MPI_Type_size(MPI_Datatype datatype, size_t* size) {
80 if(datatype == MPI_DATATYPE_NULL) {
81 retval = MPI_ERR_TYPE;
82 } else if(size == NULL) {
85 *size = smpi_datatype_size(datatype);
88 smpi_bench_begin("MPI_Type_size");
92 int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent) {
96 if(datatype == MPI_DATATYPE_NULL) {
97 retval = MPI_ERR_TYPE;
98 } else if(lb == NULL || extent == NULL) {
101 retval = smpi_datatype_extent(datatype, lb, extent);
103 smpi_bench_begin("MPI_Type_get_extent");
107 int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp) {
111 if(datatype == MPI_DATATYPE_NULL) {
112 retval = MPI_ERR_TYPE;
113 } else if(disp == NULL) {
114 retval = MPI_ERR_ARG;
116 *disp = smpi_datatype_lb(datatype);
117 retval = MPI_SUCCESS;
119 smpi_bench_begin("MPI_Type_lb");
123 int MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp) {
127 if(datatype == MPI_DATATYPE_NULL) {
128 retval = MPI_ERR_TYPE;
129 } else if(disp == NULL) {
130 retval = MPI_ERR_ARG;
132 *disp = smpi_datatype_ub(datatype);
133 retval = MPI_SUCCESS;
135 smpi_bench_begin("MPI_Type_ub");
139 int MPI_Op_create(MPI_User_function* function, int commute, MPI_Op* op) {
143 if(function == NULL || op == NULL) {
144 retval = MPI_ERR_ARG;
146 *op = smpi_op_new(function, commute);
147 retval = MPI_SUCCESS;
149 smpi_bench_begin("MPI_Op_create");
153 int MPI_Op_free(MPI_Op* op) {
158 retval = MPI_ERR_ARG;
159 } else if(*op == MPI_OP_NULL) {
162 smpi_op_destroy(*op);
164 retval = MPI_SUCCESS;
166 smpi_bench_begin("MPI_Op_free");
170 int MPI_Group_free(MPI_Group *group) {
175 retval = MPI_ERR_ARG;
177 smpi_group_destroy(*group);
178 *group = MPI_GROUP_NULL;
179 retval = MPI_SUCCESS;
181 smpi_bench_begin("MPI_Group_free");
185 int MPI_Group_size(MPI_Group group, int* size) {
189 if(group == MPI_GROUP_NULL) {
190 retval = MPI_ERR_GROUP;
191 } else if(size == NULL) {
192 retval = MPI_ERR_ARG;
194 *size = smpi_group_size(group);
195 retval = MPI_SUCCESS;
197 smpi_bench_begin("MPI_Group_size");
201 int MPI_Group_rank(MPI_Group group, int* rank) {
205 if(group == MPI_GROUP_NULL) {
206 retval = MPI_ERR_GROUP;
207 } else if(rank == NULL) {
208 retval = MPI_ERR_ARG;
210 *rank = smpi_group_rank(group, smpi_process_index());
211 retval = MPI_SUCCESS;
213 smpi_bench_begin("MPI_Group_rank");
217 int MPI_Group_translate_ranks (MPI_Group group1, int n, int* ranks1, MPI_Group group2, int* ranks2) {
218 int retval, i, index;
221 if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
222 retval = MPI_ERR_GROUP;
224 for(i = 0; i < n; i++) {
225 index = smpi_group_index(group1, ranks1[i]);
226 ranks2[i] = smpi_group_rank(group2, index);
228 retval = MPI_SUCCESS;
230 smpi_bench_begin("MPI_Group_translate_ranks");
234 int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int* result) {
238 if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
239 retval = MPI_ERR_GROUP;
240 } else if(result == NULL) {
241 retval = MPI_ERR_ARG;
243 *result = smpi_group_compare(group1, group2);
244 retval = MPI_SUCCESS;
246 smpi_bench_begin("MPI_Group_compare");
250 int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) {
251 int retval, i, proc1, proc2, size, size2;
254 if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
255 retval = MPI_ERR_GROUP;
256 } else if(newgroup == NULL) {
257 retval = MPI_ERR_ARG;
259 size = smpi_group_size(group1);
260 size2 = smpi_group_size(group2);
261 for(i = 0; i < size2; i++) {
262 proc2 = smpi_group_index(group2, i);
263 proc1 = smpi_group_rank(group1, proc2);
264 if(proc1 == MPI_UNDEFINED) {
269 *newgroup = MPI_GROUP_EMPTY;
271 *newgroup = smpi_group_new(size);
272 size2 = smpi_group_size(group1);
273 for(i = 0; i < size2; i++) {
274 proc1 = smpi_group_index(group1, i);
275 smpi_group_set_mapping(*newgroup, proc1, i);
277 for(i = size2; i < size; i++) {
278 proc2 = smpi_group_index(group2, i - size2);
279 smpi_group_set_mapping(*newgroup, proc2, i);
282 smpi_group_use(*newgroup);
283 retval = MPI_SUCCESS;
285 smpi_bench_begin("MPI_Group_union");
289 int MPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) {
290 int retval, i, proc1, proc2, size, size2;
293 if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
294 retval = MPI_ERR_GROUP;
295 } else if(newgroup == NULL) {
296 retval = MPI_ERR_ARG;
298 size = smpi_group_size(group1);
299 size2 = smpi_group_size(group2);
300 for(i = 0; i < size2; i++) {
301 proc2 = smpi_group_index(group2, i);
302 proc1 = smpi_group_rank(group1, proc2);
303 if(proc1 == MPI_UNDEFINED) {
308 *newgroup = MPI_GROUP_EMPTY;
310 *newgroup = smpi_group_new(size);
311 size2 = smpi_group_size(group1);
312 for(i = 0; i < size2; i++) {
313 proc1 = smpi_group_index(group1, i);
314 proc2 = smpi_group_rank(group2, proc1);
315 if(proc2 != MPI_UNDEFINED) {
316 smpi_group_set_mapping(*newgroup, proc1, i);
320 smpi_group_use(*newgroup);
321 retval = MPI_SUCCESS;
323 smpi_bench_begin("MPI_Group_intersection");
327 int MPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) {
328 int retval, i, proc1, proc2, size, size2;
331 if(group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) {
332 retval = MPI_ERR_GROUP;
333 } else if(newgroup == NULL) {
334 retval = MPI_ERR_ARG;
336 size = size2 = smpi_group_size(group1);
337 for(i = 0; i < size2; i++) {
338 proc1 = smpi_group_index(group1, i);
339 proc2 = smpi_group_rank(group2, proc1);
340 if(proc2 != MPI_UNDEFINED) {
345 *newgroup = MPI_GROUP_EMPTY;
347 *newgroup = smpi_group_new(size);
348 for(i = 0; i < size2; i++) {
349 proc1 = smpi_group_index(group1, i);
350 proc2 = smpi_group_rank(group2, proc1);
351 if(proc2 == MPI_UNDEFINED) {
352 smpi_group_set_mapping(*newgroup, proc1, i);
356 smpi_group_use(*newgroup);
357 retval = MPI_SUCCESS;
359 smpi_bench_begin("MPI_Group_difference");
363 int MPI_Group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) {
364 int retval, i, index;
367 if(group == MPI_GROUP_NULL) {
368 retval = MPI_ERR_GROUP;
369 } else if(newgroup == NULL) {
370 retval = MPI_ERR_ARG;
373 *newgroup = MPI_GROUP_EMPTY;
374 } else if(n == smpi_group_size(group)) {
377 *newgroup = smpi_group_new(n);
378 for(i = 0; i < n; i++) {
379 index = smpi_group_index(group, ranks[i]);
380 smpi_group_set_mapping(*newgroup, index, i);
383 smpi_group_use(*newgroup);
384 retval = MPI_SUCCESS;
386 smpi_bench_begin("MPI_Group_incl");
390 int MPI_Group_excl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) {
391 int retval, i, size, rank, index;
394 if(group == MPI_GROUP_NULL) {
395 retval = MPI_ERR_GROUP;
396 } else if(newgroup == NULL) {
397 retval = MPI_ERR_ARG;
401 } else if(n == smpi_group_size(group)) {
402 *newgroup = MPI_GROUP_EMPTY;
404 size = smpi_group_size(group) - n;
405 *newgroup = smpi_group_new(size);
408 for(i = 0; i < n; i++) {
409 if(ranks[i] == rank) {
414 index = smpi_group_index(group, rank);
415 smpi_group_set_mapping(*newgroup, index, rank);
420 smpi_group_use(*newgroup);
421 retval = MPI_SUCCESS;
423 smpi_bench_begin("MPI_Group_excl");
427 int MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group* newgroup) {
428 int retval, i, j, rank, size, index;
431 if(group == MPI_GROUP_NULL) {
432 retval = MPI_ERR_GROUP;
433 } else if(newgroup == NULL) {
434 retval = MPI_ERR_ARG;
437 *newgroup = MPI_GROUP_EMPTY;
440 for(i = 0; i < n; i++) {
441 for(rank = ranges[i][0]; /* First */
442 rank >= 0 && rank <= ranges[i][1]; /* Last */
443 rank += ranges[i][2] /* Stride */) {
447 if(size == smpi_group_size(group)) {
450 *newgroup = smpi_group_new(size);
452 for(i = 0; i < n; i++) {
453 for(rank = ranges[i][0]; /* First */
454 rank >= 0 && rank <= ranges[i][1]; /* Last */
455 rank += ranges[i][2] /* Stride */) {
456 index = smpi_group_index(group, rank);
457 smpi_group_set_mapping(*newgroup, index, j);
463 smpi_group_use(*newgroup);
464 retval = MPI_SUCCESS;
466 smpi_bench_begin("MPI_Group_range_incl");
470 int MPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group* newgroup) {
471 int retval, i, newrank, rank, size, index, add;
474 if(group == MPI_GROUP_NULL) {
475 retval = MPI_ERR_GROUP;
476 } else if(newgroup == NULL) {
477 retval = MPI_ERR_ARG;
482 size = smpi_group_size(group);
483 for(i = 0; i < n; i++) {
484 for(rank = ranges[i][0]; /* First */
485 rank >= 0 && rank <= ranges[i][1]; /* Last */
486 rank += ranges[i][2] /* Stride */) {
491 *newgroup = MPI_GROUP_EMPTY;
493 *newgroup = smpi_group_new(size);
495 while(newrank < size) {
496 for(i = 0; i < n; i++) {
498 for(rank = ranges[i][0]; /* First */
499 rank >= 0 && rank <= ranges[i][1]; /* Last */
500 rank += ranges[i][2] /* Stride */) {
501 if(rank == newrank) {
507 index = smpi_group_index(group, newrank);
508 smpi_group_set_mapping(*newgroup, index, newrank);
514 smpi_group_use(*newgroup);
515 retval = MPI_SUCCESS;
517 smpi_bench_begin("MPI_Group_range_excl");
521 int MPI_Comm_rank(MPI_Comm comm, int* rank) {
525 if(comm == MPI_COMM_NULL) {
526 retval = MPI_ERR_COMM;
528 *rank = smpi_comm_rank(comm);
529 retval = MPI_SUCCESS;
531 smpi_bench_begin("MPI_Comm_rank");
535 int MPI_Comm_size(MPI_Comm comm, int* size) {
539 if(comm == MPI_COMM_NULL) {
540 retval = MPI_ERR_COMM;
541 } else if(size == NULL) {
542 retval = MPI_ERR_ARG;
544 *size = smpi_comm_size(comm);
545 retval = MPI_SUCCESS;
547 smpi_bench_begin("MPI_Comm_size");
551 int MPI_Comm_group(MPI_Comm comm, MPI_Group* group) {
555 if(comm == MPI_COMM_NULL) {
556 retval = MPI_ERR_COMM;
557 } else if(group == NULL) {
558 retval = MPI_ERR_ARG;
560 *group = smpi_comm_group(comm);
561 retval = MPI_SUCCESS;
563 smpi_bench_begin("MPI_Comm_group");
567 int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int* result) {
571 if(comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) {
572 retval = MPI_ERR_COMM;
573 } else if(result == NULL) {
574 retval = MPI_ERR_ARG;
576 if(comm1 == comm2) { /* Same communicators means same groups */
579 *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
580 if(*result == MPI_IDENT) {
581 *result = MPI_CONGRUENT;
584 retval = MPI_SUCCESS;
586 smpi_bench_begin("MPI_Comm_compare");
590 int MPI_Comm_dup(MPI_Comm comm, MPI_Comm* newcomm) {
594 if(comm == MPI_COMM_NULL) {
595 retval = MPI_ERR_COMM;
596 } else if(newcomm == NULL) {
597 retval = MPI_ERR_ARG;
599 *newcomm = smpi_comm_new(smpi_comm_group(comm));
600 retval = MPI_SUCCESS;
602 smpi_bench_begin("MPI_Comm_dup");
606 int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm* newcomm) {
610 if(comm == MPI_COMM_NULL) {
611 retval = MPI_ERR_COMM;
612 } else if(group == MPI_GROUP_NULL) {
613 retval = MPI_ERR_GROUP;
614 } else if(newcomm == NULL) {
615 retval = MPI_ERR_ARG;
617 *newcomm = smpi_comm_new(group);
618 retval = MPI_SUCCESS;
620 smpi_bench_begin("MPI_Comm_create");
624 int MPI_Comm_free(MPI_Comm* comm) {
629 retval = MPI_ERR_ARG;
630 } else if(*comm == MPI_COMM_NULL) {
631 retval = MPI_ERR_COMM;
633 smpi_comm_destroy(*comm);
634 *comm = MPI_COMM_NULL;
635 retval = MPI_SUCCESS;
637 smpi_bench_begin("MPI_Comm_free");
641 int MPI_Irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request) {
645 if(request == NULL) {
646 retval = MPI_ERR_ARG;
648 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
649 retval = MPI_SUCCESS;
651 smpi_bench_begin("MPI_Irecv");
655 int MPI_Isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
659 if(request == NULL) {
660 retval = MPI_ERR_ARG;
662 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
663 retval = MPI_SUCCESS;
665 smpi_bench_begin("MPI_Isend");
669 int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status) {
671 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
672 smpi_bench_begin("MPI_Recv");
676 int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
678 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
679 smpi_bench_begin("MPI_Send");
683 int MPI_Sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status) {
685 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm, status);
686 smpi_bench_begin("MPI_Sendrecv");
690 int MPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst, int sendtag, int src, int recvtag, MPI_Comm comm, MPI_Status* status) {
691 //TODO: suboptimal implementation
695 size = smpi_datatype_size(datatype) * count;
696 recvbuf = xbt_new(char, size);
697 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
698 memcpy(buf, recvbuf, size * sizeof(char));
703 int MPI_Test(MPI_Request* request, int* flag, MPI_Status* status) {
707 if(request == NULL || flag == NULL) {
708 retval = MPI_ERR_ARG;
709 } else if(*request == MPI_REQUEST_NULL) {
710 retval = MPI_ERR_REQUEST;
712 *flag = smpi_mpi_test(request, status);
713 retval = MPI_SUCCESS;
715 smpi_bench_begin("MPI_Test");
719 int MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_Status* status) {
723 if(index == NULL || flag == NULL) {
724 retval = MPI_ERR_ARG;
726 *flag = smpi_mpi_testany(count, requests, index, status);
727 retval = MPI_SUCCESS;
729 smpi_bench_begin("MPI_Testany");
733 int MPI_Wait(MPI_Request* request, MPI_Status* status) {
737 if(request == NULL) {
738 retval = MPI_ERR_ARG;
739 } else if(*request == MPI_REQUEST_NULL) {
740 retval = MPI_ERR_REQUEST;
742 smpi_mpi_wait(request, status);
743 retval = MPI_SUCCESS;
745 smpi_bench_begin("MPI_Wait");
749 int MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* status) {
754 retval = MPI_ERR_ARG;
756 *index = smpi_mpi_waitany(count, requests, status);
757 retval = MPI_SUCCESS;
759 smpi_bench_begin("MPI_Waitany");
763 int MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]) {
765 smpi_mpi_waitall(count, requests, status);
766 smpi_bench_begin("MPI_Waitall");
770 int MPI_Waitsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[]) {
774 if(outcount == NULL || indices == NULL) {
775 retval = MPI_ERR_ARG;
777 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
778 retval = MPI_SUCCESS;
780 smpi_bench_begin("MPI_Waitsome");
784 int MPI_Bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
788 if(comm == MPI_COMM_NULL) {
789 retval = MPI_ERR_COMM;
791 smpi_mpi_bcast(buf, count, datatype, root, comm);
792 retval = MPI_SUCCESS;
794 smpi_bench_begin("MPI_Bcast");
798 int MPI_Barrier(MPI_Comm comm) {
802 if(comm == MPI_COMM_NULL) {
803 retval = MPI_ERR_COMM;
805 smpi_mpi_barrier(comm);
806 retval = MPI_SUCCESS;
808 smpi_bench_begin("MPI_Barrier");
812 int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
816 if(comm == MPI_COMM_NULL) {
817 retval = MPI_ERR_COMM;
818 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
819 retval = MPI_ERR_TYPE;
821 smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
822 retval = MPI_SUCCESS;
824 smpi_bench_begin("MPI_Gather");
828 int MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm) {
832 if(comm == MPI_COMM_NULL) {
833 retval = MPI_ERR_COMM;
834 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
835 retval = MPI_ERR_TYPE;
836 } else if(recvcounts == NULL || displs == NULL) {
837 retval = MPI_ERR_ARG;
839 smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm);
840 retval = MPI_SUCCESS;
842 smpi_bench_begin("MPI_Gatherv");
846 int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
850 if(comm == MPI_COMM_NULL) {
851 retval = MPI_ERR_COMM;
852 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
853 retval = MPI_ERR_TYPE;
855 smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
856 retval = MPI_SUCCESS;
858 smpi_bench_begin("MPI_Allgather");
862 int MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm) {
866 if(comm == MPI_COMM_NULL) {
867 retval = MPI_ERR_COMM;
868 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
869 retval = MPI_ERR_TYPE;
870 } else if(recvcounts == NULL || displs == NULL) {
871 retval = MPI_ERR_ARG;
873 smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
874 retval = MPI_SUCCESS;
876 smpi_bench_begin("MPI_Allgatherv");
880 int MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
884 if(comm == MPI_COMM_NULL) {
885 retval = MPI_ERR_COMM;
886 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
887 retval = MPI_ERR_TYPE;
889 smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
890 retval = MPI_SUCCESS;
892 smpi_bench_begin("MPI_Scatter");
896 int MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
900 if(comm == MPI_COMM_NULL) {
901 retval = MPI_ERR_COMM;
902 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
903 retval = MPI_ERR_TYPE;
904 } else if(sendcounts == NULL || displs == NULL) {
905 retval = MPI_ERR_ARG;
907 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
908 retval = MPI_SUCCESS;
910 smpi_bench_begin("MPI_Scatterv");
914 int MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) {
918 if(comm == MPI_COMM_NULL) {
919 retval = MPI_ERR_COMM;
920 } else if(datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
921 retval = MPI_ERR_ARG;
923 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
924 retval = MPI_SUCCESS;
926 smpi_bench_begin("MPI_Reduce");
930 int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
934 if(comm == MPI_COMM_NULL) {
935 retval = MPI_ERR_COMM;
936 } else if(datatype == MPI_DATATYPE_NULL) {
937 retval = MPI_ERR_TYPE;
938 } else if(op == MPI_OP_NULL) {
941 smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
942 retval = MPI_SUCCESS;
944 smpi_bench_begin("MPI_Allreduce");
948 int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
949 int retval, i, rank, size, count;
953 if(comm == MPI_COMM_NULL) {
954 retval = MPI_ERR_COMM;
955 } else if(datatype == MPI_DATATYPE_NULL) {
956 retval = MPI_ERR_TYPE;
957 } else if(op == MPI_OP_NULL) {
959 } else if(recvcounts == NULL) {
960 retval = MPI_ERR_ARG;
962 /* arbitrarily choose root as rank 0 */
963 /* TODO: faster direct implementation ? */
964 rank = smpi_comm_rank(comm);
965 size = smpi_comm_size(comm);
967 displs = xbt_new(int, size);
968 for(i = 0; i < size; i++) {
969 count += recvcounts[i];
972 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
973 smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
975 retval = MPI_SUCCESS;
977 smpi_bench_begin("MPI_Reduce_scatter");
982 * MPI_Alltoall user entry point
984 * Uses the logic of OpenMPI (upto 1.2.7 or greater) for the optimizations
985 * ompi/mca/coll/tuned/coll_tuned_module.c
988 int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
989 int retval, size, sendsize;
992 if(comm == MPI_COMM_NULL) {
993 retval = MPI_ERR_COMM;
994 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
995 retval = MPI_ERR_TYPE;
997 size = smpi_comm_size(comm);
998 sendsize = smpi_datatype_size(sendtype) * sendcount;
999 if(sendsize < 200 && size > 12) {
1000 retval = smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1001 } else if(sendsize < 3000) {
1002 retval = smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1004 retval = smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1007 smpi_bench_begin("MPI_Alltoall");
1011 int MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm) {
1015 if(comm == MPI_COMM_NULL) {
1016 retval = MPI_ERR_COMM;
1017 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
1018 retval = MPI_ERR_TYPE;
1019 } else if(sendcounts == NULL || senddisps == NULL || recvcounts == NULL || recvdisps == NULL) {
1020 retval = MPI_ERR_ARG;
1022 retval = smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm);
1024 smpi_bench_begin("MPI_Alltoallv");