1 /* Copyright (c) 2007-2014. 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 "simix/smx_private.h"
13 #include "surf/surf.h"
14 #include "simgrid/sg_config.h"
15 #include "colls/colls.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)");
20 static int match_recv(void* a, void* b, smx_action_t ignored) {
21 MPI_Request ref = (MPI_Request)a;
22 MPI_Request req = (MPI_Request)b;
23 XBT_DEBUG("Trying to match a recv of src %d against %d, tag %d against %d",ref->src,req->src, ref->tag, req->tag);
25 xbt_assert(ref, "Cannot match recv against null reference");
26 xbt_assert(req, "Cannot match recv against null request");
27 if((ref->src == MPI_ANY_SOURCE || req->src == ref->src)
28 && ((ref->tag == MPI_ANY_TAG && req->tag >=0) || req->tag == ref->tag)){
29 //we match, we can transfer some values
30 // FIXME : move this to the copy function ?
31 if(ref->src == MPI_ANY_SOURCE)ref->real_src = req->src;
32 if(ref->tag == MPI_ANY_TAG)ref->real_tag = req->tag;
33 if(ref->real_size < req->real_size) ref->truncated = 1;
35 ref->detached_sender=req; //tie the sender to the receiver, as it is detached and has to be freed in the receiver
37 XBT_DEBUG("match succeeded");
42 static int match_send(void* a, void* b,smx_action_t ignored) {
43 MPI_Request ref = (MPI_Request)a;
44 MPI_Request req = (MPI_Request)b;
45 XBT_DEBUG("Trying to match a send of src %d against %d, tag %d against %d",ref->src,req->src, ref->tag, req->tag);
46 xbt_assert(ref, "Cannot match send against null reference");
47 xbt_assert(req, "Cannot match send against null request");
49 if((req->src == MPI_ANY_SOURCE || req->src == ref->src)
50 && ((req->tag == MPI_ANY_TAG && ref->tag >=0)|| req->tag == ref->tag))
52 if(req->src == MPI_ANY_SOURCE)req->real_src = ref->src;
53 if(req->tag == MPI_ANY_TAG)req->real_tag = ref->tag;
54 if(req->real_size < ref->real_size) req->truncated = 1;
56 req->detached_sender=ref; //tie the sender to the receiver, as it is detached and has to be freed in the receiver
58 XBT_DEBUG("match succeeded");
64 typedef struct s_smpi_factor *smpi_factor_t;
65 typedef struct s_smpi_factor {
68 double values[4];//arbitrary set to 4
70 xbt_dynar_t smpi_os_values = NULL;
71 xbt_dynar_t smpi_or_values = NULL;
72 xbt_dynar_t smpi_ois_values = NULL;
74 // Methods used to parse and store the values for timing injections in smpi
75 // These are taken from surf/network.c and generalized to have more factors
76 // These methods should be merged with those in surf/network.c (moved somewhere in xbt ?)
78 static int factor_cmp(const void *pa, const void *pb)
80 return (((s_smpi_factor_t*)pa)->factor > ((s_smpi_factor_t*)pb)->factor) ? 1 :
81 (((s_smpi_factor_t*)pa)->factor < ((s_smpi_factor_t*)pb)->factor) ? -1 : 0;
85 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
88 unsigned int iter = 0;
92 xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
94 smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
95 radical_elements = xbt_str_split(smpi_coef_string, ";");
96 xbt_dynar_foreach(radical_elements, iter, value) {
97 memset(&fact, 0, sizeof(s_smpi_factor_t));
98 radical_elements2 = xbt_str_split(value, ":");
99 if (xbt_dynar_length(radical_elements2) <2 || xbt_dynar_length(radical_elements2) > 5)
100 xbt_die("Malformed radical for smpi factor!");
101 for(i =0; i<xbt_dynar_length(radical_elements2);i++ ){
103 fact.factor = atol(xbt_dynar_get_as(radical_elements2, i, char *));
105 fact.values[fact.nb_values] = atof(xbt_dynar_get_as(radical_elements2, i, char *));
110 xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
111 XBT_DEBUG("smpi_factor:\t%ld : %d values, first: %f", fact.factor, fact.nb_values ,fact.values[0]);
112 xbt_dynar_free(&radical_elements2);
114 xbt_dynar_free(&radical_elements);
116 xbt_dynar_sort(smpi_factor, &factor_cmp);
117 xbt_dynar_foreach(smpi_factor, iter, fact) {
118 XBT_DEBUG("smpi_factor:\t%ld : %d values, first: %f", fact.factor, fact.nb_values ,fact.values[0]);
123 static double smpi_os(double size)
125 if (!smpi_os_values) {
126 smpi_os_values = parse_factor(sg_cfg_get_string("smpi/os"));
127 smpi_register_static(smpi_os_values, xbt_dynar_free_voidp);
129 unsigned int iter = 0;
130 s_smpi_factor_t fact;
132 xbt_dynar_foreach(smpi_os_values, iter, fact) {
133 if (size <= fact.factor) {
134 XBT_DEBUG("os : %f <= %ld return %f", size, fact.factor, current);
137 current=fact.values[0]+fact.values[1]*size;
140 XBT_DEBUG("os : %f > %ld return %f", size, fact.factor, current);
145 static double smpi_ois(double size)
147 if (!smpi_ois_values) {
148 smpi_ois_values = parse_factor(sg_cfg_get_string("smpi/ois"));
149 smpi_register_static(smpi_ois_values, xbt_dynar_free_voidp);
151 unsigned int iter = 0;
152 s_smpi_factor_t fact;
154 xbt_dynar_foreach(smpi_ois_values, iter, fact) {
155 if (size <= fact.factor) {
156 XBT_DEBUG("ois : %f <= %ld return %f", size, fact.factor, current);
159 current=fact.values[0]+fact.values[1]*size;
162 XBT_DEBUG("ois : %f > %ld return %f", size, fact.factor, current);
167 static double smpi_or(double size)
169 if (!smpi_or_values) {
170 smpi_or_values = parse_factor(sg_cfg_get_string("smpi/or"));
171 smpi_register_static(smpi_or_values, xbt_dynar_free_voidp);
173 unsigned int iter = 0;
174 s_smpi_factor_t fact;
176 xbt_dynar_foreach(smpi_or_values, iter, fact) {
177 if (size <= fact.factor) {
178 XBT_DEBUG("or : %f <= %ld return %f", size, fact.factor, current);
181 current=fact.values[0]+fact.values[1]*size;
183 XBT_DEBUG("or : %f > %ld return %f", size, fact.factor, current);
188 static MPI_Request build_request(void *buf, int count,
189 MPI_Datatype datatype, int src, int dst,
190 int tag, MPI_Comm comm, unsigned flags)
192 MPI_Request request = NULL;
194 void *old_buf = NULL;
196 request = xbt_new(s_smpi_mpi_request_t, 1);
198 s_smpi_subtype_t *subtype = datatype->substruct;
200 if(datatype->has_subtype == 1){
201 // This part handles the problem of non-contiguous memory
203 buf = count==0 ? NULL : xbt_malloc(count*smpi_datatype_size(datatype));
205 subtype->serialize(old_buf, buf, count, datatype->substruct);
210 // This part handles the problem of non-contiguous memory (for the
211 // unserialisation at the reception)
212 request->old_buf = old_buf;
213 request->old_type = datatype;
215 request->size = smpi_datatype_size(datatype) * count;
219 request->comm = comm;
220 request->action = NULL;
221 request->flags = flags;
222 request->detached = 0;
223 request->detached_sender = NULL;
224 request->real_src = 0;
226 request->truncated = 0;
227 request->real_size = 0;
228 request->real_tag = 0;
229 if(flags & PERSISTENT)
230 request->refcount = 1;
232 request->refcount = 0;
238 if (flags & SEND) smpi_datatype_unuse(datatype);
244 void smpi_empty_status(MPI_Status * status)
246 if(status != MPI_STATUS_IGNORE) {
247 status->MPI_SOURCE = MPI_ANY_SOURCE;
248 status->MPI_TAG = MPI_ANY_TAG;
249 status->MPI_ERROR = MPI_SUCCESS;
254 void smpi_action_trace_run(char *path)
258 xbt_dict_cursor_t cursor;
262 action_fp = fopen(path, "r");
263 xbt_assert(action_fp != NULL, "Cannot open %s: %s", path,
267 if (!xbt_dict_is_empty(action_queues)) {
269 ("Not all actions got consumed. If the simulation ended successfully (without deadlock), you may want to add new processes to your deployment file.");
272 xbt_dict_foreach(action_queues, cursor, name, todo) {
273 XBT_WARN("Still %lu actions for %s", xbt_dynar_length(todo), name);
279 xbt_dict_free(&action_queues);
280 action_queues = xbt_dict_new_homogeneous(NULL);
283 static void smpi_mpi_request_free_voidp(void* request)
285 MPI_Request req = request;
286 smpi_mpi_request_free(&req);
289 /* MPI Low level calls */
290 MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype,
291 int dst, int tag, MPI_Comm comm)
293 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
294 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
295 comm, PERSISTENT | SEND | PREPARED);
299 MPI_Request smpi_mpi_ssend_init(void *buf, int count, MPI_Datatype datatype,
300 int dst, int tag, MPI_Comm comm)
302 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
303 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
304 comm, PERSISTENT | SSEND | SEND | PREPARED);
308 MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype,
309 int src, int tag, MPI_Comm comm)
311 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
312 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
313 comm, PERSISTENT | RECV | PREPARED);
317 void smpi_mpi_start(MPI_Request request)
321 xbt_assert(!request->action, "Cannot (re)start a non-finished communication");
322 request->flags &= ~PREPARED;
323 request->flags &= ~FINISHED;
326 if (request->flags & RECV) {
327 print_request("New recv", request);
328 //FIXME: if receive is posted with a large size, but send is smaller, mailboxes may not match !
329 if (request->size < sg_cfg_get_int("smpi/async_small_thres"))
330 mailbox = smpi_process_mailbox_small();
332 mailbox = smpi_process_mailbox();
333 // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
334 request->real_size=request->size;
335 smpi_datatype_use(request->old_type);
336 smpi_comm_use(request->comm);
337 request->action = simcall_comm_irecv(mailbox, request->buf,
338 &request->real_size, &match_recv,
341 //integrate pseudo-timing for buffering of small messages, do not bother to execute the simcall if 0
342 double sleeptime = request->detached ? smpi_or(request->size) : 0.0;
344 simcall_process_sleep(sleeptime);
345 XBT_DEBUG("receiving size of %zu : sleep %f ", request->size, smpi_or(request->size));
351 int receiver = request->dst;//smpi_group_index(smpi_comm_group(request->comm), request->dst);
354 int rank = smpi_process_index();
355 if (TRACE_smpi_view_internals()) {
356 TRACE_smpi_send(rank, rank, receiver,request->size);
359 /* if(receiver == MPI_UNDEFINED) {*/
360 /* XBT_WARN("Trying to send a message to a wrong rank");*/
363 print_request("New send", request);
364 if (request->size < sg_cfg_get_int("smpi/async_small_thres")) { // eager mode
365 mailbox = smpi_process_remote_mailbox_small(receiver);
367 XBT_DEBUG("Send request %p is not in the permanent receive mailbox (buf: %p)",request,request->buf);
368 mailbox = smpi_process_remote_mailbox(receiver);
371 void* buf = request->buf;
372 if ( (! (request->flags & SSEND)) && (request->size < sg_cfg_get_int("smpi/send_is_detached_thres"))) {
374 request->detached = 1;
376 if(request->old_type->has_subtype == 0){
377 oldbuf = request->buf;
378 if (!_xbt_replay_is_active() && oldbuf && request->size!=0){
379 if((smpi_privatize_global_variables)
380 && ((char*)request->buf >= start_data_exe)
381 && ((char*)request->buf < start_data_exe + size_data_exe )){
382 XBT_DEBUG("Privatization : We are sending from a zone inside global memory. Switch data segment ");
383 switch_data_segment(smpi_process_index());
385 buf = xbt_malloc(request->size);
386 memcpy(buf,oldbuf,request->size);
389 XBT_DEBUG("Send request %p is detached; buf %p copied into %p",request,oldbuf,request->buf);
392 // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
393 request->real_size=request->size;
394 smpi_datatype_use(request->old_type);
395 smpi_comm_use(request->comm);
397 //if we are giving back the control to the user without waiting for completion, we have to inject timings
398 double sleeptime = 0.0;
399 if(request->detached || (request->flags & (ISEND|SSEND))){// issend should be treated as isend
400 //isend and send timings may be different
401 sleeptime = (request->flags & ISEND)? smpi_ois(request->size) : smpi_os(request->size);
404 if(sleeptime != 0.0){
405 simcall_process_sleep(sleeptime);
406 XBT_DEBUG("sending size of %zu : sleep %f ", request->size, smpi_os(request->size));
410 simcall_comm_isend(mailbox, request->size, -1.0,
411 buf, request->real_size,
413 &xbt_free, // how to free the userdata if a detached send fails
415 // detach if msg size < eager/rdv switch limit
419 /* FIXME: detached sends are not traceable (request->action == NULL) */
421 simcall_set_category(request->action, TRACE_internal_smpi_get_category());
429 void smpi_mpi_startall(int count, MPI_Request * requests)
432 if(requests==NULL) return;
434 for(i = 0; i < count; i++) {
435 smpi_mpi_start(requests[i]);
439 void smpi_mpi_request_free(MPI_Request * request)
441 if((*request) != MPI_REQUEST_NULL){
442 (*request)->refcount--;
443 if((*request)->refcount<0) xbt_die("wrong refcount");
445 if((*request)->refcount==0){
446 print_request("Destroying", (*request));
448 *request = MPI_REQUEST_NULL;
450 print_request("Decrementing", (*request));
453 xbt_die("freeing an already free request");
457 MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype,
458 int dst, int tag, MPI_Comm comm)
460 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
461 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf , count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
462 comm, PERSISTENT | ISEND | SEND | PREPARED);
466 MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype,
467 int dst, int tag, MPI_Comm comm)
469 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
470 request = build_request(buf==MPI_BOTTOM?(void*)0:buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
471 comm, NON_PERSISTENT | ISEND | SEND);
472 smpi_mpi_start(request);
476 MPI_Request smpi_mpi_issend(void *buf, int count, MPI_Datatype datatype,
477 int dst, int tag, MPI_Comm comm)
479 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
480 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
481 comm, NON_PERSISTENT | ISEND | SSEND | SEND);
482 smpi_mpi_start(request);
488 MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype,
489 int src, int tag, MPI_Comm comm)
491 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
492 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
493 comm, PERSISTENT | RECV | PREPARED);
497 MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype,
498 int src, int tag, MPI_Comm comm)
500 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
501 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
502 comm, NON_PERSISTENT | RECV);
503 smpi_mpi_start(request);
507 void smpi_mpi_recv(void *buf, int count, MPI_Datatype datatype, int src,
508 int tag, MPI_Comm comm, MPI_Status * status)
510 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
511 request = smpi_mpi_irecv(buf, count, datatype, src, tag, comm);
512 smpi_mpi_wait(&request, status);
518 void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst,
519 int tag, MPI_Comm comm)
521 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
522 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
523 comm, NON_PERSISTENT | SEND);
525 smpi_mpi_start(request);
526 smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
530 void smpi_mpi_ssend(void *buf, int count, MPI_Datatype datatype,
531 int dst, int tag, MPI_Comm comm)
533 MPI_Request request = NULL; /* MC needs the comm to be set to NULL during the call */
534 request = build_request(buf==MPI_BOTTOM ? (void*)0 : buf, count, datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(comm), dst), tag,
535 comm, NON_PERSISTENT | SSEND | SEND);
537 smpi_mpi_start(request);
538 smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
542 void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
543 int dst, int sendtag, void *recvbuf, int recvcount,
544 MPI_Datatype recvtype, int src, int recvtag,
545 MPI_Comm comm, MPI_Status * status)
547 MPI_Request requests[2];
549 int myid=smpi_process_index();
550 if ((smpi_group_index(smpi_comm_group(comm), dst) == myid) && (smpi_group_index(smpi_comm_group(comm), src) == myid)) {
551 smpi_datatype_copy(sendbuf, sendcount, sendtype,
552 recvbuf, recvcount, recvtype);
556 smpi_isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
558 smpi_irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm);
559 smpi_mpi_startall(2, requests);
560 smpi_mpi_waitall(2, requests, stats);
561 smpi_mpi_request_free(&requests[0]);
562 smpi_mpi_request_free(&requests[1]);
563 if(status != MPI_STATUS_IGNORE) {
564 // Copy receive status
569 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype)
571 return status->count / smpi_datatype_size(datatype);
574 static void finish_wait(MPI_Request * request, MPI_Status * status)
576 MPI_Request req = *request;
577 smpi_empty_status(status);
579 if(!(req->detached && req->flags & SEND)
580 && !(req->flags & PREPARED)){
581 if(status != MPI_STATUS_IGNORE) {
582 int src = req->src == MPI_ANY_SOURCE ? req->real_src : req->src;
583 status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(req->comm), src);
584 status->MPI_TAG = req->tag == MPI_ANY_TAG ? req->real_tag : req->tag;
585 status->MPI_ERROR = req->truncated ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
586 // this handles the case were size in receive differs from size in send
587 // FIXME: really this should just contain the count of receive-type blocks,
589 status->count = req->real_size;
592 print_request("Finishing", req);
593 MPI_Datatype datatype = req->old_type;
595 if(datatype->has_subtype == 1){
596 if (!_xbt_replay_is_active()){
597 if( smpi_privatize_global_variables
598 && ((char*)req->old_buf >= start_data_exe)
599 && ((char*)req->old_buf < start_data_exe + size_data_exe )
601 XBT_VERB("Privatization : We are unserializing to a zone in global memory - Switch data segment ");
602 switch_data_segment(smpi_process_index());
605 // This part handles the problem of non-contignous memory
606 // the unserialization at the reception
607 s_smpi_subtype_t *subtype = datatype->substruct;
608 if(req->flags & RECV) {
609 subtype->unserialize(req->buf, req->old_buf, req->real_size/smpi_datatype_size(datatype) , datatype->substruct);
611 if(req->detached == 0) free(req->buf);
613 smpi_comm_unuse(req->comm);
614 smpi_datatype_unuse(datatype);
619 if (TRACE_smpi_view_internals()) {
620 if(req->flags & RECV){
621 int rank = smpi_process_index();
622 int src_traced = (req->src == MPI_ANY_SOURCE ? req->real_src : req->src);
623 TRACE_smpi_recv(rank, src_traced, rank);
628 if(req->detached_sender!=NULL){
629 smpi_mpi_request_free(&(req->detached_sender));
631 if(req->flags & PERSISTENT)
633 req->flags |= FINISHED;
635 smpi_mpi_request_free(request);
639 int smpi_mpi_test(MPI_Request * request, MPI_Status * status) {
642 //assume that request is not MPI_REQUEST_NULL (filtered in PMPI_Test or smpi_mpi_testall before)
643 smpi_empty_status(status);
645 if (!((*request)->flags & PREPARED)) {
646 if ((*request)->action != NULL)
647 flag = simcall_comm_test((*request)->action);
649 finish_wait(request, status);
650 if (*request != MPI_REQUEST_NULL && !((*request)->flags & PERSISTENT))
651 *request = MPI_REQUEST_NULL;
657 int smpi_mpi_testany(int count, MPI_Request requests[], int *index,
664 *index = MPI_UNDEFINED;
666 comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
667 map = xbt_new(int, count);
669 for(i = 0; i < count; i++) {
670 if ((requests[i] != MPI_REQUEST_NULL) && requests[i]->action &&
671 !(requests[i]->flags & PREPARED)) {
672 xbt_dynar_push(comms, &requests[i]->action);
678 i = simcall_comm_testany(comms);
679 // not MPI_UNDEFINED, as this is a simix return code
682 finish_wait(&requests[*index], status);
683 if (requests[*index] != MPI_REQUEST_NULL && (requests[*index]->flags & NON_PERSISTENT))
684 requests[*index] = MPI_REQUEST_NULL;
688 //all requests are null or inactive, return true
690 smpi_empty_status(status);
693 xbt_dynar_free(&comms);
699 int smpi_mpi_testall(int count, MPI_Request requests[],
703 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
706 for(i=0; i<count; i++){
707 if (requests[i] != MPI_REQUEST_NULL && !(requests[i]->flags & PREPARED)) {
708 if (smpi_mpi_test(&requests[i], pstat)!=1){
711 requests[i]=MPI_REQUEST_NULL;
714 smpi_empty_status(pstat);
716 if(status != MPI_STATUSES_IGNORE) {
723 void smpi_mpi_probe(int source, int tag, MPI_Comm comm, MPI_Status* status){
725 //FIXME find another wait to avoid busy waiting ?
726 // the issue here is that we have to wait on a nonexistent comm
728 smpi_mpi_iprobe(source, tag, comm, &flag, status);
729 XBT_DEBUG("Busy Waiting on probing : %d", flag);
733 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
735 MPI_Request request =build_request(NULL, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), source), smpi_comm_rank(comm), tag,
736 comm, PERSISTENT | RECV);
738 //to avoid deadlock, we have to sleep some time here, or the timer won't advance and we will only do iprobe simcalls
739 double sleeptime= sg_cfg_get_double("smpi/iprobe");
740 //multiplier to the sleeptime, to increase speed of execution, each failed iprobe will increase it
741 static int nsleeps = 1;
743 simcall_process_sleep(sleeptime);
745 // behave like a receive, but don't do it
748 print_request("New iprobe", request);
749 // We have to test both mailboxes as we don't know if we will receive one one or another
750 if (sg_cfg_get_int("smpi/async_small_thres")>0){
751 mailbox = smpi_process_mailbox_small();
752 XBT_DEBUG("trying to probe the perm recv mailbox");
753 request->action = simcall_comm_iprobe(mailbox, request->src, request->tag, &match_recv, (void*)request);
755 if (request->action==NULL){
756 mailbox = smpi_process_mailbox();
757 XBT_DEBUG("trying to probe the other mailbox");
758 request->action = simcall_comm_iprobe(mailbox, request->src, request->tag, &match_recv, (void*)request);
762 MPI_Request req = (MPI_Request)SIMIX_comm_get_src_data(request->action);
764 if(status != MPI_STATUS_IGNORE && !(req->flags & PREPARED)) {
765 status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(comm), req->src);
766 status->MPI_TAG = req->tag;
767 status->MPI_ERROR = MPI_SUCCESS;
768 status->count = req->real_size;
770 nsleeps=1;//reset the number of sleeps we will do next time
776 smpi_mpi_request_free(&request);
781 void smpi_mpi_wait(MPI_Request * request, MPI_Status * status)
783 print_request("Waiting", *request);
784 if ((*request)->flags & PREPARED) {
785 smpi_empty_status(status);
789 if ((*request)->action != NULL) { // this is not a detached send
790 simcall_comm_wait((*request)->action, -1.0);
792 if(MC_is_active() && (*request)->action)
793 (*request)->action->comm.dst_data = NULL; // dangling pointer : dst_data is freed with a wait, need to set it to NULL for system state comparison
797 finish_wait(request, status);
798 if (*request != MPI_REQUEST_NULL && ((*request)->flags & NON_PERSISTENT))
799 *request = MPI_REQUEST_NULL;
800 // FIXME for a detached send, finish_wait is not called:
803 int smpi_mpi_waitany(int count, MPI_Request requests[],
810 index = MPI_UNDEFINED;
812 // Wait for a request to complete
813 comms = xbt_dynar_new(sizeof(smx_action_t), NULL);
814 map = xbt_new(int, count);
816 XBT_DEBUG("Wait for one of %d", count);
817 for(i = 0; i < count; i++) {
818 if (requests[i] != MPI_REQUEST_NULL
819 && !(requests[i]->flags & PREPARED)
820 && !(requests[i]->flags & FINISHED)) {
821 if (requests[i]->action != NULL) {
822 XBT_DEBUG("Waiting any %p ", requests[i]);
823 xbt_dynar_push(comms, &requests[i]->action);
827 //This is a finished detached request, let's return this one
828 size=0;//so we free the dynar but don't do the waitany call
830 finish_wait(&requests[i], status);//cleanup if refcount = 0
831 if (requests[i] != MPI_REQUEST_NULL && (requests[i]->flags & NON_PERSISTENT))
832 requests[i]=MPI_REQUEST_NULL;//set to null
838 i = simcall_comm_waitany(comms);
840 // not MPI_UNDEFINED, as this is a simix return code
843 finish_wait(&requests[index], status);
844 if (requests[i] != MPI_REQUEST_NULL && (requests[i]->flags & NON_PERSISTENT))
845 requests[index] = MPI_REQUEST_NULL;
849 xbt_dynar_free(&comms);
852 if (index==MPI_UNDEFINED)
853 smpi_empty_status(status);
858 int smpi_mpi_waitall(int count, MPI_Request requests[],
863 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
864 int retvalue = MPI_SUCCESS;
865 //tag invalid requests in the set
866 if (status != MPI_STATUSES_IGNORE) {
867 for (c = 0; c < count; c++) {
868 if (requests[c] == MPI_REQUEST_NULL || requests[c]->dst == MPI_PROC_NULL ||
869 (requests[c]->flags & PREPARED)) {
870 smpi_empty_status(&status[c]);
871 } else if (requests[c]->src == MPI_PROC_NULL) {
872 smpi_empty_status(&status[c]);
873 status[c].MPI_SOURCE = MPI_PROC_NULL;
877 for(c = 0; c < count; c++) {
879 if (MC_is_active()) {
880 smpi_mpi_wait(&requests[c], pstat);
883 index = smpi_mpi_waitany(count, requests, pstat);
884 if (index == MPI_UNDEFINED)
886 if (requests[index] != MPI_REQUEST_NULL && (requests[index]->flags & NON_PERSISTENT))
887 requests[index]=MPI_REQUEST_NULL;
889 if (status != MPI_STATUSES_IGNORE) {
890 status[index] = *pstat;
891 if (status[index].MPI_ERROR == MPI_ERR_TRUNCATE)
892 retvalue = MPI_ERR_IN_STATUS;
899 int smpi_mpi_waitsome(int incount, MPI_Request requests[], int *indices,
904 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
907 for(i = 0; i < incount; i++)
909 index=smpi_mpi_waitany(incount, requests, pstat);
910 if(index!=MPI_UNDEFINED){
911 indices[count] = index;
913 if(status != MPI_STATUSES_IGNORE) {
914 status[index] = *pstat;
916 if (requests[index] != MPI_REQUEST_NULL && (requests[index]->flags & NON_PERSISTENT))
917 requests[index]=MPI_REQUEST_NULL;
919 return MPI_UNDEFINED;
925 int smpi_mpi_testsome(int incount, MPI_Request requests[], int *indices,
928 int i, count, count_dead;
930 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
934 for(i = 0; i < incount; i++) {
935 if((requests[i] != MPI_REQUEST_NULL)) {
936 if(smpi_mpi_test(&requests[i], pstat)) {
939 if(status != MPI_STATUSES_IGNORE) {
942 if ((requests[i] != MPI_REQUEST_NULL) && requests[i]->flags & NON_PERSISTENT)
943 requests[i]=MPI_REQUEST_NULL;
949 if(count_dead==incount)return MPI_UNDEFINED;
953 void smpi_mpi_bcast(void *buf, int count, MPI_Datatype datatype, int root,
956 // arity=2: a binary tree, arity=4 seem to be a good setting (see P2P-MPI))
957 nary_tree_bcast(buf, count, datatype, root, comm, 4);
960 void smpi_mpi_barrier(MPI_Comm comm)
962 // arity=2: a binary tree, arity=4 seem to be a good setting (see P2P-MPI))
963 nary_tree_barrier(comm, 4);
966 void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
967 void *recvbuf, int recvcount, MPI_Datatype recvtype,
968 int root, MPI_Comm comm)
970 int system_tag = COLL_TAG_GATHER;
971 int rank, size, src, index;
972 MPI_Aint lb = 0, recvext = 0;
973 MPI_Request *requests;
975 rank = smpi_comm_rank(comm);
976 size = smpi_comm_size(comm);
978 // Send buffer to root
979 smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm);
981 // FIXME: check for errors
982 smpi_datatype_extent(recvtype, &lb, &recvext);
983 // Local copy from root
984 smpi_datatype_copy(sendbuf, sendcount, sendtype,
985 (char *)recvbuf + root * recvcount * recvext, recvcount, recvtype);
986 // Receive buffers from senders
987 requests = xbt_new(MPI_Request, size - 1);
989 for(src = 0; src < size; src++) {
991 requests[index] = smpi_irecv_init((char *)recvbuf + src * recvcount * recvext,
993 src, system_tag, comm);
997 // Wait for completion of irecv's.
998 smpi_mpi_startall(size - 1, requests);
999 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
1000 for(src = 0; src < size-1; src++) {
1001 smpi_mpi_request_free(&requests[src]);
1008 void smpi_mpi_reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
1009 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1013 int rank = smpi_process_index();
1016 /* arbitrarily choose root as rank 0 */
1017 size = smpi_comm_size(comm);
1019 displs = xbt_new(int, size);
1020 for (i = 0; i < size; i++) {
1022 count += recvcounts[i];
1024 tmpbuf=(void*)xbt_malloc(count*smpi_datatype_get_extent(datatype));
1025 mpi_coll_reduce_fun(sendbuf, tmpbuf, count, datatype, op, 0, comm);
1026 smpi_mpi_scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf,
1027 recvcounts[rank], datatype, 0, comm);
1032 void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1033 void *recvbuf, int *recvcounts, int *displs,
1034 MPI_Datatype recvtype, int root, MPI_Comm comm)
1036 int system_tag = COLL_TAG_GATHERV;
1037 int rank, size, src, index;
1038 MPI_Aint lb = 0, recvext = 0;
1039 MPI_Request *requests;
1041 rank = smpi_comm_rank(comm);
1042 size = smpi_comm_size(comm);
1044 // Send buffer to root
1045 smpi_mpi_send(sendbuf, sendcount, sendtype, root, system_tag, comm);
1047 // FIXME: check for errors
1048 smpi_datatype_extent(recvtype, &lb, &recvext);
1049 // Local copy from root
1050 smpi_datatype_copy(sendbuf, sendcount, sendtype,
1051 (char *)recvbuf + displs[root] * recvext,
1052 recvcounts[root], recvtype);
1053 // Receive buffers from senders
1054 requests = xbt_new(MPI_Request, size - 1);
1056 for(src = 0; src < size; src++) {
1059 smpi_irecv_init((char *)recvbuf + displs[src] * recvext,
1060 recvcounts[src], recvtype, src, system_tag, comm);
1064 // Wait for completion of irecv's.
1065 smpi_mpi_startall(size - 1, requests);
1066 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
1067 for(src = 0; src < size-1; src++) {
1068 smpi_mpi_request_free(&requests[src]);
1074 void smpi_mpi_allgather(void *sendbuf, int sendcount,
1075 MPI_Datatype sendtype, void *recvbuf,
1076 int recvcount, MPI_Datatype recvtype,
1079 int system_tag = COLL_TAG_ALLGATHER;
1080 int rank, size, other, index;
1081 MPI_Aint lb = 0, recvext = 0;
1082 MPI_Request *requests;
1084 rank = smpi_comm_rank(comm);
1085 size = smpi_comm_size(comm);
1086 // FIXME: check for errors
1087 smpi_datatype_extent(recvtype, &lb, &recvext);
1088 // Local copy from self
1089 smpi_datatype_copy(sendbuf, sendcount, sendtype,
1090 (char *)recvbuf + rank * recvcount * recvext, recvcount,
1092 // Send/Recv buffers to/from others;
1093 requests = xbt_new(MPI_Request, 2 * (size - 1));
1095 for(other = 0; other < size; other++) {
1098 smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag,
1101 requests[index] = smpi_irecv_init((char *)recvbuf + other * recvcount * recvext,
1102 recvcount, recvtype, other,
1107 // Wait for completion of all comms.
1108 smpi_mpi_startall(2 * (size - 1), requests);
1109 smpi_mpi_waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
1110 for(other = 0; other < 2*(size-1); other++) {
1111 smpi_mpi_request_free(&requests[other]);
1116 void smpi_mpi_allgatherv(void *sendbuf, int sendcount,
1117 MPI_Datatype sendtype, void *recvbuf,
1118 int *recvcounts, int *displs,
1119 MPI_Datatype recvtype, MPI_Comm comm)
1121 int system_tag = COLL_TAG_ALLGATHERV;
1122 int rank, size, other, index;
1123 MPI_Aint lb = 0, recvext = 0;
1124 MPI_Request *requests;
1126 rank = smpi_comm_rank(comm);
1127 size = smpi_comm_size(comm);
1128 // FIXME: check for errors
1129 smpi_datatype_extent(recvtype, &lb, &recvext);
1130 // Local copy from self
1131 smpi_datatype_copy(sendbuf, sendcount, sendtype,
1132 (char *)recvbuf + displs[rank] * recvext,
1133 recvcounts[rank], recvtype);
1134 // Send buffers to others;
1135 requests = xbt_new(MPI_Request, 2 * (size - 1));
1137 for(other = 0; other < size; other++) {
1140 smpi_isend_init(sendbuf, sendcount, sendtype, other, system_tag,
1144 smpi_irecv_init((char *)recvbuf + displs[other] * recvext, recvcounts[other],
1145 recvtype, other, system_tag, comm);
1149 // Wait for completion of all comms.
1150 smpi_mpi_startall(2 * (size - 1), requests);
1151 smpi_mpi_waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
1152 for(other = 0; other < 2*(size-1); other++) {
1153 smpi_mpi_request_free(&requests[other]);
1158 void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
1159 void *recvbuf, int recvcount, MPI_Datatype recvtype,
1160 int root, MPI_Comm comm)
1162 int system_tag = COLL_TAG_SCATTER;
1163 int rank, size, dst, index;
1164 MPI_Aint lb = 0, sendext = 0;
1165 MPI_Request *requests;
1167 rank = smpi_comm_rank(comm);
1168 size = smpi_comm_size(comm);
1170 // Recv buffer from root
1171 smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm,
1174 // FIXME: check for errors
1175 smpi_datatype_extent(sendtype, &lb, &sendext);
1176 // Local copy from root
1177 if(recvbuf!=MPI_IN_PLACE){
1178 smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
1179 sendcount, sendtype, recvbuf, recvcount, recvtype);
1181 // Send buffers to receivers
1182 requests = xbt_new(MPI_Request, size - 1);
1184 for(dst = 0; dst < size; dst++) {
1186 requests[index] = smpi_isend_init((char *)sendbuf + dst * sendcount * sendext,
1187 sendcount, sendtype, dst,
1192 // Wait for completion of isend's.
1193 smpi_mpi_startall(size - 1, requests);
1194 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
1195 for(dst = 0; dst < size-1; dst++) {
1196 smpi_mpi_request_free(&requests[dst]);
1202 void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
1203 MPI_Datatype sendtype, void *recvbuf, int recvcount,
1204 MPI_Datatype recvtype, int root, MPI_Comm comm)
1206 int system_tag = COLL_TAG_SCATTERV;
1207 int rank, size, dst, index;
1208 MPI_Aint lb = 0, sendext = 0;
1209 MPI_Request *requests;
1211 rank = smpi_comm_rank(comm);
1212 size = smpi_comm_size(comm);
1214 // Recv buffer from root
1215 smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm,
1218 // FIXME: check for errors
1219 smpi_datatype_extent(sendtype, &lb, &sendext);
1220 // Local copy from root
1221 if(recvbuf!=MPI_IN_PLACE){
1222 smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
1223 sendtype, recvbuf, recvcount, recvtype);
1225 // Send buffers to receivers
1226 requests = xbt_new(MPI_Request, size - 1);
1228 for(dst = 0; dst < size; dst++) {
1231 smpi_isend_init((char *)sendbuf + displs[dst] * sendext, sendcounts[dst],
1232 sendtype, dst, system_tag, comm);
1236 // Wait for completion of isend's.
1237 smpi_mpi_startall(size - 1, requests);
1238 smpi_mpi_waitall(size - 1, requests, MPI_STATUS_IGNORE);
1239 for(dst = 0; dst < size-1; dst++) {
1240 smpi_mpi_request_free(&requests[dst]);
1246 void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
1247 MPI_Datatype datatype, MPI_Op op, int root,
1250 int system_tag = COLL_TAG_REDUCE;
1251 int rank, size, src, index;
1252 MPI_Aint lb = 0, dataext = 0;
1253 MPI_Request *requests;
1257 char* sendtmpbuf = (char*) sendbuf;
1258 if( sendbuf == MPI_IN_PLACE ) {
1259 sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
1260 smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
1263 rank = smpi_comm_rank(comm);
1264 size = smpi_comm_size(comm);
1265 //non commutative case, use a working algo from openmpi
1266 if(!smpi_op_is_commute(op)){
1267 smpi_coll_tuned_reduce_ompi_basic_linear(sendtmpbuf, recvbuf, count,
1268 datatype, op, root, comm);
1273 // Send buffer to root
1274 smpi_mpi_send(sendtmpbuf, count, datatype, root, system_tag, comm);
1276 // FIXME: check for errors
1277 smpi_datatype_extent(datatype, &lb, &dataext);
1278 // Local copy from root
1279 if (sendtmpbuf && recvbuf)
1280 smpi_datatype_copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
1281 // Receive buffers from senders
1282 //TODO: make a MPI_barrier here ?
1283 requests = xbt_new(MPI_Request, size - 1);
1284 tmpbufs = xbt_new(void *, size - 1);
1286 for(src = 0; src < size; src++) {
1288 // FIXME: possibly overkill we we have contiguous/noncontiguous data
1290 tmpbufs[index] = xbt_malloc(count * dataext);
1292 smpi_irecv_init(tmpbufs[index], count, datatype, src,
1297 // Wait for completion of irecv's.
1298 smpi_mpi_startall(size - 1, requests);
1299 for(src = 0; src < size - 1; src++) {
1300 index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
1301 XBT_DEBUG("finished waiting any request with index %d", index);
1302 if(index == MPI_UNDEFINED) {
1305 smpi_mpi_request_free(&requests[index]);
1307 if(op) /* op can be MPI_OP_NULL that does nothing */
1308 smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
1310 for(index = 0; index < size - 1; index++) {
1311 xbt_free(tmpbufs[index]);
1316 if( sendbuf == MPI_IN_PLACE ) {
1317 xbt_free(sendtmpbuf);
1322 void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count,
1323 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1325 smpi_mpi_reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
1326 smpi_mpi_bcast(recvbuf, count, datatype, 0, comm);
1329 void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count,
1330 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1332 int system_tag = -888;
1333 int rank, size, other, index;
1334 MPI_Aint lb = 0, dataext = 0;
1335 MPI_Request *requests;
1338 rank = smpi_comm_rank(comm);
1339 size = smpi_comm_size(comm);
1341 // FIXME: check for errors
1342 smpi_datatype_extent(datatype, &lb, &dataext);
1344 // Local copy from self
1345 smpi_datatype_copy(sendbuf, count, datatype, recvbuf, count, datatype);
1347 // Send/Recv buffers to/from others;
1348 requests = xbt_new(MPI_Request, size - 1);
1349 tmpbufs = xbt_new(void *, rank);
1351 for(other = 0; other < rank; other++) {
1352 // FIXME: possibly overkill we we have contiguous/noncontiguous data
1354 tmpbufs[index] = xbt_malloc(count * dataext);
1356 smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag,
1360 for(other = rank + 1; other < size; other++) {
1362 smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm);
1365 // Wait for completion of all comms.
1366 smpi_mpi_startall(size - 1, requests);
1368 if(smpi_op_is_commute(op)){
1369 for(other = 0; other < size - 1; other++) {
1370 index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
1371 if(index == MPI_UNDEFINED) {
1375 // #Request is below rank: it's a irecv
1376 smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
1380 //non commutative case, wait in order
1381 for(other = 0; other < size - 1; other++) {
1382 smpi_mpi_wait(&(requests[other]), MPI_STATUS_IGNORE);
1384 smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
1388 for(index = 0; index < rank; index++) {
1389 xbt_free(tmpbufs[index]);
1391 for(index = 0; index < size-1; index++) {
1392 smpi_mpi_request_free(&requests[index]);
1398 void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count,
1399 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
1401 int system_tag = -888;
1402 int rank, size, other, index;
1403 MPI_Aint lb = 0, dataext = 0;
1404 MPI_Request *requests;
1406 int recvbuf_is_empty=1;
1407 rank = smpi_comm_rank(comm);
1408 size = smpi_comm_size(comm);
1410 // FIXME: check for errors
1411 smpi_datatype_extent(datatype, &lb, &dataext);
1413 // Send/Recv buffers to/from others;
1414 requests = xbt_new(MPI_Request, size - 1);
1415 tmpbufs = xbt_new(void *, rank);
1417 for(other = 0; other < rank; other++) {
1418 // FIXME: possibly overkill we we have contiguous/noncontiguous data
1420 tmpbufs[index] = xbt_malloc(count * dataext);
1422 smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag,
1426 for(other = rank + 1; other < size; other++) {
1428 smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm);
1431 // Wait for completion of all comms.
1432 smpi_mpi_startall(size - 1, requests);
1433 if(smpi_op_is_commute(op)){
1434 for(other = 0; other < size - 1; other++) {
1435 index = smpi_mpi_waitany(size - 1, requests, MPI_STATUS_IGNORE);
1436 if(index == MPI_UNDEFINED) {
1440 if(recvbuf_is_empty){
1441 smpi_datatype_copy(tmpbufs[index], count, datatype, recvbuf, count, datatype);
1444 // #Request is below rank: it's a irecv
1445 smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
1449 //non commutative case, wait in order
1450 for(other = 0; other < size - 1; other++) {
1451 smpi_mpi_wait(&(requests[other]), MPI_STATUS_IGNORE);
1453 if(recvbuf_is_empty){
1454 smpi_datatype_copy(tmpbufs[other], count, datatype, recvbuf, count, datatype);
1456 }else smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
1460 for(index = 0; index < rank; index++) {
1461 xbt_free(tmpbufs[index]);
1463 for(index = 0; index < size-1; index++) {
1464 smpi_mpi_request_free(&requests[index]);