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_Get_count(MPI_Status *status, MPI_Datatype datatype, int *count) {
738 * Returns the number of entries received. (Again, we count entries, each of type datatype, not bytes.)
739 * The datatype argument should match the argument provided by the receive call that set the status variable.
740 * If the size of the datatype is zero, this routine will return a count of zero.
741 * If the amount of data in status is not an exact multiple of the size of datatype
742 * (so that count would not be integral), a count of MPI_UNDEFINED is returned instead.
745 smpi_bench_end(-1, NULL); //FIXME
747 if( 0==smpi_datatype_size(datatype)) {
748 // also check that the type is 'committed' when we have MPI_Type_commit (s.g. 23/03/21010)
749 retval = MPI_ERR_TYPE;
751 smpi_mpi_get_count(status, datatype, count);
752 retval = MPI_SUCCESS;
754 smpi_bench_begin(-1, NULL);
759 int MPI_Test(MPI_Request* request, int* flag, MPI_Status* status) {
761 int rank = request && (*request)->comm != MPI_COMM_NULL
762 ? smpi_comm_rank((*request)->comm)
765 smpi_bench_end(rank, "Test");
766 if(request == NULL || flag == NULL) {
767 retval = MPI_ERR_ARG;
768 } else if(*request == MPI_REQUEST_NULL) {
769 retval = MPI_ERR_REQUEST;
771 *flag = smpi_mpi_test(request, status);
772 retval = MPI_SUCCESS;
774 smpi_bench_begin(rank, "Test");
778 int MPI_Testany(int count, MPI_Request requests[], int* index, int* flag, MPI_Status* status) {
781 smpi_bench_end(-1, NULL); //FIXME
782 if(index == NULL || flag == NULL) {
783 retval = MPI_ERR_ARG;
785 *flag = smpi_mpi_testany(count, requests, index, status);
786 retval = MPI_SUCCESS;
788 smpi_bench_begin(-1, NULL);
792 int MPI_Wait(MPI_Request* request, MPI_Status* status) {
794 int rank = request && (*request)->comm != MPI_COMM_NULL
795 ? smpi_comm_rank((*request)->comm)
798 smpi_bench_end(rank, "Wait");
799 if(request == NULL) {
800 retval = MPI_ERR_ARG;
801 } else if(*request == MPI_REQUEST_NULL) {
802 retval = MPI_ERR_REQUEST;
804 smpi_mpi_wait(request, status);
805 retval = MPI_SUCCESS;
807 smpi_bench_begin(rank, "Wait");
811 int MPI_Waitany(int count, MPI_Request requests[], int* index, MPI_Status* status) {
814 smpi_bench_end(-1, NULL); //FIXME
816 retval = MPI_ERR_ARG;
818 *index = smpi_mpi_waitany(count, requests, status);
819 retval = MPI_SUCCESS;
821 smpi_bench_begin(-1, NULL);
825 int MPI_Waitall(int count, MPI_Request requests[], MPI_Status status[]) {
826 smpi_bench_end(-1, NULL); //FIXME
827 smpi_mpi_waitall(count, requests, status);
828 smpi_bench_begin(-1, NULL);
832 int MPI_Waitsome(int incount, MPI_Request requests[], int* outcount, int* indices, MPI_Status status[]) {
835 smpi_bench_end(-1, NULL); //FIXME
836 if(outcount == NULL || indices == NULL) {
837 retval = MPI_ERR_ARG;
839 *outcount = smpi_mpi_waitsome(incount, requests, indices, status);
840 retval = MPI_SUCCESS;
842 smpi_bench_begin(-1, NULL);
846 int MPI_Bcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) {
848 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
850 smpi_bench_end(rank, "Bcast");
851 if(comm == MPI_COMM_NULL) {
852 retval = MPI_ERR_COMM;
854 smpi_mpi_bcast(buf, count, datatype, root, comm);
855 retval = MPI_SUCCESS;
857 smpi_bench_begin(rank, "Bcast");
861 int MPI_Barrier(MPI_Comm comm) {
863 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
865 smpi_bench_end(rank, "Barrier");
866 if(comm == MPI_COMM_NULL) {
867 retval = MPI_ERR_COMM;
869 smpi_mpi_barrier(comm);
870 retval = MPI_SUCCESS;
872 smpi_bench_begin(rank, "Barrier");
876 int MPI_Gather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
878 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
880 smpi_bench_end(rank, "Gather");
881 if(comm == MPI_COMM_NULL) {
882 retval = MPI_ERR_COMM;
883 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
884 retval = MPI_ERR_TYPE;
886 smpi_mpi_gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
887 retval = MPI_SUCCESS;
889 smpi_bench_begin(rank, "Gather");
893 int MPI_Gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm) {
895 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
897 smpi_bench_end(rank, "Gatherv");
898 if(comm == MPI_COMM_NULL) {
899 retval = MPI_ERR_COMM;
900 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
901 retval = MPI_ERR_TYPE;
902 } else if(recvcounts == NULL || displs == NULL) {
903 retval = MPI_ERR_ARG;
905 smpi_mpi_gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm);
906 retval = MPI_SUCCESS;
908 smpi_bench_begin(rank, "Gatherv");
912 int MPI_Allgather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
914 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
916 smpi_bench_end(rank, "Allgather");
917 if(comm == MPI_COMM_NULL) {
918 retval = MPI_ERR_COMM;
919 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
920 retval = MPI_ERR_TYPE;
922 smpi_mpi_allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
923 retval = MPI_SUCCESS;
925 smpi_bench_begin(rank, "Allgather");
929 int MPI_Allgatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, MPI_Comm comm) {
931 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
933 smpi_bench_end(rank, "Allgatherv");
934 if(comm == MPI_COMM_NULL) {
935 retval = MPI_ERR_COMM;
936 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
937 retval = MPI_ERR_TYPE;
938 } else if(recvcounts == NULL || displs == NULL) {
939 retval = MPI_ERR_ARG;
941 smpi_mpi_allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
942 retval = MPI_SUCCESS;
944 smpi_bench_begin(rank, "Allgatherv");
948 int MPI_Scatter(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
950 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
952 smpi_bench_end(rank, "Scatter");
953 if(comm == MPI_COMM_NULL) {
954 retval = MPI_ERR_COMM;
955 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
956 retval = MPI_ERR_TYPE;
958 smpi_mpi_scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
959 retval = MPI_SUCCESS;
961 smpi_bench_begin(rank, "Scatter");
965 int MPI_Scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) {
967 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
969 smpi_bench_end(rank, "Scatterv");
970 if(comm == MPI_COMM_NULL) {
971 retval = MPI_ERR_COMM;
972 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
973 retval = MPI_ERR_TYPE;
974 } else if(sendcounts == NULL || displs == NULL) {
975 retval = MPI_ERR_ARG;
977 smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
978 retval = MPI_SUCCESS;
980 smpi_bench_begin(rank, "Scatterv");
984 int MPI_Reduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) {
986 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
988 smpi_bench_end(rank, "Reduce");
989 if(comm == MPI_COMM_NULL) {
990 retval = MPI_ERR_COMM;
991 } else if(datatype == MPI_DATATYPE_NULL || op == MPI_OP_NULL) {
992 retval = MPI_ERR_ARG;
994 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, root, comm);
995 retval = MPI_SUCCESS;
997 smpi_bench_begin(rank, "Reduce");
1001 int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
1003 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1005 smpi_bench_end(rank, "Allreduce");
1006 if(comm == MPI_COMM_NULL) {
1007 retval = MPI_ERR_COMM;
1008 } else if(datatype == MPI_DATATYPE_NULL) {
1009 retval = MPI_ERR_TYPE;
1010 } else if(op == MPI_OP_NULL) {
1011 retval = MPI_ERR_OP;
1013 smpi_mpi_allreduce(sendbuf, recvbuf, count, datatype, op, comm);
1014 retval = MPI_SUCCESS;
1016 smpi_bench_begin(rank, "Allreduce");
1020 int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int* recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) {
1021 int retval, i, size, count;
1023 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1025 smpi_bench_end(rank, "Reduce_scatter");
1026 if(comm == MPI_COMM_NULL) {
1027 retval = MPI_ERR_COMM;
1028 } else if(datatype == MPI_DATATYPE_NULL) {
1029 retval = MPI_ERR_TYPE;
1030 } else if(op == MPI_OP_NULL) {
1031 retval = MPI_ERR_OP;
1032 } else if(recvcounts == NULL) {
1033 retval = MPI_ERR_ARG;
1035 /* arbitrarily choose root as rank 0 */
1036 /* TODO: faster direct implementation ? */
1037 size = smpi_comm_size(comm);
1039 displs = xbt_new(int, size);
1040 for(i = 0; i < size; i++) {
1041 count += recvcounts[i];
1044 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
1045 smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
1047 retval = MPI_SUCCESS;
1049 smpi_bench_begin(rank, "Reduce_scatter");
1053 int MPI_Alltoall(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) {
1054 int retval, size, sendsize;
1055 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1057 smpi_bench_end(rank, "Alltoall");
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;
1063 size = smpi_comm_size(comm);
1064 sendsize = smpi_datatype_size(sendtype) * sendcount;
1065 if(sendsize < 200 && size > 12) {
1066 retval = smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1067 } else if(sendsize < 3000) {
1068 retval = smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1070 retval = smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
1073 smpi_bench_begin(rank, "Alltoall");
1077 int MPI_Alltoallv(void* sendbuf, int* sendcounts, int* senddisps, MPI_Datatype sendtype, void* recvbuf, int *recvcounts, int* recvdisps, MPI_Datatype recvtype, MPI_Comm comm) {
1079 int rank = comm != MPI_COMM_NULL ? smpi_comm_rank(comm) : -1;
1081 smpi_bench_end(rank, "Alltoallv");
1082 if(comm == MPI_COMM_NULL) {
1083 retval = MPI_ERR_COMM;
1084 } else if(sendtype == MPI_DATATYPE_NULL || recvtype == MPI_DATATYPE_NULL) {
1085 retval = MPI_ERR_TYPE;
1086 } else if(sendcounts == NULL || senddisps == NULL || recvcounts == NULL || recvdisps == NULL) {
1087 retval = MPI_ERR_ARG;
1089 retval = smpi_coll_basic_alltoallv(sendbuf, sendcounts, senddisps, sendtype, recvbuf, recvcounts, recvdisps, recvtype, comm);
1091 smpi_bench_begin(rank, "Alltoallv");
1096 int MPI_Get_processor_name( char *name, int *resultlen ) {
1097 int retval = MPI_SUCCESS;
1098 smpi_bench_end(-1, NULL);
1099 strncpy( name , SIMIX_host_get_name(SIMIX_host_self()), MPI_MAX_PROCESSOR_NAME-1);
1100 *resultlen= strlen(name) > MPI_MAX_PROCESSOR_NAME ? MPI_MAX_PROCESSOR_NAME : strlen(name);
1102 smpi_bench_begin(-1, NULL);