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(-1, NULL);
18 int MPI_Finalize(void) {
19 smpi_bench_end(-1, NULL);
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) {
34 smpi_bench_end(-1, NULL);
35 if(provided == NULL) {
38 *provided = MPI_THREAD_MULTIPLE;
41 smpi_bench_begin(-1, NULL);
45 int MPI_Is_thread_main(int* flag) {
48 smpi_bench_end(-1, NULL);
52 *flag = smpi_process_index() == 0;
55 smpi_bench_begin(-1, NULL);
59 int MPI_Abort(MPI_Comm comm, int errorcode) {
60 smpi_bench_end(-1, NULL);
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) {
70 smpi_bench_end(-1, NULL);
71 time = SIMIX_get_clock();
72 smpi_bench_begin(-1, NULL);
76 int MPI_Type_size(MPI_Datatype datatype, size_t* size) {
79 smpi_bench_end(-1, NULL);
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(-1, NULL);
92 int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint* lb, MPI_Aint* extent) {
95 smpi_bench_end(-1, NULL);
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(-1, NULL);
107 int MPI_Type_lb(MPI_Datatype datatype, MPI_Aint* disp) {
110 smpi_bench_end(-1, NULL);
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(-1, NULL);
123 int MPI_Type_ub(MPI_Datatype datatype, MPI_Aint* disp) {
126 smpi_bench_end(-1, NULL);
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(-1, NULL);
139 int MPI_Op_create(MPI_User_function* function, int commute, MPI_Op* op) {
142 smpi_bench_end(-1, NULL);
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(-1, NULL);
153 int MPI_Op_free(MPI_Op* op) {
156 smpi_bench_end(-1, NULL);
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(-1, NULL);
170 int MPI_Group_free(MPI_Group *group) {
173 smpi_bench_end(-1, NULL);
175 retval = MPI_ERR_ARG;
177 smpi_group_destroy(*group);
178 *group = MPI_GROUP_NULL;
179 retval = MPI_SUCCESS;
181 smpi_bench_begin(-1, NULL);
185 int MPI_Group_size(MPI_Group group, int* size) {
188 smpi_bench_end(-1, NULL);
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(-1, NULL);
201 int MPI_Group_rank(MPI_Group group, int* rank) {
204 smpi_bench_end(-1, NULL);
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(-1, NULL);
217 int MPI_Group_translate_ranks (MPI_Group group1, int n, int* ranks1, MPI_Group group2, int* ranks2) {
218 int retval, i, index;
220 smpi_bench_end(-1, NULL);
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(-1, NULL);
234 int MPI_Group_compare(MPI_Group group1, MPI_Group group2, int* result) {
237 smpi_bench_end(-1, NULL);
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(-1, NULL);
250 int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) {
251 int retval, i, proc1, proc2, size, size2;
253 smpi_bench_end(-1, NULL);
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(-1, NULL);
289 int MPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) {
290 int retval, i, proc1, proc2, size, size2;
292 smpi_bench_end(-1, NULL);
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(-1, NULL);
327 int MPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group* newgroup) {
328 int retval, i, proc1, proc2, size, size2;
330 smpi_bench_end(-1, NULL);
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(-1, NULL);
363 int MPI_Group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) {
364 int retval, i, index;
366 smpi_bench_end(-1, NULL);
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(-1, NULL);
390 int MPI_Group_excl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup) {
391 int retval, i, size, rank, index;
393 smpi_bench_end(-1, NULL);
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(-1, NULL);
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;
430 smpi_bench_end(-1, NULL);
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(-1, NULL);
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;
473 smpi_bench_end(-1, NULL);
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(-1, NULL);
521 int MPI_Comm_rank(MPI_Comm comm, int* rank) {
524 smpi_bench_end(-1, NULL);
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(-1, NULL);
535 int MPI_Comm_size(MPI_Comm comm, int* size) {
538 smpi_bench_end(-1, NULL);
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(-1, NULL);
551 int MPI_Comm_group(MPI_Comm comm, MPI_Group* group) {
554 smpi_bench_end(-1, NULL);
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(-1, NULL);
567 int MPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int* result) {
570 smpi_bench_end(-1, NULL);
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(-1, NULL);
590 int MPI_Comm_dup(MPI_Comm comm, MPI_Comm* newcomm) {
593 smpi_bench_end(-1, NULL);
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(-1, NULL);
606 int MPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm* newcomm) {
609 smpi_bench_end(-1, NULL);
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(-1, NULL);
624 int MPI_Comm_free(MPI_Comm* comm) {
627 smpi_bench_end(-1, NULL);
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(-1, NULL);
641 int MPI_Irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request* request) {
643 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
645 smpi_bench_end(rank, "Irecv");
646 if(request == NULL) {
647 retval = MPI_ERR_ARG;
648 } else if (comm == MPI_COMM_NULL) {
649 retval = MPI_ERR_COMM;
651 *request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
652 retval = MPI_SUCCESS;
654 smpi_bench_begin(rank, "Irecv");
658 int MPI_Isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) {
660 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
662 smpi_bench_end(rank, "Isend");
663 if(request == NULL) {
664 retval = MPI_ERR_ARG;
665 } else if (comm == MPI_COMM_NULL) {
666 retval = MPI_ERR_COMM;
668 *request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
669 retval = MPI_SUCCESS;
671 smpi_bench_begin(rank, "Isend");
675 int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status) {
677 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
679 smpi_bench_end(rank, "Recv");
680 if (comm == MPI_COMM_NULL) {
681 retval = MPI_ERR_COMM;
683 smpi_mpi_recv(buf, count, datatype, src, tag, comm, status);
684 retval = MPI_SUCCESS;
686 smpi_bench_begin(rank, "Recv");
690 int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) {
692 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
694 smpi_bench_end(rank, "Send");
695 if (comm == MPI_COMM_NULL) {
696 retval = MPI_ERR_COMM;
698 smpi_mpi_send(buf, count, datatype, dst, tag, comm);
699 retval = MPI_SUCCESS;
701 smpi_bench_begin(rank, "Send");
705 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) {
707 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
709 smpi_bench_end(rank, "Sendrecv");
710 if (comm == MPI_COMM_NULL) {
711 retval = MPI_ERR_COMM;
712 } else if (sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
713 retval = MPI_ERR_TYPE;
715 smpi_mpi_sendrecv(sendbuf, sendcount, sendtype, dst, sendtag, recvbuf, recvcount, recvtype, src, recvtag, comm, status);
716 retval = MPI_SUCCESS;
718 smpi_bench_begin(rank, "Sendrecv");
722 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) {
723 //TODO: suboptimal implementation
727 size = smpi_datatype_size(datatype) * count;
728 recvbuf = xbt_new(char, size);
729 retval = MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count, datatype, src, recvtag, comm, status);
730 memcpy(buf, recvbuf, size * sizeof(char));
735 int MPI_Test(MPI_Request* request, int* flag, MPI_Status* status) {
737 int rank = request && (*request)->comm != MPI_COMM_NULL
738 ? smpi_comm_rank((*request)->comm)
741 smpi_bench_end(rank, "Test");
742 if(request == NULL || flag == NULL) {
743 retval = MPI_ERR_ARG;
744 } else if(*request == MPI_REQUEST_NULL) {
745 retval = MPI_ERR_REQUEST;
747 *flag = smpi_mpi_test(request, status);
748 retval = MPI_SUCCESS;
750 smpi_bench_begin(rank, "Test");
754 int MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_Status* status) {
757 smpi_bench_end(-1, NULL); //FIXME
758 if(index == NULL || flag == NULL) {
759 retval = MPI_ERR_ARG;
761 *flag = smpi_mpi_testany(count, requests, index, status);
762 retval = MPI_SUCCESS;
764 smpi_bench_begin(-1, NULL);
768 int MPI_Wait(MPI_Request* request, MPI_Status* status) {
770 int rank = request && (*request)->comm != MPI_COMM_NULL
771 ? smpi_comm_rank((*request)->comm)
774 smpi_bench_end(rank, "Wait");
775 if(request == NULL) {
776 retval = MPI_ERR_ARG;
777 } else if(*request == MPI_REQUEST_NULL) {
778 retval = MPI_ERR_REQUEST;
780 smpi_mpi_wait(request, status);
781 retval = MPI_SUCCESS;
783 smpi_bench_begin(rank, "Wait");
787 int MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* status) {
790 smpi_bench_end(-1, NULL); //FIXME
792 retval = MPI_ERR_ARG;
794 *index = smpi_mpi_waitany(count, requests, status);
795 retval = MPI_SUCCESS;
797 smpi_bench_begin(-1, NULL);
801 int MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]) {
802 smpi_bench_end(-1, NULL); //FIXME
803 smpi_mpi_waitall(count, requests, status);
804 smpi_bench_begin(-1, NULL);
808 int MPI_Waitsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[]) {
811 smpi_bench_end(-1, NULL); //FIXME
812 if(outcount == NULL || indices == NULL) {
813 retval = MPI_ERR_ARG;
815 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
816 retval = MPI_SUCCESS;
818 smpi_bench_begin(-1, NULL);
822 int MPI_Bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
824 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
826 smpi_bench_end(rank, "Bcast");
827 if(comm == MPI_COMM_NULL) {
828 retval = MPI_ERR_COMM;
830 smpi_mpi_bcast(buf, count, datatype, root, comm);
831 retval = MPI_SUCCESS;
833 smpi_bench_begin(rank, "Bcast");
837 int MPI_Barrier(MPI_Comm comm) {
839 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
841 smpi_bench_end(rank, "Barrier");
842 if(comm == MPI_COMM_NULL) {
843 retval = MPI_ERR_COMM;
845 smpi_mpi_barrier(comm);
846 retval = MPI_SUCCESS;
848 smpi_bench_begin(rank, "Barrier");
852 int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
854 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
856 smpi_bench_end(rank, "Gather");
857 if(comm == MPI_COMM_NULL) {
858 retval = MPI_ERR_COMM;
859 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
860 retval = MPI_ERR_TYPE;
862 smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
863 retval = MPI_SUCCESS;
865 smpi_bench_begin(rank, "Gather");
869 int MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm) {
871 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
873 smpi_bench_end(rank, "Gatherv");
874 if(comm == MPI_COMM_NULL) {
875 retval = MPI_ERR_COMM;
876 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
877 retval = MPI_ERR_TYPE;
878 } else if(recvcounts == NULL || displs == NULL) {
879 retval = MPI_ERR_ARG;
881 smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm);
882 retval = MPI_SUCCESS;
884 smpi_bench_begin(rank, "Gatherv");
888 int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
890 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
892 smpi_bench_end(rank, "Allgather");
893 if(comm == MPI_COMM_NULL) {
894 retval = MPI_ERR_COMM;
895 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
896 retval = MPI_ERR_TYPE;
898 smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
899 retval = MPI_SUCCESS;
901 smpi_bench_begin(rank, "Allgather");
905 int MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm) {
907 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
909 smpi_bench_end(rank, "Allgatherv");
910 if(comm == MPI_COMM_NULL) {
911 retval = MPI_ERR_COMM;
912 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
913 retval = MPI_ERR_TYPE;
914 } else if(recvcounts == NULL || displs == NULL) {
915 retval = MPI_ERR_ARG;
917 smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
918 retval = MPI_SUCCESS;
920 smpi_bench_begin(rank, "Allgatherv");
924 int MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
926 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
928 smpi_bench_end(rank, "Scatter");
929 if(comm == MPI_COMM_NULL) {
930 retval = MPI_ERR_COMM;
931 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
932 retval = MPI_ERR_TYPE;
934 smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
935 retval = MPI_SUCCESS;
937 smpi_bench_begin(rank, "Scatter");
941 int MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
943 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
945 smpi_bench_end(rank, "Scatterv");
946 if(comm == MPI_COMM_NULL) {
947 retval = MPI_ERR_COMM;
948 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
949 retval = MPI_ERR_TYPE;
950 } else if(sendcounts == NULL || displs == NULL) {
951 retval = MPI_ERR_ARG;
953 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
954 retval = MPI_SUCCESS;
956 smpi_bench_begin(rank, "Scatterv");
960 int MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) {
962 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
964 smpi_bench_end(rank, "Reduce");
965 if(comm == MPI_COMM_NULL) {
966 retval = MPI_ERR_COMM;
967 } else if(datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
968 retval = MPI_ERR_ARG;
970 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
971 retval = MPI_SUCCESS;
973 smpi_bench_begin(rank, "Reduce");
977 int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
979 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
981 smpi_bench_end(rank, "Allreduce");
982 if(comm == MPI_COMM_NULL) {
983 retval = MPI_ERR_COMM;
984 } else if(datatype == MPI_DATATYPE_NULL) {
985 retval = MPI_ERR_TYPE;
986 } else if(op == MPI_OP_NULL) {
989 smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
990 retval = MPI_SUCCESS;
992 smpi_bench_begin(rank, "Allreduce");
996 int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
997 int retval, i, size, count;
999 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1001 smpi_bench_end(rank, "Reduce_scatter");
1002 if(comm == MPI_COMM_NULL) {
1003 retval = MPI_ERR_COMM;
1004 } else if(datatype == MPI_DATATYPE_NULL) {
1005 retval = MPI_ERR_TYPE;
1006 } else if(op == MPI_OP_NULL) {
1007 retval = MPI_ERR_OP;
1008 } else if(recvcounts == NULL) {
1009 retval = MPI_ERR_ARG;
1011 /* arbitrarily choose root as rank 0 */
1012 /* TODO: faster direct implementation ? */
1013 size = smpi_comm_size(comm);
1015 displs = xbt_new(int, size);
1016 for(i = 0; i < size; i++) {
1017 count += recvcounts[i];
1020 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
1021 smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
1023 retval = MPI_SUCCESS;
1025 smpi_bench_begin(rank, "Reduce_scatter");
1029 int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
1030 int retval, size, sendsize;
1031 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1033 smpi_bench_end(rank, "Alltoall");
1034 if(comm == MPI_COMM_NULL) {
1035 retval = MPI_ERR_COMM;
1036 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
1037 retval = MPI_ERR_TYPE;
1039 size = smpi_comm_size(comm);
1040 sendsize = smpi_datatype_size(sendtype) * sendcount;
1041 if(sendsize < 200 && size > 12) {
1042 retval = smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1043 } else if(sendsize < 3000) {
1044 retval = smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1046 retval = smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1049 smpi_bench_begin(rank, "Alltoall");
1053 int MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm) {
1055 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1057 smpi_bench_end(rank, "Alltoallv");
1058 if(comm == MPI_COMM_NULL) {
1059 retval = MPI_ERR_COMM;
1060 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
1061 retval = MPI_ERR_TYPE;
1062 } else if(sendcounts == NULL || senddisps == NULL || recvcounts == NULL || recvdisps == NULL) {
1063 retval = MPI_ERR_ARG;
1065 retval = smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm);
1067 smpi_bench_begin(rank, "Alltoallv");