1 /* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "smpi_request.hpp"
10 #include "simgrid/Exception.hpp"
11 #include "simgrid/s4u/Exec.hpp"
12 #include "smpi_comm.hpp"
13 #include "smpi_datatype.hpp"
14 #include "smpi_host.hpp"
15 #include "smpi_op.hpp"
16 #include "src/kernel/activity/CommImpl.hpp"
17 #include "src/mc/mc_replay.hpp"
18 #include "src/smpi/include/smpi_actor.hpp"
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_request, smpi, "Logging specific to SMPI (request)");
25 static simgrid::config::Flag<double> smpi_iprobe_sleep(
26 "smpi/iprobe", "Minimum time to inject inside a call to MPI_Iprobe", 1e-4);
27 static simgrid::config::Flag<double> smpi_test_sleep(
28 "smpi/test", "Minimum time to inject inside a call to MPI_Test", 1e-4);
30 std::vector<s_smpi_factor_t> smpi_ois_values;
32 extern void (*smpi_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*, void*, size_t);
37 Request::Request(const void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm,
38 unsigned flags, MPI_Op op)
39 : buf_(const_cast<void*>(buf))
41 , size_(datatype->size() * count)
51 if(op != MPI_REPLACE && op != MPI_OP_NULL)
55 detached_sender_ = nullptr;
60 if (flags & MPI_REQ_PERSISTENT)
65 nbc_requests_=nullptr;
74 void Request::unref(MPI_Request* request)
76 if((*request) != MPI_REQUEST_NULL){
77 (*request)->refcount_--;
78 if((*request)->refcount_ < 0) {
79 (*request)->print_request("wrong refcount");
80 xbt_die("Whoops, wrong refcount");
82 if((*request)->refcount_==0){
83 if ((*request)->flags_ & MPI_REQ_GENERALIZED){
84 ((*request)->generalized_funcs)->free_fn(((*request)->generalized_funcs)->extra_state);
86 Comm::unref((*request)->comm_);
87 Datatype::unref((*request)->old_type_);
89 if ((*request)->op_!=MPI_REPLACE && (*request)->op_!=MPI_OP_NULL)
90 Op::unref(&(*request)->op_);
92 (*request)->print_request("Destroying");
94 *request = MPI_REQUEST_NULL;
96 (*request)->print_request("Decrementing");
99 xbt_die("freeing an already free request");
103 bool Request::match_common(MPI_Request req, MPI_Request sender, MPI_Request receiver)
105 xbt_assert(sender, "Cannot match against null sender");
106 xbt_assert(receiver, "Cannot match against null receiver");
107 XBT_DEBUG("Trying to match %s of sender src %d against %d, tag %d against %d, id %d against %d",
108 (req == receiver ? "send" : "recv"), sender->src_, receiver->src_, sender->tag_, receiver->tag_,
109 sender->comm_->id(), receiver->comm_->id());
111 if ((receiver->comm_->id() == MPI_UNDEFINED || sender->comm_->id() == MPI_UNDEFINED ||
112 receiver->comm_->id() == sender->comm_->id()) &&
113 ((receiver->src_ == MPI_ANY_SOURCE && (receiver->comm_->group()->rank(sender->src_) != MPI_UNDEFINED)) ||
114 receiver->src_ == sender->src_) &&
115 ((receiver->tag_ == MPI_ANY_TAG && sender->tag_ >= 0) || receiver->tag_ == sender->tag_)) {
116 // we match, we can transfer some values
117 if (receiver->src_ == MPI_ANY_SOURCE)
118 receiver->real_src_ = sender->src_;
119 if (receiver->tag_ == MPI_ANY_TAG)
120 receiver->real_tag_ = sender->tag_;
121 if (receiver->real_size_ < sender->real_size_ && ((receiver->flags_ & MPI_REQ_PROBE) == 0 )){
122 XBT_DEBUG("Truncating message - should not happen: receiver size : %zu < sender size : %zu", receiver->real_size_, sender->real_size_);
123 receiver->truncated_ = true;
125 if (sender->detached_)
126 receiver->detached_sender_ = sender; // tie the sender to the receiver, as it is detached and has to be freed in
128 if (req->cancelled_ == 0)
129 req->cancelled_ = -1; // mark as uncancelable
130 XBT_DEBUG("match succeeded");
136 void Request::init_buffer(int count){
137 void *old_buf = nullptr;
138 // FIXME Handle the case of a partial shared malloc.
139 // This part handles the problem of non-contiguous memory (for the unserialization at the reception)
140 if ((((flags_ & MPI_REQ_RECV) != 0) && ((flags_ & MPI_REQ_ACCUMULATE) != 0)) || (old_type_->flags() & DT_FLAG_DERIVED)) {
141 // This part handles the problem of non-contiguous memory
146 buf_ = xbt_malloc(count*old_type_->size());
147 if ((old_type_->flags() & DT_FLAG_DERIVED) && ((flags_ & MPI_REQ_SEND) != 0)) {
148 old_type_->serialize(old_buf, buf_, count);
155 bool Request::match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl*)
157 auto ref = static_cast<MPI_Request>(a);
158 auto req = static_cast<MPI_Request>(b);
159 return match_common(req, req, ref);
162 bool Request::match_send(void* a, void* b, simgrid::kernel::activity::CommImpl*)
164 auto ref = static_cast<MPI_Request>(a);
165 auto req = static_cast<MPI_Request>(b);
166 return match_common(req, ref, req);
169 void Request::print_request(const char* message) const
171 XBT_VERB("%s request %p [buf = %p, size = %zu, src = %d, dst = %d, tag = %d, flags = %x]",
172 message, this, buf_, size_, src_, dst_, tag_, flags_);
175 /* factories, to hide the internal flags from the caller */
176 MPI_Request Request::bsend_init(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
178 return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
179 comm->group()->actor(dst)->get_pid(), tag, comm,
180 MPI_REQ_PERSISTENT | MPI_REQ_SEND | MPI_REQ_PREPARED | MPI_REQ_BSEND);
183 MPI_Request Request::send_init(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
185 return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
186 comm->group()->actor(dst)->get_pid(), tag, comm,
187 MPI_REQ_PERSISTENT | MPI_REQ_SEND | MPI_REQ_PREPARED);
190 MPI_Request Request::ssend_init(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
192 return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
193 comm->group()->actor(dst)->get_pid(), tag, comm,
194 MPI_REQ_PERSISTENT | MPI_REQ_SSEND | MPI_REQ_SEND | MPI_REQ_PREPARED);
197 MPI_Request Request::isend_init(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
199 return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
200 comm->group()->actor(dst)->get_pid(), tag, comm,
201 MPI_REQ_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SEND | MPI_REQ_PREPARED);
205 MPI_Request Request::rma_send_init(const void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm,
208 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
210 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, comm->group()->actor(src)->get_pid(),
211 comm->group()->actor(dst)->get_pid(), tag, comm,
212 MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SEND | MPI_REQ_PREPARED);
214 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, comm->group()->actor(src)->get_pid(),
215 comm->group()->actor(dst)->get_pid(), tag, comm,
216 MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SEND | MPI_REQ_PREPARED |
217 MPI_REQ_ACCUMULATE, op);
222 MPI_Request Request::recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm)
224 return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype,
225 src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(src)->get_pid(),
226 simgrid::s4u::this_actor::get_pid(), tag, comm,
227 MPI_REQ_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PREPARED);
230 MPI_Request Request::rma_recv_init(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm,
233 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
235 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, comm->group()->actor(src)->get_pid(),
236 comm->group()->actor(dst)->get_pid(), tag, comm,
237 MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PREPARED);
239 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, comm->group()->actor(src)->get_pid(),
240 comm->group()->actor(dst)->get_pid(), tag, comm,
241 MPI_REQ_RMA | MPI_REQ_NON_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PREPARED | MPI_REQ_ACCUMULATE, op);
246 MPI_Request Request::irecv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm)
248 return new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype,
249 src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(src)->get_pid(),
250 simgrid::s4u::this_actor::get_pid(), tag, comm,
251 MPI_REQ_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PREPARED);
254 MPI_Request Request::ibsend(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
256 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
257 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
258 comm->group()->actor(dst)->get_pid(), tag, comm,
259 MPI_REQ_NON_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SEND | MPI_REQ_BSEND);
264 MPI_Request Request::isend(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
266 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
267 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
268 comm->group()->actor(dst)->get_pid(), tag, comm,
269 MPI_REQ_NON_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SEND);
274 MPI_Request Request::issend(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
276 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
277 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
278 comm->group()->actor(dst)->get_pid(), tag, comm,
279 MPI_REQ_NON_PERSISTENT | MPI_REQ_ISEND | MPI_REQ_SSEND | MPI_REQ_SEND);
285 MPI_Request Request::irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm)
287 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
288 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype,
289 src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(src)->get_pid(),
290 simgrid::s4u::this_actor::get_pid(), tag, comm, MPI_REQ_NON_PERSISTENT | MPI_REQ_RECV);
295 void Request::recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status)
297 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
298 request = irecv(buf, count, datatype, src, tag, comm);
299 wait(&request,status);
303 void Request::bsend(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
305 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
306 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
307 comm->group()->actor(dst)->get_pid(), tag, comm, MPI_REQ_NON_PERSISTENT | MPI_REQ_SEND | MPI_REQ_BSEND);
310 wait(&request, MPI_STATUS_IGNORE);
314 void Request::send(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
316 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
317 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
318 comm->group()->actor(dst)->get_pid(), tag, comm, MPI_REQ_NON_PERSISTENT | MPI_REQ_SEND);
321 wait(&request, MPI_STATUS_IGNORE);
325 void Request::ssend(const void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm)
327 MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
328 request = new Request(buf == MPI_BOTTOM ? nullptr : buf, count, datatype, simgrid::s4u::this_actor::get_pid(),
329 comm->group()->actor(dst)->get_pid(), tag, comm,
330 MPI_REQ_NON_PERSISTENT | MPI_REQ_SSEND | MPI_REQ_SEND);
333 wait(&request,MPI_STATUS_IGNORE);
337 void Request::sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,int dst, int sendtag,
338 void *recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag,
339 MPI_Comm comm, MPI_Status * status)
341 std::array<MPI_Request, 2> requests;
342 std::array<MPI_Status, 2> stats;
343 int myid = simgrid::s4u::this_actor::get_pid();
344 if ((comm->group()->actor(dst)->get_pid() == myid) && (comm->group()->actor(src)->get_pid() == myid)) {
345 Datatype::copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
346 if (status != MPI_STATUS_IGNORE) {
347 status->MPI_SOURCE = src;
348 status->MPI_TAG = recvtag;
349 status->MPI_ERROR = MPI_SUCCESS;
350 status->count = sendcount * sendtype->size();
354 requests[0] = isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
355 requests[1] = irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm);
356 startall(2, requests.data());
357 waitall(2, requests.data(), stats.data());
360 if(status != MPI_STATUS_IGNORE) {
361 // Copy receive status
366 void Request::start()
368 s4u::Mailbox* mailbox;
370 xbt_assert(action_ == nullptr, "Cannot (re-)start unfinished communication");
371 //reinitialize temporary buffer for persistent requests
372 if(real_size_ > 0 && flags_ & MPI_REQ_FINISHED){
374 init_buffer(real_size_/old_type_->size());
376 flags_ &= ~MPI_REQ_PREPARED;
377 flags_ &= ~MPI_REQ_FINISHED;
380 // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later
382 if ((flags_ & MPI_REQ_RECV) != 0) {
383 this->print_request("New recv");
385 simgrid::smpi::ActorExt* process = smpi_process_remote(simgrid::s4u::Actor::by_pid(dst_));
387 simgrid::s4u::MutexPtr mut = process->mailboxes_mutex();
388 if (smpi_cfg_async_small_thresh() != 0 || (flags_ & MPI_REQ_RMA) != 0)
391 if (smpi_cfg_async_small_thresh() == 0 && (flags_ & MPI_REQ_RMA) == 0) {
392 mailbox = process->mailbox();
393 } else if (((flags_ & MPI_REQ_RMA) != 0) || static_cast<int>(size_) < smpi_cfg_async_small_thresh()) {
394 //We have to check both mailboxes (because SSEND messages are sent to the large mbox).
395 //begin with the more appropriate one : the small one.
396 mailbox = process->mailbox_small();
397 XBT_DEBUG("Is there a corresponding send already posted in the small mailbox %s (in case of SSEND)?",
398 mailbox->get_cname());
399 simgrid::kernel::activity::ActivityImplPtr action = mailbox->iprobe(0, &match_recv, static_cast<void*>(this));
401 if (action == nullptr) {
402 mailbox = process->mailbox();
403 XBT_DEBUG("No, nothing in the small mailbox test the other one : %s", mailbox->get_cname());
404 action = mailbox->iprobe(0, &match_recv, static_cast<void*>(this));
405 if (action == nullptr) {
406 XBT_DEBUG("Still nothing, switch back to the small mailbox : %s", mailbox->get_cname());
407 mailbox = process->mailbox_small();
410 XBT_DEBUG("yes there was something for us in the large mailbox");
413 mailbox = process->mailbox_small();
414 XBT_DEBUG("Is there a corresponding send already posted the small mailbox?");
415 simgrid::kernel::activity::ActivityImplPtr action = mailbox->iprobe(0, &match_recv, static_cast<void*>(this));
417 if (action == nullptr) {
418 XBT_DEBUG("No, nothing in the permanent receive mailbox");
419 mailbox = process->mailbox();
421 XBT_DEBUG("yes there was something for us in the small mailbox");
425 action_ = simcall_comm_irecv(
426 process->get_actor()->get_impl(), mailbox->get_impl(), buf_, &real_size_, &match_recv,
427 process->replaying() ? &smpi_comm_null_copy_buffer_callback : smpi_comm_copy_data_callback, this, -1.0);
428 XBT_DEBUG("recv simcall posted");
430 if (smpi_cfg_async_small_thresh() != 0 || (flags_ & MPI_REQ_RMA) != 0)
432 } else { /* the RECV flag was not set, so this is a send */
433 const simgrid::smpi::ActorExt* process = smpi_process_remote(simgrid::s4u::Actor::by_pid(dst_));
434 xbt_assert(process, "Actor pid=%d is gone??", dst_);
436 if (TRACE_smpi_view_internals()) {
437 TRACE_smpi_send(rank, rank, dst_, tag_, size_);
439 this->print_request("New send");
442 if ((flags_ & MPI_REQ_SSEND) == 0 &&
443 ((flags_ & MPI_REQ_RMA) != 0 || (flags_ & MPI_REQ_BSEND) != 0 ||
444 static_cast<int>(size_) < smpi_cfg_detached_send_thresh())) {
445 void *oldbuf = nullptr;
447 XBT_DEBUG("Send request %p is detached", this);
449 if (not(old_type_->flags() & DT_FLAG_DERIVED)) {
451 if (not process->replaying() && oldbuf != nullptr && size_ != 0) {
452 if ((smpi_cfg_privatization() != SmpiPrivStrategies::NONE) &&
453 (static_cast<char*>(buf_) >= smpi_data_exe_start) &&
454 (static_cast<char*>(buf_) < smpi_data_exe_start + smpi_data_exe_size)) {
455 XBT_DEBUG("Privatization : We are sending from a zone inside global memory. Switch data segment ");
456 smpi_switch_data_segment(simgrid::s4u::Actor::by_pid(src_));
458 //we need this temporary buffer even for bsend, as it will be released in the copy callback and we don't have a way to differentiate it
459 //so actually ... don't use manually attached buffer space.
460 buf = xbt_malloc(size_);
461 memcpy(buf,oldbuf,size_);
462 XBT_DEBUG("buf %p copied into %p",oldbuf,buf);
467 //if we are giving back the control to the user without waiting for completion, we have to inject timings
468 double sleeptime = 0.0;
469 if (detached_ || ((flags_ & (MPI_REQ_ISEND | MPI_REQ_SSEND)) != 0)) { // issend should be treated as isend
470 // isend and send timings may be different
471 sleeptime = ((flags_ & MPI_REQ_ISEND) != 0)
472 ? simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->oisend(size_)
473 : simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->osend(size_);
477 simgrid::s4u::this_actor::sleep_for(sleeptime);
478 XBT_DEBUG("sending size of %zu : sleep %f ", size_, sleeptime);
481 simgrid::s4u::MutexPtr mut = process->mailboxes_mutex();
483 if (smpi_cfg_async_small_thresh() != 0 || (flags_ & MPI_REQ_RMA) != 0)
486 if (not(smpi_cfg_async_small_thresh() != 0 || (flags_ & MPI_REQ_RMA) != 0)) {
487 mailbox = process->mailbox();
488 } else if (((flags_ & MPI_REQ_RMA) != 0) || static_cast<int>(size_) < smpi_cfg_async_small_thresh()) { // eager mode
489 mailbox = process->mailbox();
490 XBT_DEBUG("Is there a corresponding recv already posted in the large mailbox %s?", mailbox->get_cname());
491 simgrid::kernel::activity::ActivityImplPtr action = mailbox->iprobe(1, &match_send, static_cast<void*>(this));
492 if (action == nullptr) {
493 if ((flags_ & MPI_REQ_SSEND) == 0) {
494 mailbox = process->mailbox_small();
495 XBT_DEBUG("No, nothing in the large mailbox, message is to be sent on the small one %s",
496 mailbox->get_cname());
498 mailbox = process->mailbox_small();
499 XBT_DEBUG("SSEND : Is there a corresponding recv already posted in the small mailbox %s?",
500 mailbox->get_cname());
501 action = mailbox->iprobe(1, &match_send, static_cast<void*>(this));
502 if (action == nullptr) {
503 XBT_DEBUG("No, we are first, send to large mailbox");
504 mailbox = process->mailbox();
508 XBT_DEBUG("Yes there was something for us in the large mailbox");
511 mailbox = process->mailbox();
512 XBT_DEBUG("Send request %p is in the large mailbox %s (buf: %p)", this, mailbox->get_cname(), buf_);
515 size_t payload_size_ = size_ + 16;//MPI enveloppe size (tag+dest+communicator)
516 action_ = simcall_comm_isend(
517 simgrid::s4u::Actor::by_pid(src_)->get_impl(), mailbox->get_impl(), payload_size_, -1.0, buf, real_size_, &match_send,
518 &xbt_free_f, // how to free the userdata if a detached send fails
519 process->replaying() ? &smpi_comm_null_copy_buffer_callback : smpi_comm_copy_data_callback, this,
520 // detach if msg size < eager/rdv switch limit
522 XBT_DEBUG("send simcall posted");
524 /* FIXME: detached sends are not traceable (action_ == nullptr) */
525 if (action_ != nullptr) {
526 boost::static_pointer_cast<kernel::activity::CommImpl>(action_)->set_tracing_category(
527 smpi_process()->get_tracing_category());
530 if (smpi_cfg_async_small_thresh() != 0 || ((flags_ & MPI_REQ_RMA) != 0))
535 void Request::startall(int count, MPI_Request * requests)
537 if(requests== nullptr)
540 for(int i = 0; i < count; i++) {
541 requests[i]->start();
545 void Request::cancel()
549 if (this->action_ != nullptr)
550 (boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(this->action_))->cancel();
553 int Request::test(MPI_Request * request, MPI_Status * status, int* flag) {
554 // assume that *request is not MPI_REQUEST_NULL (filtered in PMPI_Test or testall before)
555 // to avoid deadlocks if used as a break condition, such as
556 // while (MPI_Test(request, flag, status) && flag) dostuff...
557 // because the time will not normally advance when only calls to MPI_Test are made -> deadlock
558 // multiplier to the sleeptime, to increase speed of execution, each failed test will increase it
559 xbt_assert(*request != MPI_REQUEST_NULL);
561 static int nsleeps = 1;
562 int ret = MPI_SUCCESS;
564 // Are we testing a request meant for non blocking collectives ?
565 // If so, test all the subrequests.
566 if ((*request)->nbc_requests_size_>0){
567 ret = testall((*request)->nbc_requests_size_, (*request)->nbc_requests_, flag, MPI_STATUSES_IGNORE);
569 delete[] (*request)->nbc_requests_;
570 (*request)->nbc_requests_size_=0;
576 if(smpi_test_sleep > 0)
577 simgrid::s4u::this_actor::sleep_for(nsleeps * smpi_test_sleep);
579 Status::empty(status);
581 if (((*request)->flags_ & (MPI_REQ_PREPARED | MPI_REQ_FINISHED)) == 0) {
582 if ((*request)->action_ != nullptr && (*request)->cancelled_ != 1){
584 *flag = simcall_comm_test((*request)->action_.get());
585 } catch (const Exception&) {
590 if (((*request)->flags_ & MPI_REQ_GENERALIZED) && !((*request)->flags_ & MPI_REQ_COMPLETE))
593 finish_wait(request, status); // may invalidate *request
594 if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & MPI_REQ_GENERALIZED)){
595 MPI_Status tmp_status;
596 MPI_Status* mystatus;
597 if (status == MPI_STATUS_IGNORE) {
598 mystatus = &tmp_status;
599 Status::empty(mystatus);
603 ret = ((*request)->generalized_funcs)->query_fn(((*request)->generalized_funcs)->extra_state, mystatus);
605 nsleeps=1;//reset the number of sleeps we will do next time
606 if (*request != MPI_REQUEST_NULL && ((*request)->flags_ & MPI_REQ_PERSISTENT) == 0)
607 *request = MPI_REQUEST_NULL;
608 } else if (smpi_cfg_grow_injected_times()) {
615 int Request::testsome(int incount, MPI_Request requests[], int *count, int *indices, MPI_Status status[])
621 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
624 for (int i = 0; i < incount; i++) {
625 if (requests[i] != MPI_REQUEST_NULL && not (requests[i]->flags_ & MPI_REQ_FINISHED)) {
626 int ret = test(&requests[i], pstat, &flag);
631 if (status != MPI_STATUSES_IGNORE)
632 status[*count] = *pstat;
634 if ((requests[i] != MPI_REQUEST_NULL) && (requests[i]->flags_ & MPI_REQ_NON_PERSISTENT))
635 requests[i] = MPI_REQUEST_NULL;
641 if(count_dead==incount)*count=MPI_UNDEFINED;
643 return MPI_ERR_IN_STATUS;
648 int Request::testany(int count, MPI_Request requests[], int *index, int* flag, MPI_Status * status)
650 std::vector<simgrid::kernel::activity::CommImpl*> comms;
651 comms.reserve(count);
655 int ret = MPI_SUCCESS;
656 *index = MPI_UNDEFINED;
658 std::vector<int> map; /** Maps all matching comms back to their location in requests **/
659 for(i = 0; i < count; i++) {
660 if ((requests[i] != MPI_REQUEST_NULL) && requests[i]->action_ && not(requests[i]->flags_ & MPI_REQ_PREPARED)) {
661 comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(requests[i]->action_.get()));
665 if (not map.empty()) {
666 //multiplier to the sleeptime, to increase speed of execution, each failed testany will increase it
667 static int nsleeps = 1;
668 if(smpi_test_sleep > 0)
669 simgrid::s4u::this_actor::sleep_for(nsleeps * smpi_test_sleep);
671 i = simcall_comm_testany(comms.data(), comms.size()); // The i-th element in comms matches!
672 } catch (const Exception&) {
673 XBT_DEBUG("Exception in testany");
677 if (i != -1) { // -1 is not MPI_UNDEFINED but a SIMIX return code. (nothing matches)
679 if (requests[*index] != MPI_REQUEST_NULL &&
680 (requests[*index]->flags_ & MPI_REQ_GENERALIZED)
681 && !(requests[*index]->flags_ & MPI_REQ_COMPLETE)) {
684 finish_wait(&requests[*index],status);
685 if (requests[*index] != MPI_REQUEST_NULL && (requests[*index]->flags_ & MPI_REQ_GENERALIZED)){
686 MPI_Status tmp_status;
687 MPI_Status* mystatus;
688 if (status == MPI_STATUS_IGNORE) {
689 mystatus = &tmp_status;
690 Status::empty(mystatus);
694 ret=(requests[*index]->generalized_funcs)->query_fn((requests[*index]->generalized_funcs)->extra_state, mystatus);
697 if (requests[*index] != MPI_REQUEST_NULL && (requests[*index]->flags_ & MPI_REQ_NON_PERSISTENT))
698 requests[*index] = MPI_REQUEST_NULL;
699 XBT_DEBUG("Testany - returning with index %d", *index);
707 XBT_DEBUG("Testany on inactive handles, returning flag=1 but empty status");
708 //all requests are null or inactive, return true
710 *index = MPI_UNDEFINED;
711 Status::empty(status);
717 int Request::testall(int count, MPI_Request requests[], int* outflag, MPI_Status status[])
720 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
724 for(int i=0; i<count; i++){
725 if (requests[i] != MPI_REQUEST_NULL && not(requests[i]->flags_ & MPI_REQ_PREPARED)) {
726 int ret = test(&requests[i], pstat, &flag);
729 requests[i]=MPI_REQUEST_NULL;
733 if (ret != MPI_SUCCESS)
736 Status::empty(pstat);
738 if(status != MPI_STATUSES_IGNORE) {
743 return MPI_ERR_IN_STATUS;
748 void Request::probe(int source, int tag, MPI_Comm comm, MPI_Status* status){
750 //FIXME find another way to avoid busy waiting ?
751 // the issue here is that we have to wait on a nonexistent comm
753 iprobe(source, tag, comm, &flag, status);
754 XBT_DEBUG("Busy Waiting on probing : %d", flag);
758 void Request::iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
759 // to avoid deadlock, we have to sleep some time here, or the timer won't advance and we will only do iprobe simcalls
760 // especially when used as a break condition, such as while (MPI_Iprobe(...)) dostuff...
761 // nsleeps is a multiplier to the sleeptime, to increase speed of execution, each failed iprobe will increase it
762 // This can speed up the execution of certain applications by an order of magnitude, such as HPL
763 static int nsleeps = 1;
764 double speed = s4u::this_actor::get_host()->get_speed();
765 double maxrate = smpi_cfg_iprobe_cpu_usage();
766 auto request = new Request(nullptr, 0, MPI_CHAR,
767 source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : comm->group()->actor(source)->get_pid(),
768 simgrid::s4u::this_actor::get_pid(), tag, comm, MPI_REQ_PERSISTENT | MPI_REQ_RECV | MPI_REQ_PROBE);
769 if (smpi_iprobe_sleep > 0) {
770 /** Compute the number of flops we will sleep **/
771 s4u::this_actor::exec_init(/*nsleeps: See comment above */ nsleeps *
772 /*(seconds * flop/s -> total flops)*/ smpi_iprobe_sleep * speed * maxrate)
774 /* Not the entire CPU can be used when iprobing: This is important for
775 * the energy consumption caused by polling with iprobes.
776 * Note also that the number of flops that was
777 * computed above contains a maxrate factor and is hence reduced (maxrate < 1)
779 ->set_bound(maxrate*speed)
783 // behave like a receive, but don't do it
784 s4u::Mailbox* mailbox;
786 request->print_request("New iprobe");
787 // We have to test both mailboxes as we don't know if we will receive one or another
788 if (smpi_cfg_async_small_thresh() > 0) {
789 mailbox = smpi_process()->mailbox_small();
790 XBT_DEBUG("Trying to probe the perm recv mailbox");
791 request->action_ = mailbox->iprobe(0, &match_recv, static_cast<void*>(request));
794 if (request->action_ == nullptr){
795 mailbox = smpi_process()->mailbox();
796 XBT_DEBUG("trying to probe the other mailbox");
797 request->action_ = mailbox->iprobe(0, &match_recv, static_cast<void*>(request));
800 if (request->action_ != nullptr){
801 kernel::activity::CommImplPtr sync_comm = boost::static_pointer_cast<kernel::activity::CommImpl>(request->action_);
802 const Request* req = static_cast<MPI_Request>(sync_comm->src_data_);
804 if (status != MPI_STATUS_IGNORE && (req->flags_ & MPI_REQ_PREPARED) == 0) {
805 status->MPI_SOURCE = comm->group()->rank(req->src_);
806 status->MPI_TAG = req->tag_;
807 status->MPI_ERROR = MPI_SUCCESS;
808 status->count = req->real_size_;
810 nsleeps = 1;//reset the number of sleeps we will do next time
814 if (smpi_cfg_grow_injected_times())
818 xbt_assert(request == MPI_REQUEST_NULL);
821 void Request::finish_wait(MPI_Request* request, MPI_Status * status)
823 MPI_Request req = *request;
824 Status::empty(status);
826 if (req->cancelled_==1){
827 if (status!=MPI_STATUS_IGNORE)
829 if(req->detached_sender_ != nullptr)
830 unref(&(req->detached_sender_));
835 if ((req->flags_ & (MPI_REQ_PREPARED | MPI_REQ_GENERALIZED | MPI_REQ_FINISHED)) == 0) {
836 if(status != MPI_STATUS_IGNORE) {
837 int src = req->src_ == MPI_ANY_SOURCE ? req->real_src_ : req->src_;
838 status->MPI_SOURCE = req->comm_->group()->rank(src);
839 status->MPI_TAG = req->tag_ == MPI_ANY_TAG ? req->real_tag_ : req->tag_;
840 status->MPI_ERROR = req->truncated_ ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
841 // this handles the case were size in receive differs from size in send
842 status->count = req->real_size_;
844 //detached send will be finished at the other end
845 if (not(req->detached_ && ((req->flags_ & MPI_REQ_SEND) != 0))) {
846 req->print_request("Finishing");
847 MPI_Datatype datatype = req->old_type_;
849 // FIXME Handle the case of a partial shared malloc.
850 if (((req->flags_ & MPI_REQ_ACCUMULATE) != 0) ||
851 (datatype->flags() & DT_FLAG_DERIVED)) { // && (not smpi_is_shared(req->old_buf_))){
852 if (not smpi_process()->replaying() && smpi_cfg_privatization() != SmpiPrivStrategies::NONE &&
853 static_cast<char*>(req->old_buf_) >= smpi_data_exe_start &&
854 static_cast<char*>(req->old_buf_) < smpi_data_exe_start + smpi_data_exe_size) {
855 XBT_VERB("Privatization : We are unserializing to a zone in global memory Switch data segment ");
856 smpi_switch_data_segment(simgrid::s4u::Actor::self());
859 if(datatype->flags() & DT_FLAG_DERIVED){
860 // This part handles the problem of non-contiguous memory the unserialization at the reception
861 if ((req->flags_ & MPI_REQ_RECV) && datatype->size() != 0)
862 datatype->unserialize(req->buf_, req->old_buf_, req->real_size_/datatype->size() , req->op_);
865 } else if (req->flags_ & MPI_REQ_RECV) { // apply op on contiguous buffer for accumulate
866 if (datatype->size() != 0) {
867 int n = req->real_size_ / datatype->size();
868 req->op_->apply(req->buf_, req->old_buf_, &n, datatype);
877 if (TRACE_smpi_view_internals() && ((req->flags_ & MPI_REQ_RECV) != 0)) {
878 int rank = simgrid::s4u::this_actor::get_pid();
879 int src_traced = (req->src_ == MPI_ANY_SOURCE ? req->real_src_ : req->src_);
880 TRACE_smpi_recv(src_traced, rank,req->tag_);
882 if(req->detached_sender_ != nullptr){
883 //integrate pseudo-timing for buffering of small messages, do not bother to execute the simcall if 0
885 simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->orecv(req->real_size());
886 if (sleeptime > 0.0) {
887 simgrid::s4u::this_actor::sleep_for(sleeptime);
888 XBT_DEBUG("receiving size of %zu : sleep %f ", req->real_size_, sleeptime);
890 unref(&(req->detached_sender_));
892 if (req->flags_ & MPI_REQ_PERSISTENT)
893 req->action_ = nullptr;
894 req->flags_ |= MPI_REQ_FINISHED;
896 if (req->truncated_) {
897 char error_string[MPI_MAX_ERROR_STRING];
899 PMPI_Error_string(MPI_ERR_TRUNCATE, error_string, &error_size);
900 MPI_Errhandler err = (req->comm_) ? (req->comm_)->errhandler() : MPI_ERRHANDLER_NULL;
901 if (err == MPI_ERRHANDLER_NULL || err == MPI_ERRORS_RETURN)
902 XBT_WARN("recv - returned %.*s instead of MPI_SUCCESS", error_size, error_string);
903 else if (err == MPI_ERRORS_ARE_FATAL)
904 xbt_die("recv - returned %.*s instead of MPI_SUCCESS", error_size, error_string);
906 err->call((req->comm_), MPI_ERR_TRUNCATE);
907 if (err != MPI_ERRHANDLER_NULL)
908 simgrid::smpi::Errhandler::unref(err);
909 MC_assert(not MC_is_active()); /* Only fail in MC mode */
915 int Request::wait(MPI_Request * request, MPI_Status * status)
917 // assume that *request is not MPI_REQUEST_NULL (filtered in PMPI_Wait before)
918 xbt_assert(*request != MPI_REQUEST_NULL);
921 // Are we waiting on a request meant for non blocking collectives ?
922 // If so, wait for all the subrequests.
923 if ((*request)->nbc_requests_size_>0){
924 ret = waitall((*request)->nbc_requests_size_, (*request)->nbc_requests_, MPI_STATUSES_IGNORE);
925 for (int i = 0; i < (*request)->nbc_requests_size_; i++) {
926 if((*request)->buf_!=nullptr && (*request)->nbc_requests_[i]!=MPI_REQUEST_NULL){//reduce case
927 void * buf=(*request)->nbc_requests_[i]->buf_;
928 if((*request)->old_type_->flags() & DT_FLAG_DERIVED)
929 buf=(*request)->nbc_requests_[i]->old_buf_;
930 if((*request)->nbc_requests_[i]->flags_ & MPI_REQ_RECV ){
931 if((*request)->op_!=MPI_OP_NULL){
932 int count=(*request)->size_/ (*request)->old_type_->size();
933 (*request)->op_->apply(buf, (*request)->buf_, &count, (*request)->old_type_);
935 smpi_free_tmp_buffer(static_cast<unsigned char*>(buf));
938 if((*request)->nbc_requests_[i]!=MPI_REQUEST_NULL)
939 Request::unref(&((*request)->nbc_requests_[i]));
941 delete[] (*request)->nbc_requests_;
942 (*request)->nbc_requests_size_=0;
944 (*request)=MPI_REQUEST_NULL;
948 (*request)->print_request("Waiting");
949 if ((*request)->flags_ & (MPI_REQ_PREPARED | MPI_REQ_FINISHED)) {
950 Status::empty(status);
954 if ((*request)->action_ != nullptr){
956 // this is not a detached send
957 simcall_comm_wait((*request)->action_.get(), -1.0);
958 } catch (const Exception&) {
959 XBT_VERB("Request cancelled");
963 if ((*request)->flags_ & MPI_REQ_GENERALIZED) {
964 if(!((*request)->flags_ & MPI_REQ_COMPLETE)){
965 ((*request)->generalized_funcs)->mutex->lock();
966 ((*request)->generalized_funcs)->cond->wait(((*request)->generalized_funcs)->mutex);
967 ((*request)->generalized_funcs)->mutex->unlock();
969 MPI_Status tmp_status;
970 MPI_Status* mystatus;
971 if (status == MPI_STATUS_IGNORE) {
972 mystatus = &tmp_status;
973 Status::empty(mystatus);
977 ret = ((*request)->generalized_funcs)->query_fn(((*request)->generalized_funcs)->extra_state, mystatus);
980 finish_wait(request, status); // may invalidate *request
981 if (*request != MPI_REQUEST_NULL && (((*request)->flags_ & MPI_REQ_NON_PERSISTENT) != 0))
982 *request = MPI_REQUEST_NULL;
986 int Request::waitany(int count, MPI_Request requests[], MPI_Status * status)
988 int index = MPI_UNDEFINED;
991 // Wait for a request to complete
992 std::vector<simgrid::kernel::activity::CommImpl*> comms;
993 std::vector<int> map;
994 XBT_DEBUG("Wait for one of %d", count);
995 for(int i = 0; i < count; i++) {
996 if (requests[i] != MPI_REQUEST_NULL && not(requests[i]->flags_ & MPI_REQ_PREPARED) &&
997 not(requests[i]->flags_ & MPI_REQ_FINISHED)) {
998 if (requests[i]->action_ != nullptr) {
999 XBT_DEBUG("Waiting any %p ", requests[i]);
1000 comms.push_back(static_cast<simgrid::kernel::activity::CommImpl*>(requests[i]->action_.get()));
1003 // This is a finished detached request, let's return this one
1004 comms.clear(); // don't do the waitany call afterwards
1006 finish_wait(&requests[i], status); // cleanup if refcount = 0
1007 if (requests[i] != MPI_REQUEST_NULL && (requests[i]->flags_ & MPI_REQ_NON_PERSISTENT))
1008 requests[i] = MPI_REQUEST_NULL; // set to null
1013 if (not comms.empty()) {
1014 XBT_DEBUG("Enter waitany for %zu comms", comms.size());
1017 i = simcall_comm_waitany(comms.data(), comms.size(), -1);
1018 } catch (const Exception&) {
1019 XBT_INFO("request cancelled");
1023 // not MPI_UNDEFINED, as this is a simix return code
1026 //in case of an accumulate, we have to wait the end of all requests to apply the operation, ordered correctly.
1027 if ((requests[index] == MPI_REQUEST_NULL) ||
1028 (not((requests[index]->flags_ & MPI_REQ_ACCUMULATE) && (requests[index]->flags_ & MPI_REQ_RECV)))) {
1029 finish_wait(&requests[index],status);
1030 if (requests[index] != MPI_REQUEST_NULL && (requests[index]->flags_ & MPI_REQ_NON_PERSISTENT))
1031 requests[index] = MPI_REQUEST_NULL;
1037 if (index==MPI_UNDEFINED)
1038 Status::empty(status);
1043 static int sort_accumulates(const Request* a, const Request* b)
1045 return (a->tag() > b->tag());
1048 int Request::waitall(int count, MPI_Request requests[], MPI_Status status[])
1050 std::vector<MPI_Request> accumulates;
1053 MPI_Status *pstat = (status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat);
1054 int retvalue = MPI_SUCCESS;
1055 //tag invalid requests in the set
1056 if (status != MPI_STATUSES_IGNORE) {
1057 for (int c = 0; c < count; c++) {
1058 if (requests[c] == MPI_REQUEST_NULL || requests[c]->dst_ == MPI_PROC_NULL ||
1059 (requests[c]->flags_ & MPI_REQ_PREPARED)) {
1060 Status::empty(&status[c]);
1061 } else if (requests[c]->src_ == MPI_PROC_NULL) {
1062 Status::empty(&status[c]);
1063 status[c].MPI_SOURCE = MPI_PROC_NULL;
1067 for (int c = 0; c < count; c++) {
1068 if (MC_is_active() || MC_record_replay_is_active()) {
1069 wait(&requests[c],pstat);
1072 index = waitany(count, requests, pstat);
1074 if (index == MPI_UNDEFINED)
1077 if (requests[index] != MPI_REQUEST_NULL && (requests[index]->flags_ & MPI_REQ_RECV) &&
1078 (requests[index]->flags_ & MPI_REQ_ACCUMULATE))
1079 accumulates.push_back(requests[index]);
1080 if (requests[index] != MPI_REQUEST_NULL && (requests[index]->flags_ & MPI_REQ_NON_PERSISTENT))
1081 requests[index] = MPI_REQUEST_NULL;
1083 if (status != MPI_STATUSES_IGNORE) {
1084 status[index] = *pstat;
1085 if (status[index].MPI_ERROR == MPI_ERR_TRUNCATE)
1086 retvalue = MPI_ERR_IN_STATUS;
1090 if (not accumulates.empty()) {
1091 std::sort(accumulates.begin(), accumulates.end(), sort_accumulates);
1092 for (auto& req : accumulates) {
1093 finish_wait(&req, status);
1100 int Request::waitsome(int incount, MPI_Request requests[], int *indices, MPI_Status status[])
1106 MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat;
1107 index = waitany(incount, requests, pstat);
1108 if(index==MPI_UNDEFINED) return MPI_UNDEFINED;
1109 if(status != MPI_STATUSES_IGNORE) {
1110 status[count] = *pstat;
1112 indices[count] = index;
1114 for (int i = 0; i < incount; i++) {
1115 if (i!=index && requests[i] != MPI_REQUEST_NULL
1116 && not(requests[i]->flags_ & MPI_REQ_FINISHED)) {
1117 test(&requests[i], pstat,&flag);
1120 if(status != MPI_STATUSES_IGNORE) {
1121 status[count] = *pstat;
1123 if (requests[i] != MPI_REQUEST_NULL && (requests[i]->flags_ & MPI_REQ_NON_PERSISTENT))
1124 requests[i]=MPI_REQUEST_NULL;
1132 MPI_Request Request::f2c(int id)
1134 if(id==MPI_FORTRAN_REQUEST_NULL)
1135 return MPI_REQUEST_NULL;
1136 return static_cast<MPI_Request>(F2C::lookup()->at(id));
1139 void Request::free_f(int id)
1141 if (id != MPI_FORTRAN_REQUEST_NULL) {
1142 F2C::lookup()->erase(id);
1146 int Request::get_status(const Request* req, int* flag, MPI_Status* status)
1150 if(req != MPI_REQUEST_NULL && req->action_ != nullptr) {
1151 req->iprobe(req->src_, req->tag_, req->comm_, flag, status);
1155 if (req != MPI_REQUEST_NULL &&
1156 (req->flags_ & MPI_REQ_GENERALIZED)
1157 && !(req->flags_ & MPI_REQ_COMPLETE)) {
1163 if(req != MPI_REQUEST_NULL &&
1164 status != MPI_STATUS_IGNORE) {
1165 int src = req->src_ == MPI_ANY_SOURCE ? req->real_src_ : req->src_;
1166 status->MPI_SOURCE = req->comm_->group()->rank(src);
1167 status->MPI_TAG = req->tag_ == MPI_ANY_TAG ? req->real_tag_ : req->tag_;
1168 status->MPI_ERROR = req->truncated_ ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
1169 status->count = req->real_size_;
1174 int Request::grequest_start(MPI_Grequest_query_function* query_fn, MPI_Grequest_free_function* free_fn,
1175 MPI_Grequest_cancel_function* cancel_fn, void* extra_state, MPI_Request* request)
1177 *request = new Request();
1178 (*request)->flags_ |= MPI_REQ_GENERALIZED;
1179 (*request)->flags_ |= MPI_REQ_PERSISTENT;
1180 (*request)->refcount_ = 1;
1181 ((*request)->generalized_funcs) = std::make_unique<smpi_mpi_generalized_request_funcs_t>();
1182 ((*request)->generalized_funcs)->query_fn=query_fn;
1183 ((*request)->generalized_funcs)->free_fn=free_fn;
1184 ((*request)->generalized_funcs)->cancel_fn=cancel_fn;
1185 ((*request)->generalized_funcs)->extra_state=extra_state;
1186 ((*request)->generalized_funcs)->cond = simgrid::s4u::ConditionVariable::create();
1187 ((*request)->generalized_funcs)->mutex = simgrid::s4u::Mutex::create();
1191 int Request::grequest_complete(MPI_Request request)
1193 if ((!(request->flags_ & MPI_REQ_GENERALIZED)) || request->generalized_funcs->mutex == nullptr)
1194 return MPI_ERR_REQUEST;
1195 request->generalized_funcs->mutex->lock();
1196 request->flags_ |= MPI_REQ_COMPLETE; // in case wait would be called after complete
1197 request->generalized_funcs->cond->notify_one();
1198 request->generalized_funcs->mutex->unlock();
1202 void Request::set_nbc_requests(MPI_Request* reqs, int size){
1203 nbc_requests_size_ = size;
1205 nbc_requests_ = reqs;
1208 nbc_requests_ = nullptr;
1212 int Request::get_nbc_requests_size() const
1214 return nbc_requests_size_;
1217 MPI_Request* Request::get_nbc_requests() const
1219 return nbc_requests_;