1 /* Copyright (c) 2007-2019. 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 "src/kernel/activity/CommImpl.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/kernel/resource/Action.hpp"
9 #include "simgrid/modelchecker.h"
10 #include "simgrid/s4u/Host.hpp"
11 #include "src/kernel/activity/MailboxImpl.hpp"
12 #include "src/kernel/context/Context.hpp"
13 #include "src/mc/mc_replay.hpp"
14 #include "src/surf/cpu_interface.hpp"
15 #include "src/surf/network_interface.hpp"
16 #include "src/surf/surf_interface.hpp"
18 #include <boost/range/algorithm.hpp>
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization");
21 XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size,
22 double rate, unsigned char* src_buff, size_t src_buff_size,
23 int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
24 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
25 void* data, double timeout)
27 smx_activity_t comm = simcall_HANDLER_comm_isend(simcall, src, mbox, task_size, rate, src_buff, src_buff_size,
28 match_fun, nullptr, copy_data_fun, data, 0);
29 SIMCALL_SET_MC_VALUE(simcall, 0);
30 simcall_HANDLER_comm_wait(simcall, static_cast<simgrid::kernel::activity::CommImpl*>(comm.get()), timeout);
33 XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend(
34 smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate,
35 unsigned char* src_buff, size_t src_buff_size, int (*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 simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl());
45 this_comm->set_type(simgrid::kernel::activity::CommImpl::Type::SEND);
47 /* Look for communication synchro matching our needs. We also provide a description of
48 * ourself so that the other side also gets a chance of choosing if it wants to match with us.
50 * If it is not found then push our communication into the rendez-vous point */
51 simgrid::kernel::activity::CommImplPtr other_comm =
52 mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::RECEIVE, match_fun, data, this_comm,
53 /*done*/ false, /*remove_matching*/ true);
56 other_comm = std::move(this_comm);
58 if (mbox->permanent_receiver_ != nullptr) {
59 // this mailbox is for small messages, which have to be sent right now
60 other_comm->state_ = SIMIX_READY;
61 other_comm->dst_actor_ = mbox->permanent_receiver_.get();
62 mbox->done_comm_queue_.push_back(other_comm);
63 XBT_DEBUG("pushing a message into the permanent receive list %p, comm %p", mbox, other_comm.get());
66 mbox->push(other_comm);
69 XBT_DEBUG("Receive already pushed");
71 other_comm->state_ = SIMIX_READY;
72 other_comm->set_type(simgrid::kernel::activity::CommImpl::Type::READY);
77 other_comm->clean_fun = clean_fun;
79 other_comm->clean_fun = nullptr;
80 src_proc->comms.push_back(other_comm);
83 /* Setup the communication synchro */
84 other_comm->src_actor_ = src_proc;
85 other_comm->src_data_ = data;
86 (*other_comm).set_src_buff(src_buff, src_buff_size).set_size(task_size).set_rate(rate);
88 other_comm->match_fun = match_fun;
89 other_comm->copy_data_fun = copy_data_fun;
91 if (MC_is_active() || MC_record_replay_is_active())
92 other_comm->state_ = SIMIX_RUNNING;
96 return (detached ? nullptr : other_comm);
99 XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox,
100 unsigned char* dst_buff, size_t* dst_buff_size,
101 int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
102 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
103 void* data, double timeout, double rate)
105 smx_activity_t comm = simcall_HANDLER_comm_irecv(simcall, receiver, mbox, dst_buff, dst_buff_size, match_fun,
106 copy_data_fun, data, rate);
107 SIMCALL_SET_MC_VALUE(simcall, 0);
108 simcall_HANDLER_comm_wait(simcall, static_cast<simgrid::kernel::activity::CommImpl*>(comm.get()), timeout);
111 XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(
112 smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size,
113 simix_match_func_t match_fun, void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
114 void* data, double rate)
116 simgrid::kernel::activity::CommImplPtr this_synchro =
117 simgrid::kernel::activity::CommImplPtr(new simgrid::kernel::activity::CommImpl());
118 this_synchro->set_type(simgrid::kernel::activity::CommImpl::Type::RECEIVE);
119 XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get());
121 simgrid::kernel::activity::CommImplPtr other_comm;
122 // communication already done, get it inside the list of completed comms
123 if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) {
125 XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
126 // find a match in the list of already received comms
127 other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
128 this_synchro, /*done*/ true,
129 /*remove_matching*/ true);
130 // if not found, assume the receiver came first, register it to the mailbox in the classical way
131 if (not other_comm) {
132 XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request "
134 other_comm = std::move(this_synchro);
135 mbox->push(other_comm);
137 if (other_comm->surf_action_ && other_comm->get_remaining() < 1e-12) {
138 XBT_DEBUG("comm %p has been already sent, and is finished, destroy it", other_comm.get());
139 other_comm->state_ = SIMIX_DONE;
140 other_comm->set_type(simgrid::kernel::activity::CommImpl::Type::DONE).set_mailbox(nullptr);
144 /* Prepare a comm describing us, so that it gets passed to the user-provided filter of other side */
146 /* Look for communication activity matching our needs. We also provide a description of
147 * ourself so that the other side also gets a chance of choosing if it wants to match with us.
149 * If it is not found then push our communication into the rendez-vous point */
150 other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
151 this_synchro, /*done*/ false,
152 /*remove_matching*/ true);
154 if (other_comm == nullptr) {
155 XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue_.size());
156 other_comm = std::move(this_synchro);
157 mbox->push(other_comm);
159 XBT_DEBUG("Match my %p with the existing %p", this_synchro.get(), other_comm.get());
161 other_comm->state_ = SIMIX_READY;
162 other_comm->set_type(simgrid::kernel::activity::CommImpl::Type::READY);
164 receiver->comms.push_back(other_comm);
167 /* Setup communication synchro */
168 other_comm->dst_actor_ = receiver;
169 other_comm->dst_data_ = data;
170 other_comm->set_dst_buff(dst_buff, dst_buff_size);
172 if (rate > -1.0 && (other_comm->get_rate() < 0.0 || rate < other_comm->get_rate()))
173 other_comm->set_rate(rate);
175 other_comm->match_fun = match_fun;
176 other_comm->copy_data_fun = copy_data_fun;
178 if (MC_is_active() || MC_record_replay_is_active()) {
179 other_comm->state_ = SIMIX_RUNNING;
186 void simcall_HANDLER_comm_wait(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm, double timeout)
188 /* Associate this simcall to the wait synchro */
189 XBT_DEBUG("simcall_HANDLER_comm_wait, %p", comm);
191 comm->register_simcall(simcall);
193 if (MC_is_active() || MC_record_replay_is_active()) {
194 int idx = SIMCALL_GET_MC_VALUE(simcall);
196 comm->state_ = SIMIX_DONE;
198 /* If we reached this point, the wait simcall must have a timeout */
199 /* Otherwise it shouldn't be enabled and executed by the MC */
203 if (comm->src_actor_ == simcall->issuer)
204 comm->state_ = SIMIX_SRC_TIMEOUT;
206 comm->state_ = SIMIX_DST_TIMEOUT;
213 /* If the synchro has already finish perform the error handling, */
214 /* otherwise set up a waiting timeout on the right side */
215 if (comm->state_ != SIMIX_WAITING && comm->state_ != SIMIX_RUNNING) {
217 } else { /* we need a sleep action (even when there is no timeout) to be notified of host failures */
218 simgrid::kernel::resource::Action* sleep = simcall->issuer->get_host()->pimpl_cpu->sleep(timeout);
219 sleep->set_activity(comm);
221 if (simcall->issuer == comm->src_actor_)
222 comm->src_timeout_ = sleep;
224 comm->dst_timeout_ = sleep;
228 void simcall_HANDLER_comm_test(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm)
232 if (MC_is_active() || MC_record_replay_is_active()) {
233 res = comm->src_actor_ && comm->dst_actor_;
235 comm->state_ = SIMIX_DONE;
237 res = comm->state_ != SIMIX_WAITING && comm->state_ != SIMIX_RUNNING;
240 simcall_comm_test__set__result(simcall, res);
241 if (simcall_comm_test__get__result(simcall)) {
242 comm->simcalls_.push_back(simcall);
245 SIMIX_simcall_answer(simcall);
249 void simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count)
251 // The default result is -1 -- this means, "nothing is ready".
252 // It can be changed below, but only if something matches.
253 simcall_comm_testany__set__result(simcall, -1);
255 if (MC_is_active() || MC_record_replay_is_active()) {
256 int idx = SIMCALL_GET_MC_VALUE(simcall);
258 SIMIX_simcall_answer(simcall);
260 simgrid::kernel::activity::CommImpl* comm = comms[idx];
261 simcall_comm_testany__set__result(simcall, idx);
262 comm->simcalls_.push_back(simcall);
263 comm->state_ = SIMIX_DONE;
269 for (std::size_t i = 0; i != count; ++i) {
270 simgrid::kernel::activity::CommImpl* comm = comms[i];
271 if (comm->state_ != SIMIX_WAITING && comm->state_ != SIMIX_RUNNING) {
272 simcall_comm_testany__set__result(simcall, i);
273 comm->simcalls_.push_back(simcall);
278 SIMIX_simcall_answer(simcall);
281 static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall)
283 simgrid::kernel::activity::CommImpl** comms = simcall_comm_waitany__get__comms(simcall);
284 size_t count = simcall_comm_waitany__get__count(simcall);
286 for (size_t i = 0; i < count; i++) {
287 // Remove the first occurence of simcall:
288 auto* comm = comms[i];
289 auto j = boost::range::find(comm->simcalls_, simcall);
290 if (j != comm->simcalls_.end())
291 comm->simcalls_.erase(j);
294 void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count,
297 if (MC_is_active() || MC_record_replay_is_active()) {
299 xbt_die("Timeout not implemented for waitany in the model-checker");
300 int idx = SIMCALL_GET_MC_VALUE(simcall);
301 auto* comm = comms[idx];
302 comm->simcalls_.push_back(simcall);
303 simcall_comm_waitany__set__result(simcall, idx);
304 comm->state_ = SIMIX_DONE;
310 simcall->timer = NULL;
312 simcall->timer = simgrid::simix::Timer::set(SIMIX_get_clock() + timeout, [simcall]() {
313 SIMIX_waitany_remove_simcall_from_actions(simcall);
314 simcall_comm_waitany__set__result(simcall, -1);
315 SIMIX_simcall_answer(simcall);
319 for (size_t i = 0; i < count; i++) {
320 /* associate this simcall to the the synchro */
321 auto* comm = comms[i];
322 comm->simcalls_.push_back(simcall);
324 /* see if the synchro is already finished */
325 if (comm->state_ != SIMIX_WAITING && comm->state_ != SIMIX_RUNNING) {
332 /******************************************************************************/
333 /* SIMIX_comm_copy_data callbacks */
334 /******************************************************************************/
335 static void (*SIMIX_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*, void*,
336 size_t) = &SIMIX_comm_copy_pointer_callback;
338 void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
340 XBT_DEBUG("Copy the data over");
341 memcpy(comm->dst_buff_, buff, buff_size);
342 if (comm->detached()) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the
343 // original buffer available to the application ASAP
345 comm->src_buff_ = nullptr;
349 void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*, size_t))
351 SIMIX_comm_copy_data_callback = callback;
354 void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
356 xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
357 *(void**)(comm->dst_buff_) = buff;
364 CommImpl& CommImpl::set_type(CommImpl::Type type)
370 CommImpl& CommImpl::set_size(double size)
376 CommImpl& CommImpl::set_rate(double rate)
381 CommImpl& CommImpl::set_mailbox(MailboxImpl* mbox)
387 CommImpl& CommImpl::set_src_buff(unsigned char* buff, size_t size)
390 src_buff_size_ = size;
394 CommImpl& CommImpl::set_dst_buff(unsigned char* buff, size_t* size)
397 dst_buff_size_ = size;
401 CommImpl& CommImpl::detach()
407 CommImpl::~CommImpl()
409 XBT_DEBUG("Really free communication %p in state %d (detached = %d)", this, static_cast<int>(state_), detached_);
413 if (detached_ && state_ != SIMIX_DONE) {
414 /* the communication has failed and was detached:
415 * we have to free the buffer */
417 clean_fun(src_buff_);
424 /** @brief Starts the simulation of a communication synchro. */
425 CommImpl* CommImpl::start()
427 /* If both the sender and the receiver are already there, start the communication */
428 if (state_ == SIMIX_READY) {
430 s4u::Host* sender = src_actor_->get_host();
431 s4u::Host* receiver = dst_actor_->get_host();
433 surf_action_ = surf_network_model->communicate(sender, receiver, size_, rate_);
434 surf_action_->set_activity(this);
435 surf_action_->set_category(get_tracing_category());
436 state_ = SIMIX_RUNNING;
438 XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p)", this, sender->get_cname(),
439 receiver->get_cname(), surf_action_);
441 /* If a link is failed, detect it immediately */
442 if (surf_action_->get_state() == resource::Action::State::FAILED) {
443 XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", sender->get_cname(),
444 receiver->get_cname());
445 state_ = SIMIX_LINK_FAILURE;
448 } else if (src_actor_->is_suspended() || dst_actor_->is_suspended()) {
449 /* If any of the process is suspended, create the synchro but stop its execution,
450 it will be restarted when the sender process resume */
451 if (src_actor_->is_suspended())
452 XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the "
454 src_actor_->get_cname(), src_actor_->get_host()->get_cname());
456 XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the "
458 dst_actor_->get_cname(), dst_actor_->get_host()->get_cname());
460 surf_action_->suspend();
467 /** @brief Copy the communication data from the sender's buffer to the receiver's one */
468 void CommImpl::copy_data()
470 size_t buff_size = src_buff_size_;
471 /* If there is no data to copy then return */
472 if (not src_buff_ || not dst_buff_ || copied_)
475 XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this,
476 src_actor_ ? src_actor_->get_host()->get_cname() : "a finished process", src_buff_,
477 dst_actor_ ? dst_actor_->get_host()->get_cname() : "a finished process", dst_buff_, buff_size);
479 /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
481 buff_size = std::min(buff_size, *(dst_buff_size_));
483 /* Update the receiver's buffer size to the copied amount */
485 *dst_buff_size_ = buff_size;
489 copy_data_fun(this, src_buff_, buff_size);
491 SIMIX_comm_copy_data_callback(this, src_buff_, buff_size);
494 /* Set the copied flag so we copy data only once */
495 /* (this function might be called from both communication ends) */
499 void CommImpl::suspend()
501 /* FIXME: shall we suspend also the timeout synchro? */
503 surf_action_->suspend();
504 /* if not created yet, the action will be suspended on creation, in CommImpl::start() */
507 void CommImpl::resume()
509 /*FIXME: check what happen with the timeouts */
511 surf_action_->resume();
512 /* in the other case, the synchro were not really suspended yet, see CommImpl::suspend() and CommImpl::start() */
515 void CommImpl::cancel()
517 /* if the synchro is a waiting state means that it is still in a mbox so remove from it and delete it */
518 if (state_ == SIMIX_WAITING) {
521 state_ = SIMIX_CANCELED;
523 } else if (not MC_is_active() /* when running the MC there are no surf actions */
524 && not MC_record_replay_is_active() && (state_ == SIMIX_READY || state_ == SIMIX_RUNNING)) {
525 surf_action_->cancel();
529 /** @brief This is part of the cleanup process, probably an internal command */
530 void CommImpl::cleanupSurf()
535 src_timeout_->unref();
536 src_timeout_ = nullptr;
540 dst_timeout_->unref();
541 dst_timeout_ = nullptr;
545 void CommImpl::post()
547 /* Update synchro state */
548 if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FINISHED)
549 state_ = SIMIX_SRC_TIMEOUT;
550 else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FINISHED)
551 state_ = SIMIX_DST_TIMEOUT;
552 else if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FAILED)
553 state_ = SIMIX_SRC_HOST_FAILURE;
554 else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FAILED)
555 state_ = SIMIX_DST_HOST_FAILURE;
556 else if (surf_action_ && surf_action_->get_state() == resource::Action::State::FAILED) {
557 state_ = SIMIX_LINK_FAILURE;
561 XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d", this, (int)state_,
562 src_actor_.get(), dst_actor_.get(), detached_);
564 /* destroy the surf actions associated with the Simix communication */
567 /* if there are simcalls associated with the synchro, then answer them */
568 if (not simcalls_.empty()) {
573 void CommImpl::finish()
575 while (not simcalls_.empty()) {
576 smx_simcall_t simcall = simcalls_.front();
577 simcalls_.pop_front();
579 /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
580 * list. Afterwards, get the position of the actual synchro in the waitany list and return it as the result of the
583 if (simcall->call == SIMCALL_NONE) // FIXME: maybe a better way to handle this case
584 continue; // if process handling comm is killed
585 if (simcall->call == SIMCALL_COMM_WAITANY) {
586 SIMIX_waitany_remove_simcall_from_actions(simcall);
587 if (simcall->timer) {
588 simcall->timer->remove();
589 simcall->timer = nullptr;
591 if (not MC_is_active() && not MC_record_replay_is_active()) {
592 CommImpl** comms = simcall_comm_waitany__get__comms(simcall);
593 size_t count = simcall_comm_waitany__get__count(simcall);
594 CommImpl** element = std::find(comms, comms + count, this);
595 int rank = (element != comms + count) ? element - comms : -1;
596 simcall_comm_waitany__set__result(simcall, rank);
600 /* If the synchro is still in a rendez-vous point then remove from it */
604 XBT_DEBUG("CommImpl::finish(): synchro state = %d", static_cast<int>(state_));
606 /* Check out for errors */
608 if (not simcall->issuer->get_host()->is_on()) {
609 simcall->issuer->context_->iwannadie = true;
614 XBT_DEBUG("Communication %p complete!", this);
618 case SIMIX_SRC_TIMEOUT:
619 simcall->issuer->exception_ = std::make_exception_ptr(
620 simgrid::TimeoutError(XBT_THROW_POINT, "Communication timeouted because of the sender"));
623 case SIMIX_DST_TIMEOUT:
624 simcall->issuer->exception_ = std::make_exception_ptr(
625 simgrid::TimeoutError(XBT_THROW_POINT, "Communication timeouted because of the receiver"));
628 case SIMIX_SRC_HOST_FAILURE:
629 if (simcall->issuer == src_actor_)
630 simcall->issuer->context_->iwannadie = true;
632 simcall->issuer->exception_ =
633 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
636 case SIMIX_DST_HOST_FAILURE:
637 if (simcall->issuer == dst_actor_)
638 simcall->issuer->context_->iwannadie = true;
640 simcall->issuer->exception_ =
641 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
644 case SIMIX_LINK_FAILURE:
645 XBT_DEBUG("Link failure in synchro %p between '%s' and '%s': posting an exception to the issuer: %s (%p) "
647 this, src_actor_ ? src_actor_->get_host()->get_cname() : nullptr,
648 dst_actor_ ? dst_actor_->get_host()->get_cname() : nullptr, simcall->issuer->get_cname(),
649 simcall->issuer, detached_);
650 if (src_actor_ == simcall->issuer) {
651 XBT_DEBUG("I'm source");
652 } else if (dst_actor_ == simcall->issuer) {
653 XBT_DEBUG("I'm dest");
655 XBT_DEBUG("I'm neither source nor dest");
657 simcall->issuer->throw_exception(
658 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Link failure")));
662 if (simcall->issuer == dst_actor_)
663 simcall->issuer->exception_ = std::make_exception_ptr(
664 simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the sender"));
666 simcall->issuer->exception_ = std::make_exception_ptr(
667 simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the receiver"));
671 xbt_die("Unexpected synchro state in CommImpl::finish: %d", static_cast<int>(state_));
674 /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
675 if (simcall->issuer->exception_ &&
676 (simcall->call == SIMCALL_COMM_WAITANY || simcall->call == SIMCALL_COMM_TESTANY)) {
677 // First retrieve the rank of our failing synchro
680 if (simcall->call == SIMCALL_COMM_WAITANY) {
681 comms = simcall_comm_waitany__get__comms(simcall);
682 count = simcall_comm_waitany__get__count(simcall);
684 /* simcall->call == SIMCALL_COMM_TESTANY */
685 comms = simcall_comm_testany__get__comms(simcall);
686 count = simcall_comm_testany__get__count(simcall);
688 CommImpl** element = std::find(comms, comms + count, this);
689 int rank = (element != comms + count) ? element - comms : -1;
691 // In order to modify the exception we have to rethrow it:
693 std::rethrow_exception(simcall->issuer->exception_);
694 } catch (simgrid::TimeoutError& e) {
696 simcall->issuer->exception_ = std::make_exception_ptr(e);
697 } catch (simgrid::NetworkFailureException& e) {
699 simcall->issuer->exception_ = std::make_exception_ptr(e);
700 } catch (simgrid::CancelException& e) {
702 simcall->issuer->exception_ = std::make_exception_ptr(e);
706 simcall->issuer->waiting_synchro = nullptr;
707 simcall->issuer->comms.remove(this);
709 if (simcall->issuer == src_actor_) {
711 dst_actor_->comms.remove(this);
712 } else if (simcall->issuer == dst_actor_) {
714 src_actor_->comms.remove(this);
716 dst_actor_->comms.remove(this);
717 src_actor_->comms.remove(this);
721 if (simcall->issuer->get_host()->is_on())
722 SIMIX_simcall_answer(simcall);
724 simcall->issuer->context_->iwannadie = true;
728 } // namespace activity
729 } // namespace kernel
730 } // namespace simgrid