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 <simgrid/Exception.hpp>
7 #include <simgrid/kernel/routing/NetPoint.hpp>
8 #include <simgrid/modelchecker.h>
9 #include <simgrid/s4u/Host.hpp>
11 #include "src/kernel/activity/CommImpl.hpp"
12 #include "src/kernel/activity/MailboxImpl.hpp"
13 #include "src/kernel/context/Context.hpp"
14 #include "src/mc/mc_replay.hpp"
15 #include "src/surf/cpu_interface.hpp"
16 #include "src/surf/network_interface.hpp"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization");
20 XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size,
21 double rate, unsigned char* src_buff, size_t src_buff_size,
22 bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
23 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
24 void* data, double timeout)
26 simgrid::kernel::activity::ActivityImplPtr comm = simcall_HANDLER_comm_isend(
27 simcall, src, mbox, task_size, rate, src_buff, src_buff_size, match_fun, nullptr, copy_data_fun, data, false);
28 simcall->mc_value_ = 0;
29 comm->wait_for(simcall->issuer_, timeout);
32 XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr simcall_HANDLER_comm_isend(
33 smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate,
34 unsigned char* src_buff, size_t src_buff_size,
35 bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
36 void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send
37 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), // used to copy data if not default one
38 void* data, bool detached)
40 XBT_DEBUG("send from mailbox %p", mbox);
42 /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
43 simgrid::kernel::activity::CommImplPtr this_comm(
44 new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::SEND));
46 /* Look for communication synchro matching our needs. We also provide a description of
47 * ourself so that the other side also gets a chance of choosing if it wants to match with us.
49 * If it is not found then push our communication into the rendez-vous point */
50 simgrid::kernel::activity::CommImplPtr other_comm =
51 mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::RECEIVE, match_fun, data, this_comm,
52 /*done*/ false, /*remove_matching*/ true);
55 other_comm = std::move(this_comm);
57 if (mbox->is_permanent()) {
58 // this mailbox is for small messages, which have to be sent right now
59 other_comm->state_ = simgrid::kernel::activity::State::READY;
60 other_comm->dst_actor_ = mbox->get_permanent_receiver().get();
61 mbox->push_done(other_comm);
62 XBT_DEBUG("pushing a message into the permanent receive list %p, comm %p", mbox, other_comm.get());
65 mbox->push(other_comm);
68 XBT_DEBUG("Receive already pushed");
70 other_comm->state_ = simgrid::kernel::activity::State::READY;
75 other_comm->clean_fun = clean_fun;
77 other_comm->clean_fun = nullptr;
78 src_proc->activities_.emplace_back(other_comm);
81 /* Setup the communication synchro */
82 other_comm->src_actor_ = src_proc;
83 other_comm->src_data_ = data;
84 (*other_comm).set_src_buff(src_buff, src_buff_size).set_size(task_size).set_rate(rate);
86 other_comm->match_fun = match_fun;
87 other_comm->copy_data_fun = copy_data_fun;
89 if (MC_is_active() || MC_record_replay_is_active())
90 other_comm->state_ = simgrid::kernel::activity::State::RUNNING;
94 return (detached ? nullptr : other_comm);
97 XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox,
98 unsigned char* dst_buff, size_t* dst_buff_size,
99 bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
100 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
101 void* data, double timeout, double rate)
103 simgrid::kernel::activity::ActivityImplPtr comm = simcall_HANDLER_comm_irecv(
104 simcall, receiver, mbox, dst_buff, dst_buff_size, match_fun, copy_data_fun, data, rate);
105 simcall->mc_value_ = 0;
106 comm->wait_for(simcall->issuer_, timeout);
109 XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr
110 simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff,
111 size_t* dst_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
112 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
115 simgrid::kernel::activity::CommImplPtr this_synchro(
116 new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::RECEIVE));
117 XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get());
119 simgrid::kernel::activity::CommImplPtr other_comm;
120 // communication already done, get it inside the list of completed comms
121 if (mbox->is_permanent() && mbox->has_some_done_comm()) {
122 XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
123 // find a match in the list of already received comms
124 other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
125 this_synchro, /*done*/ true,
126 /*remove_matching*/ true);
127 // if not found, assume the receiver came first, register it to the mailbox in the classical way
128 if (not other_comm) {
129 XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request "
131 other_comm = std::move(this_synchro);
132 mbox->push(other_comm);
134 if (other_comm->surf_action_ && other_comm->get_remaining() < 1e-12) {
135 XBT_DEBUG("comm %p has been already sent, and is finished, destroy it", other_comm.get());
136 other_comm->state_ = simgrid::kernel::activity::State::DONE;
137 other_comm->set_mailbox(nullptr);
141 /* Prepare a comm describing us, so that it gets passed to the user-provided filter of other side */
143 /* Look for communication activity matching our needs. We also provide a description of
144 * ourself so that the other side also gets a chance of choosing if it wants to match with us.
146 * If it is not found then push our communication into the rendez-vous point */
147 other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
148 this_synchro, /*done*/ false,
149 /*remove_matching*/ true);
151 if (other_comm == nullptr) {
152 XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->size());
153 other_comm = std::move(this_synchro);
154 mbox->push(other_comm);
156 XBT_DEBUG("Match my %p with the existing %p", this_synchro.get(), other_comm.get());
158 other_comm->state_ = simgrid::kernel::activity::State::READY;
160 receiver->activities_.emplace_back(other_comm);
163 /* Setup communication synchro */
164 other_comm->dst_actor_ = receiver;
165 other_comm->dst_data_ = data;
166 other_comm->set_dst_buff(dst_buff, dst_buff_size);
168 if (rate > -1.0 && (other_comm->get_rate() < 0.0 || rate < other_comm->get_rate()))
169 other_comm->set_rate(rate);
171 other_comm->match_fun = match_fun;
172 other_comm->copy_data_fun = copy_data_fun;
174 if (MC_is_active() || MC_record_replay_is_active()) {
175 other_comm->state_ = simgrid::kernel::activity::State::RUNNING;
182 void simcall_HANDLER_comm_wait(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm, double timeout)
184 comm->wait_for(simcall->issuer_, timeout);
187 bool simcall_HANDLER_comm_test(smx_simcall_t, simgrid::kernel::activity::CommImpl* comm)
192 ssize_t simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count)
194 std::vector<simgrid::kernel::activity::CommImpl*> comms_vec(comms, comms + count);
195 return simgrid::kernel::activity::CommImpl::test_any(simcall->issuer_, comms_vec);
198 void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count,
201 std::vector<simgrid::kernel::activity::CommImpl*> comms_vec(comms, comms + count);
202 simgrid::kernel::activity::CommImpl::wait_any_for(simcall->issuer_, comms_vec, timeout);
205 /******************************************************************************/
206 /* SIMIX_comm_copy_data callbacks */
207 /******************************************************************************/
208 // XBT_ATTRIB_DEPRECATED_v333
209 void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*, size_t))
211 simgrid::kernel::activity::CommImpl::set_copy_data_callback(callback);
214 void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
216 XBT_DEBUG("Copy the data over");
217 memcpy(comm->dst_buff_, buff, buff_size);
218 if (comm->detached()) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the
219 // original buffer available to the application ASAP
221 comm->src_buff_ = nullptr;
225 void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
227 xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
228 *(void**)(comm->dst_buff_) = buff;
235 void (*CommImpl::copy_data_callback_)(CommImpl*, void*, size_t) = &SIMIX_comm_copy_pointer_callback;
237 void CommImpl::set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t))
239 copy_data_callback_ = callback;
242 CommImpl& CommImpl::set_size(double size)
248 CommImpl& CommImpl::set_rate(double rate)
253 CommImpl& CommImpl::set_mailbox(MailboxImpl* mbox)
259 CommImpl& CommImpl::set_src_buff(unsigned char* buff, size_t size)
262 src_buff_size_ = size;
266 CommImpl& CommImpl::set_dst_buff(unsigned char* buff, size_t* size)
269 dst_buff_size_ = size;
273 CommImpl& CommImpl::detach()
279 CommImpl::CommImpl(s4u::Host* from, s4u::Host* to, double bytes) : size_(bytes), detached_(true), from_(from), to_(to)
281 state_ = State::READY;
284 CommImpl::~CommImpl()
286 XBT_DEBUG("Really free communication %p in state %s (detached = %d)", this, get_state_str(), detached_);
290 if (detached_ && state_ != State::DONE) {
291 /* the communication has failed and was detached:
292 * we have to free the buffer */
294 clean_fun(src_buff_);
301 /** @brief Starts the simulation of a communication synchro. */
302 CommImpl* CommImpl::start()
304 /* If both the sender and the receiver are already there, start the communication */
305 if (state_ == State::READY) {
306 from_ = from_ != nullptr ? from_ : src_actor_->get_host();
307 to_ = to_ != nullptr ? to_ : dst_actor_->get_host();
309 /* Getting the network_model from the origin host
310 * Valid while we have a single network model, otherwise we would need to change this function to first get the
311 * routes and later create the respective surf actions */
312 auto net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model();
314 surf_action_ = net_model->communicate(from_, to_, size_, rate_);
315 surf_action_->set_activity(this);
316 surf_action_->set_category(get_tracing_category());
317 state_ = State::RUNNING;
319 XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p; state: %s)", this, from_->get_cname(),
320 to_->get_cname(), surf_action_, get_state_str());
322 /* If a link is failed, detect it immediately */
323 if (surf_action_->get_state() == resource::Action::State::FAILED) {
324 XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", from_->get_cname(),
326 state_ = State::LINK_FAILURE;
329 } else if ((src_actor_ != nullptr && src_actor_->is_suspended()) ||
330 (dst_actor_ != nullptr && dst_actor_->is_suspended())) {
331 /* If any of the actor is suspended, create the synchro but stop its execution,
332 it will be restarted when the sender actor resume */
333 if (src_actor_->is_suspended())
334 XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the "
336 src_actor_->get_cname(), src_actor_->get_host()->get_cname());
338 XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the "
340 dst_actor_->get_cname(), dst_actor_->get_host()->get_cname());
342 surf_action_->suspend();
349 /** @brief Copy the communication data from the sender's buffer to the receiver's one */
350 void CommImpl::copy_data()
352 size_t buff_size = src_buff_size_;
353 /* If there is no data to copy then return */
354 if (not src_buff_ || not dst_buff_ || copied_)
357 XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this,
358 src_actor_ ? src_actor_->get_host()->get_cname() : "a finished actor", src_buff_,
359 dst_actor_ ? dst_actor_->get_host()->get_cname() : "a finished actor", dst_buff_, buff_size);
361 /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
362 if (dst_buff_size_) {
363 buff_size = std::min(buff_size, *dst_buff_size_);
365 /* Update the receiver's buffer size to the copied amount */
366 *dst_buff_size_ = buff_size;
371 copy_data_fun(this, src_buff_, buff_size);
373 copy_data_callback_(this, src_buff_, buff_size);
376 /* Set the copied flag so we copy data only once */
377 /* (this function might be called from both communication ends) */
381 bool CommImpl::test()
383 if ((MC_is_active() || MC_record_replay_is_active()) && src_actor_ && dst_actor_)
384 state_ = State::DONE;
385 return ActivityImpl::test();
388 void CommImpl::wait_for(actor::ActorImpl* issuer, double timeout)
390 XBT_DEBUG("CommImpl::wait_for(%g), %p, state %s", timeout, this, to_c_str(state_));
392 /* Associate this simcall to the wait synchro */
393 register_simcall(&issuer->simcall_);
395 if (MC_is_active() || MC_record_replay_is_active()) {
396 int idx = issuer->simcall_.mc_value_;
398 state_ = State::DONE;
400 /* If we reached this point, the wait simcall must have a timeout */
401 /* Otherwise it shouldn't be enabled and executed by the MC */
404 state_ = (issuer == src_actor_ ? State::SRC_TIMEOUT : State::DST_TIMEOUT);
410 /* If the synchro has already finish perform the error handling, */
411 /* otherwise set up a waiting timeout on the right side */
412 if (state_ != State::WAITING && state_ != State::RUNNING) {
414 } else { /* we need a sleep action (even when there is no timeout) to be notified of host failures */
415 resource::Action* sleep = issuer->get_host()->get_cpu()->sleep(timeout);
416 sleep->set_activity(this);
418 if (issuer == src_actor_)
419 src_timeout_ = sleep;
421 dst_timeout_ = sleep;
425 ssize_t CommImpl::test_any(const actor::ActorImpl* issuer, const std::vector<CommImpl*>& comms)
427 if (MC_is_active() || MC_record_replay_is_active()) {
428 int idx = issuer->simcall_.mc_value_;
429 xbt_assert(idx == -1 || comms[idx]->test());
433 for (std::size_t i = 0; i < comms.size(); ++i) {
434 if (comms[i]->test())
440 void CommImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<CommImpl*>& comms, double timeout)
442 if (MC_is_active() || MC_record_replay_is_active()) {
443 xbt_assert(timeout <= 0.0, "Timeout not implemented for waitany in the model-checker");
444 int idx = issuer->simcall_.mc_value_;
445 auto* comm = comms[idx];
446 comm->simcalls_.push_back(&issuer->simcall_);
447 simcall_comm_waitany__set__result(&issuer->simcall_, idx);
448 comm->state_ = State::DONE;
454 issuer->simcall_.timeout_cb_ = nullptr;
456 issuer->simcall_.timeout_cb_ = timer::Timer::set(s4u::Engine::get_clock() + timeout, [issuer, comms]() {
457 // FIXME: Vector `comms' is copied here. Use a reference once its lifetime is extended (i.e. when the simcall is
459 issuer->simcall_.timeout_cb_ = nullptr;
460 for (auto* comm : comms)
461 comm->unregister_simcall(&issuer->simcall_);
462 simcall_comm_waitany__set__result(&issuer->simcall_, -1);
463 issuer->simcall_answer();
467 for (auto* comm : comms) {
468 /* associate this simcall to the the synchro */
469 comm->simcalls_.push_back(&issuer->simcall_);
471 /* see if the synchro is already finished */
472 if (comm->state_ != State::WAITING && comm->state_ != State::RUNNING) {
479 void CommImpl::suspend()
481 /* FIXME: shall we suspend also the timeout synchro? */
483 surf_action_->suspend();
484 /* if not created yet, the action will be suspended on creation, in CommImpl::start() */
487 void CommImpl::resume()
489 /*FIXME: check what happen with the timeouts */
491 surf_action_->resume();
492 /* in the other case, the synchro were not really suspended yet, see CommImpl::suspend() and CommImpl::start() */
495 void CommImpl::cancel()
497 /* if the synchro is a waiting state means that it is still in a mbox so remove from it and delete it */
498 if (state_ == State::WAITING) {
501 state_ = State::CANCELED;
503 } else if (not MC_is_active() /* when running the MC there are no surf actions */
504 && not MC_record_replay_is_active() && (state_ == State::READY || state_ == State::RUNNING)) {
505 surf_action_->cancel();
509 /** @brief This is part of the cleanup process, probably an internal command */
510 void CommImpl::cleanup_surf()
515 src_timeout_->unref();
516 src_timeout_ = nullptr;
520 dst_timeout_->unref();
521 dst_timeout_ = nullptr;
525 void CommImpl::post()
527 /* Update synchro state */
528 if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FINISHED)
529 state_ = State::SRC_TIMEOUT;
530 else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FINISHED)
531 state_ = State::DST_TIMEOUT;
532 else if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FAILED)
533 state_ = State::SRC_HOST_FAILURE;
534 else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FAILED)
535 state_ = State::DST_HOST_FAILURE;
536 else if (surf_action_ && surf_action_->get_state() == resource::Action::State::FAILED) {
537 state_ = State::LINK_FAILURE;
539 state_ = State::DONE;
541 XBT_DEBUG("CommImpl::post(): comm %p, state %s, src_proc %p, dst_proc %p, detached: %d", this, get_state_str(),
542 src_actor_.get(), dst_actor_.get(), detached_);
544 /* destroy the surf actions associated with the Simix communication */
547 /* Answer all simcalls associated with the synchro */
551 void CommImpl::finish()
553 XBT_DEBUG("CommImpl::finish() in state %s", to_c_str(state_));
555 /* If the synchro is still in a rendez-vous point then remove from it */
559 if (state_ == State::DONE)
562 while (not simcalls_.empty()) {
563 smx_simcall_t simcall = simcalls_.front();
564 simcalls_.pop_front();
566 /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
567 * list. Afterwards, get the position of the actual synchro in the waitany list and return it as the result of the
570 if (simcall->call_ == simix::Simcall::NONE) // FIXME: maybe a better way to handle this case
571 continue; // if actor handling comm is killed
572 if (simcall->call_ == simix::Simcall::COMM_WAITANY) {
573 CommImpl** comms = simcall_comm_waitany__get__comms(simcall);
574 size_t count = simcall_comm_waitany__get__count(simcall);
575 for (size_t i = 0; i < count; i++)
576 comms[i]->unregister_simcall(simcall);
577 if (simcall->timeout_cb_) {
578 simcall->timeout_cb_->remove();
579 simcall->timeout_cb_ = nullptr;
581 if (not MC_is_active() && not MC_record_replay_is_active()) {
582 CommImpl** element = std::find(comms, comms + count, this);
583 ssize_t rank = (element != comms + count) ? element - comms : -1;
584 simcall_comm_waitany__set__result(simcall, rank);
588 /* Check out for errors */
590 if (not simcall->issuer_->get_host()->is_on()) {
591 simcall->issuer_->context_->set_wannadie();
595 simcall->issuer_->exception_ =
596 std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
598 case State::SRC_TIMEOUT:
599 simcall->issuer_->exception_ = std::make_exception_ptr(
600 TimeoutException(XBT_THROW_POINT, "Communication timeouted because of the sender"));
603 case State::DST_TIMEOUT:
604 simcall->issuer_->exception_ = std::make_exception_ptr(
605 TimeoutException(XBT_THROW_POINT, "Communication timeouted because of the receiver"));
608 case State::SRC_HOST_FAILURE:
609 if (simcall->issuer_ == src_actor_)
610 simcall->issuer_->context_->set_wannadie();
612 state_ = kernel::activity::State::FAILED;
613 simcall->issuer_->exception_ =
614 std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
618 case State::DST_HOST_FAILURE:
619 if (simcall->issuer_ == dst_actor_)
620 simcall->issuer_->context_->set_wannadie();
622 state_ = kernel::activity::State::FAILED;
623 simcall->issuer_->exception_ =
624 std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
628 case State::LINK_FAILURE:
629 XBT_DEBUG("Link failure in synchro %p between '%s' and '%s': posting an exception to the issuer: %s (%p) "
631 this, src_actor_ ? src_actor_->get_host()->get_cname() : nullptr,
632 dst_actor_ ? dst_actor_->get_host()->get_cname() : nullptr, simcall->issuer_->get_cname(),
633 simcall->issuer_, detached_);
634 if (src_actor_ == simcall->issuer_) {
635 XBT_DEBUG("I'm source");
636 } else if (dst_actor_ == simcall->issuer_) {
637 XBT_DEBUG("I'm dest");
639 XBT_DEBUG("I'm neither source nor dest");
641 state_ = kernel::activity::State::FAILED;
642 simcall->issuer_->throw_exception(
643 std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Link failure")));
646 case State::CANCELED:
647 if (simcall->issuer_ == dst_actor_)
648 simcall->issuer_->exception_ =
649 std::make_exception_ptr(CancelException(XBT_THROW_POINT, "Communication canceled by the sender"));
651 simcall->issuer_->exception_ =
652 std::make_exception_ptr(CancelException(XBT_THROW_POINT, "Communication canceled by the receiver"));
656 xbt_assert(state_ == State::DONE, "Internal error in CommImpl::finish(): unexpected synchro state %s",
659 simcall->issuer_->simcall_answer();
661 /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
662 if (simcall->issuer_->exception_ &&
663 (simcall->call_ == simix::Simcall::COMM_WAITANY || simcall->call_ == simix::Simcall::COMM_TESTANY)) {
664 // First retrieve the rank of our failing synchro
667 if (simcall->call_ == simix::Simcall::COMM_WAITANY) {
668 comms = simcall_comm_waitany__get__comms(simcall);
669 count = simcall_comm_waitany__get__count(simcall);
671 /* simcall->call_ == simix::Simcall::COMM_TESTANY */
672 comms = simcall_comm_testany__get__comms(simcall);
673 count = simcall_comm_testany__get__count(simcall);
675 CommImpl** element = std::find(comms, comms + count, this);
676 ssize_t rank = (element != comms + count) ? element - comms : -1;
677 // In order to modify the exception we have to rethrow it:
679 std::rethrow_exception(simcall->issuer_->exception_);
680 } catch (Exception& e) {
685 simcall->issuer_->waiting_synchro_ = nullptr;
686 simcall->issuer_->activities_.remove(this);
688 if (simcall->issuer_ != dst_actor_ && dst_actor_ != nullptr)
689 dst_actor_->activities_.remove(this);
690 if (simcall->issuer_ != src_actor_ && src_actor_ != nullptr)
691 src_actor_->activities_.remove(this);
696 } // namespace activity
697 } // namespace kernel
698 } // namespace simgrid