1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/replay.h"
12 #include "surf/surf.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi,
15 "Logging specific to SMPI (base)");
17 static int match_recv(void* a, void* b, smx_action_t ignored) {
18 MPI_Request ref = (MPI_Request)a;
19 MPI_Request req = (MPI_Request)b;
20 XBT_DEBUG("Trying to match a recv of src %d against %d, tag %d against %d",ref->src,req->src, ref->tag, req->tag);
22 xbt_assert(ref, "Cannot match recv against null reference");
23 xbt_assert(req, "Cannot match recv against null request");
24 return (ref->src == MPI_ANY_SOURCE || req->src == ref->src)
25 && (ref->tag == MPI_ANY_TAG || req->tag == ref->tag);
28 static int match_send(void* a, void* b,smx_action_t ignored) {
29 MPI_Request ref = (MPI_Request)a;
30 MPI_Request req = (MPI_Request)b;
31 XBT_DEBUG("Trying to match a send of src %d against %d, tag %d against %d",ref->src,req->src, ref->tag, req->tag);
32 xbt_assert(ref, "Cannot match send against null reference");
33 xbt_assert(req, "Cannot match send against null request");
34 return (req->src == MPI_ANY_SOURCE || req->src == ref->src)
35 && (req->tag == MPI_ANY_TAG || req->tag == ref->tag);
38 static MPI_Request build_request(void *buf, int count,
39 MPI_Datatype datatype, int src, int dst,
40 int tag, MPI_Comm comm, unsigned flags)
44 request = xbt_new(s_smpi_mpi_request_t, 1);
46 // FIXME: this will have to be changed to support non-contiguous datatypes
47 request->size = smpi_datatype_size(datatype) * count;
52 request->action = NULL;
53 request->flags = flags;
61 void smpi_action_trace_run(char *path)
65 xbt_dict_cursor_t cursor;
69 action_fp = fopen(path, "r");
70 xbt_assert(action_fp != NULL, "Cannot open %s: %s", path,
74 if (!xbt_dict_is_empty(action_queues)) {
76 ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file.");
79 xbt_dict_foreach(action_queues, cursor, name, todo) {
80 XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
86 xbt_dict_free(&action_queues);
87 action_queues = xbt_dict_new_homogeneous(NULL);
90 static void smpi_mpi_request_free_voidp(void* request)
92 MPI_Request req = request;
93 smpi_mpi_request_free(&req);
96 /* MPI Low level calls */
97 MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype,
98 int dst, int tag, MPI_Comm comm)
100 MPI_Request request =
101 build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag,
102 comm, PERSISTENT | SEND);
107 MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype,
108 int src, int tag, MPI_Comm comm)
110 MPI_Request request =
111 build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag,
112 comm, PERSISTENT | RECV);
117 void smpi_mpi_start(MPI_Request request)
122 xbt_assert(!request->action,
123 "Cannot (re)start a non-finished communication");
124 if(request->flags & RECV) {
125 print_request("New recv", request);
126 if (request->size < xbt_cfg_get_int(_surf_cfg_set, "smpi/async_small_thres"))
127 mailbox = smpi_process_mailbox_small();
129 mailbox = smpi_process_mailbox();
131 // FIXME: SIMIX does not yet support non-contiguous datatypes
132 request->action = simcall_comm_irecv(mailbox, request->buf, &request->size, &match_recv, request);
134 print_request("New send", request);
136 if (request->size < xbt_cfg_get_int(_surf_cfg_set, "smpi/async_small_thres")) { // eager mode => detached send (FIXME: this limit should be configurable)
137 mailbox = smpi_process_remote_mailbox_small(
138 smpi_group_index(smpi_comm_group(request->comm), request->dst));
140 XBT_DEBUG("Send request %p is not in the permanent receive mailbox (buf: %p)",request,request->buf);
141 mailbox = smpi_process_remote_mailbox(
142 smpi_group_index(smpi_comm_group(request->comm), request->dst));
144 if (request->size < 64*1024 ) { //(FIXME: this limit should be configurable)
145 void *oldbuf = request->buf;
147 request->buf = malloc(request->size);
149 memcpy(request->buf,oldbuf,request->size);
150 XBT_DEBUG("Send request %p is detached; buf %p copied into %p",request,oldbuf,request->buf);
154 simcall_comm_isend(mailbox, request->size, -1.0,
155 request->buf, request->size,
157 &smpi_mpi_request_free_voidp, // how to free the userdata if a detached send fails
159 // detach if msg size < eager/rdv switch limit
163 /* FIXME: detached sends are not traceable (request->action == NULL) */
165 simcall_set_category(request->action, TRACE_internal_smpi_get_category());
172 void smpi_mpi_startall(int count, MPI_Request * requests)
176 for(i = 0; i < count; i++) {
177 smpi_mpi_start(requests[i]);
181 void smpi_mpi_request_free(MPI_Request * request)
184 *request = MPI_REQUEST_NULL;
187 MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype,
188 int dst, int tag, MPI_Comm comm)
190 MPI_Request request =
191 build_request(buf, count, datatype, smpi_comm_rank(comm), dst, tag,
192 comm, NON_PERSISTENT | SEND);
197 MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype,
198 int dst, int tag, MPI_Comm comm)
200 MPI_Request request =
201 smpi_isend_init(buf, count, datatype, dst, tag, comm);
203 smpi_mpi_start(request);
207 MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype,
208 int src, int tag, MPI_Comm comm)
210 MPI_Request request =
211 build_request(buf, count, datatype, src, smpi_comm_rank(comm), tag,
212 comm, NON_PERSISTENT | RECV);
217 MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype,
218 int src, int tag, MPI_Comm comm)
220 MPI_Request request =
221 smpi_irecv_init(buf, count, datatype, src, tag, comm);
223 smpi_mpi_start(request);
227 void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src,
228 int tag, MPI_Comm comm, MPI_Status * status)
232 request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
233 smpi_mpi_wait(&request, status);
238 void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst,
239 int tag, MPI_Comm comm)
242 request = smpi_mpi_isend(buf, count, datatype, dst, tag, comm);
243 smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
246 void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
247 int dst, int sendtag, void *recvbuf, int recvcount,
248 MPI_Datatype recvtype, int src, int recvtag,
249 MPI_Comm comm, MPI_Status * status)
251 MPI_Request requests[2];
255 smpi_isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
257 smpi_irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm);
258 smpi_mpi_startall(2, requests);
259 smpi_mpi_waitall(2, requests, stats);
260 if(status != MPI_STATUS_IGNORE) {
261 // Copy receive status
262 memcpy(status, &stats[1], sizeof(MPI_Status));
266 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype)
268 return status->count / smpi_datatype_size(datatype);
271 static void finish_wait(MPI_Request * request, MPI_Status * status)
273 MPI_Request req = *request;
274 // if we have a sender, we should use its data, and not the data from the receive
276 (req->src==MPI_ANY_SOURCE || req->tag== MPI_ANY_TAG))
277 req = (MPI_Request)SIMIX_comm_get_src_data((*request)->action);
279 if(status != MPI_STATUS_IGNORE) {
280 status->MPI_SOURCE = req->src;
281 status->MPI_TAG = req->tag;
282 status->MPI_ERROR = MPI_SUCCESS;
283 // FIXME: really this should just contain the count of receive-type blocks,
285 status->count = req->size;
289 print_request("Finishing", req);
290 if(req->flags & NON_PERSISTENT) {
291 smpi_mpi_request_free(request);
297 int smpi_mpi_test(MPI_Request * request, MPI_Status * status) {
299 if ((*request)->action == NULL)
302 flag = simcall_comm_test((*request)->action);
304 finish_wait(request, status);
309 int smpi_mpi_testany(int count, MPI_Request requests[], int *index,
316 *index = MPI_UNDEFINED;
319 comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
320 map = xbt_new(int, count);
322 for(i = 0; i < count; i++) {
323 if(requests[i]->action) {
324 xbt_dynar_push(comms, &requests[i]->action);
330 i = simcall_comm_testany(comms);
331 // FIXME: MPI_UNDEFINED or does SIMIX have a return code?
332 if(i != MPI_UNDEFINED) {
334 smpi_mpi_wait(&requests[*index], status);
339 xbt_dynar_free(&comms);
345 int smpi_mpi_testall(int count, MPI_Request requests[],
350 for(i=0; i<count; i++)
351 if(requests[i]!= MPI_REQUEST_NULL)
352 if (smpi_mpi_test(&requests[i], &status[i])!=1)
358 void smpi_mpi_probe(int source, int tag, MPI_Comm comm, MPI_Status* status){
360 //FIXME find another wait to avoid busy waiting ?
361 // the issue here is that we have to wait on a nonexistent comm
363 smpi_mpi_iprobe(source, tag, comm, &flag, status);
364 XBT_DEBUG("Busy Waiting on probing : %d", flag);
366 simcall_process_sleep(0.0001);
371 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
372 MPI_Request request =build_request(NULL, 0, MPI_CHAR, source, smpi_comm_rank(comm), tag,
373 comm, NON_PERSISTENT | RECV);
374 // behave like a receive, but don't do it
377 print_request("New iprobe", request);
378 // We have to test both mailboxes as we don't know if we will receive one one or another
379 if (xbt_cfg_get_int(_surf_cfg_set, "smpi/async_small_thres")>0){
380 mailbox = smpi_process_mailbox_small();
381 XBT_DEBUG("trying to probe the perm recv mailbox");
382 request->action = simcall_comm_iprobe(mailbox, request->src, request->tag, &match_recv, (void*)request);
384 if (request->action==NULL){
385 mailbox = smpi_process_mailbox();
386 XBT_DEBUG("trying to probe the other mailbox");
387 request->action = simcall_comm_iprobe(mailbox, request->src, request->tag, &match_recv, (void*)request);
391 MPI_Request req = (MPI_Request)SIMIX_comm_get_src_data(request->action);
393 if(status != MPI_STATUS_IGNORE) {
394 status->MPI_SOURCE = req->src;
395 status->MPI_TAG = req->tag;
396 status->MPI_ERROR = MPI_SUCCESS;
397 status->count = req->size;
401 smpi_mpi_request_free(&request);
406 void smpi_mpi_wait(MPI_Request * request, MPI_Status * status)
408 print_request("Waiting", *request);
409 if ((*request)->action != NULL) { // this is not a detached send
410 simcall_comm_wait((*request)->action, -1.0);
411 finish_wait(request, status);
413 // FIXME for a detached send, finish_wait is not called:
416 int smpi_mpi_waitany(int count, MPI_Request requests[],
423 index = MPI_UNDEFINED;
425 // Wait for a request to complete
426 comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
427 map = xbt_new(int, count);
429 XBT_DEBUG("Wait for one of");
430 for(i = 0; i < count; i++) {
431 if((requests[i] != MPI_REQUEST_NULL) && (requests[i]->action != NULL)) {
432 print_request("Waiting any ", requests[i]);
433 xbt_dynar_push(comms, &requests[i]->action);
439 i = simcall_comm_waitany(comms);
441 // FIXME: MPI_UNDEFINED or does SIMIX have a return code?
442 if (i != MPI_UNDEFINED) {
444 finish_wait(&requests[index], status);
449 xbt_dynar_free(&comms);
454 void smpi_mpi_waitall(int count, MPI_Request requests[],
459 MPI_Status *pstat = status == MPI_STATUS_IGNORE ? MPI_STATUS_IGNORE : &stat;
461 for(c = 0; c < count; c++) {
463 smpi_mpi_wait(&requests[c], pstat);
466 index = smpi_mpi_waitany(count, requests, pstat);
467 if(index == MPI_UNDEFINED) {
471 if(status != MPI_STATUS_IGNORE) {
472 memcpy(&status[index], pstat, sizeof(*pstat));
477 int smpi_mpi_waitsome(int incount, MPI_Request requests[], int *indices,
483 for(i = 0; i < incount; i++) {
484 if(smpi_mpi_testany(incount, requests, &index, status)) {
485 indices[count] = index;
492 void smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root,
495 // arity=2: a binary tree, arity=4 seem to be a good setting (see P2P-MPI))
496 nary_tree_bcast(buf, count, datatype, root, comm, 4);
499 void smpi_mpi_barrier(MPI_Comm comm)
501 // arity=2: a binary tree, arity=4 seem to be a good setting (see P2P-MPI))
502 nary_tree_barrier(comm, 4);
505 void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
506 void *recvbuf, int recvcount, MPI_Datatype recvtype,
507 int root, MPI_Comm comm)
509 int system_tag = 666;
510 int rank, size, src, index;
511 MPI_Aint lb = 0, recvext = 0;
512 MPI_Request *requests;
514 rank = smpi_comm_rank(comm);
515 size = smpi_comm_size(comm);
517 // Send buffer to root
518 smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm);
520 // FIXME: check for errors
521 smpi_datatype_extent(recvtype, &lb, &recvext);
522 // Local copy from root
523 smpi_datatype_copy(sendbuf, sendcount, sendtype,
524 (char *)recvbuf + root * recvcount * recvext, recvcount, recvtype);
525 // Receive buffers from senders
526 requests = xbt_new(MPI_Request, size - 1);
528 for(src = 0; src < size; src++) {
530 requests[index] = smpi_irecv_init((char *)recvbuf + src * recvcount * recvext,
532 src, system_tag, comm);
536 // Wait for completion of irecv's.
537 smpi_mpi_startall(size - 1, requests);
538 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
543 void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
544 void *recvbuf, int *recvcounts, int *displs,
545 MPI_Datatype recvtype, int root, MPI_Comm comm)
547 int system_tag = 666;
548 int rank, size, src, index;
549 MPI_Aint lb = 0, recvext = 0;
550 MPI_Request *requests;
552 rank = smpi_comm_rank(comm);
553 size = smpi_comm_size(comm);
555 // Send buffer to root
556 smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm);
558 // FIXME: check for errors
559 smpi_datatype_extent(recvtype, &lb, &recvext);
560 // Local copy from root
561 smpi_datatype_copy(sendbuf, sendcount, sendtype,
562 (char *)recvbuf + displs[root] * recvext,
563 recvcounts[root], recvtype);
564 // Receive buffers from senders
565 requests = xbt_new(MPI_Request, size - 1);
567 for(src = 0; src < size; src++) {
570 smpi_irecv_init((char *)recvbuf + displs[src] * recvext,
571 recvcounts[src], recvtype, src, system_tag, comm);
575 // Wait for completion of irecv's.
576 smpi_mpi_startall(size - 1, requests);
577 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
582 void smpi_mpi_allgather(void *sendbuf, int sendcount,
583 MPI_Datatype sendtype, void *recvbuf,
584 int recvcount, MPI_Datatype recvtype,
587 int system_tag = 666;
588 int rank, size, other, index;
589 MPI_Aint lb = 0, recvext = 0;
590 MPI_Request *requests;
592 rank = smpi_comm_rank(comm);
593 size = smpi_comm_size(comm);
594 // FIXME: check for errors
595 smpi_datatype_extent(recvtype, &lb, &recvext);
596 // Local copy from self
597 smpi_datatype_copy(sendbuf, sendcount, sendtype,
598 (char *)recvbuf + rank * recvcount * recvext, recvcount,
600 // Send/Recv buffers to/from others;
601 requests = xbt_new(MPI_Request, 2 * (size - 1));
603 for(other = 0; other < size; other++) {
606 smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag,
609 requests[index] = smpi_irecv_init((char *)recvbuf + other * recvcount * recvext,
610 recvcount, recvtype, other,
615 // Wait for completion of all comms.
616 smpi_mpi_startall(2 * (size - 1), requests);
617 smpi_mpi_waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
621 void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
622 MPI_Datatype sendtype, void *recvbuf,
623 int *recvcounts, int *displs,
624 MPI_Datatype recvtype, MPI_Comm comm)
626 int system_tag = 666;
627 int rank, size, other, index;
628 MPI_Aint lb = 0, recvext = 0;
629 MPI_Request *requests;
631 rank = smpi_comm_rank(comm);
632 size = smpi_comm_size(comm);
633 // FIXME: check for errors
634 smpi_datatype_extent(recvtype, &lb, &recvext);
635 // Local copy from self
636 smpi_datatype_copy(sendbuf, sendcount, sendtype,
637 (char *)recvbuf + displs[rank] * recvext,
638 recvcounts[rank], recvtype);
639 // Send buffers to others;
640 requests = xbt_new(MPI_Request, 2 * (size - 1));
642 for(other = 0; other < size; other++) {
645 smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag,
649 smpi_irecv_init((char *)recvbuf + displs[other] * recvext, recvcounts[other],
650 recvtype, other, system_tag, comm);
654 // Wait for completion of all comms.
655 smpi_mpi_startall(2 * (size - 1), requests);
656 smpi_mpi_waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
660 void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
661 void *recvbuf, int recvcount, MPI_Datatype recvtype,
662 int root, MPI_Comm comm)
664 int system_tag = 666;
665 int rank, size, dst, index;
666 MPI_Aint lb = 0, sendext = 0;
667 MPI_Request *requests;
669 rank = smpi_comm_rank(comm);
670 size = smpi_comm_size(comm);
672 // Recv buffer from root
673 smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm,
676 // FIXME: check for errors
677 smpi_datatype_extent(sendtype, &lb, &sendext);
678 // Local copy from root
679 smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
680 sendcount, sendtype, recvbuf, recvcount, recvtype);
681 // Send buffers to receivers
682 requests = xbt_new(MPI_Request, size - 1);
684 for(dst = 0; dst < size; dst++) {
686 requests[index] = smpi_isend_init((char *)sendbuf + dst * sendcount * sendext,
687 sendcount, sendtype, dst,
692 // Wait for completion of isend's.
693 smpi_mpi_startall(size - 1, requests);
694 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
699 void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
700 MPI_Datatype sendtype, void *recvbuf, int recvcount,
701 MPI_Datatype recvtype, int root, MPI_Comm comm)
703 int system_tag = 666;
704 int rank, size, dst, index;
705 MPI_Aint lb = 0, sendext = 0;
706 MPI_Request *requests;
708 rank = smpi_comm_rank(comm);
709 size = smpi_comm_size(comm);
711 // Recv buffer from root
712 smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm,
715 // FIXME: check for errors
716 smpi_datatype_extent(sendtype, &lb, &sendext);
717 // Local copy from root
718 smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
719 sendtype, recvbuf, recvcount, recvtype);
720 // Send buffers to receivers
721 requests = xbt_new(MPI_Request, size - 1);
723 for(dst = 0; dst < size; dst++) {
726 smpi_isend_init((char *)sendbuf + displs[dst] * sendext, sendcounts[dst],
727 sendtype, dst, system_tag, comm);
731 // Wait for completion of isend's.
732 smpi_mpi_startall(size - 1, requests);
733 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
738 void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
739 MPI_Datatype datatype, MPI_Op op, int root,
742 int system_tag = 666;
743 int rank, size, src, index;
744 MPI_Aint lb = 0, dataext = 0;
745 MPI_Request *requests;
748 rank = smpi_comm_rank(comm);
749 size = smpi_comm_size(comm);
751 // Send buffer to root
752 smpi_mpi_send(sendbuf, count, datatype, root, system_tag, comm);
754 // FIXME: check for errors
755 smpi_datatype_extent(datatype, &lb, &dataext);
756 // Local copy from root
757 if (sendbuf && recvbuf)
758 smpi_datatype_copy(sendbuf, count, datatype, recvbuf, count, datatype);
759 // Receive buffers from senders
760 //TODO: make a MPI_barrier here ?
761 requests = xbt_new(MPI_Request, size - 1);
762 tmpbufs = xbt_new(void *, size - 1);
764 for(src = 0; src < size; src++) {
766 // FIXME: possibly overkill we we have contiguous/noncontiguous data
768 tmpbufs[index] = xbt_malloc(count * dataext);
770 smpi_irecv_init(tmpbufs[index], count, datatype, src,
775 // Wait for completion of irecv's.
776 smpi_mpi_startall(size - 1, requests);
777 for(src = 0; src < size - 1; src++) {
778 index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
779 XBT_DEBUG("finished waiting any request with index %d", index);
780 if(index == MPI_UNDEFINED) {
783 if(op) /* op can be MPI_OP_NULL that does nothing */
784 smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
786 for(index = 0; index < size - 1; index++) {
787 xbt_free(tmpbufs[index]);
794 void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count,
795 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
797 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
798 smpi_mpi_bcast(recvbuf, count, datatype, 0, comm);
801 void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
802 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
804 int system_tag = 666;
805 int rank, size, other, index;
806 MPI_Aint lb = 0, dataext = 0;
807 MPI_Request *requests;
810 rank = smpi_comm_rank(comm);
811 size = smpi_comm_size(comm);
813 // FIXME: check for errors
814 smpi_datatype_extent(datatype, &lb, &dataext);
816 // Local copy from self
817 smpi_datatype_copy(sendbuf, count, datatype, recvbuf, count, datatype);
819 // Send/Recv buffers to/from others;
820 requests = xbt_new(MPI_Request, size - 1);
821 tmpbufs = xbt_new(void *, rank);
823 for(other = 0; other < rank; other++) {
824 // FIXME: possibly overkill we we have contiguous/noncontiguous data
826 tmpbufs[index] = xbt_malloc(count * dataext);
828 smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag,
832 for(other = rank + 1; other < size; other++) {
834 smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm);
837 // Wait for completion of all comms.
838 smpi_mpi_startall(size - 1, requests);
839 for(other = 0; other < size - 1; other++) {
840 index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
841 if(index == MPI_UNDEFINED) {
845 // #Request is below rank: it's a irecv
846 smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
849 for(index = 0; index < rank; index++) {
850 xbt_free(tmpbufs[index]);