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, void* 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, comm, 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, void* src_buff,
35 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, int 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 = simgrid::kernel::activity::CommImplPtr(
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->permanent_receiver_ != nullptr) {
58 // this mailbox is for small messages, which have to be sent right now
59 other_comm->state_ = SIMIX_READY;
60 other_comm->dst_actor_ = mbox->permanent_receiver_.get();
61 mbox->done_comm_queue_.push_back(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_ = SIMIX_READY;
71 other_comm->type = simgrid::kernel::activity::CommImpl::Type::READY;
73 src_proc->comms.push_back(other_comm);
76 other_comm->detached = true;
77 other_comm->clean_fun = clean_fun;
79 other_comm->clean_fun = nullptr;
82 /* Setup the communication synchro */
83 other_comm->src_actor_ = src_proc;
84 other_comm->task_size_ = task_size;
85 other_comm->rate_ = rate;
86 other_comm->src_buff_ = src_buff;
87 other_comm->src_buff_size_ = src_buff_size;
88 other_comm->src_data_ = data;
90 other_comm->match_fun = match_fun;
91 other_comm->copy_data_fun = copy_data_fun;
93 if (MC_is_active() || MC_record_replay_is_active()) {
94 other_comm->state_ = SIMIX_RUNNING;
95 return (detached ? nullptr : other_comm);
100 return (detached ? nullptr : other_comm);
103 XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox,
104 void* dst_buff, size_t* dst_buff_size,
105 int (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
106 void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
107 void* data, double timeout, double rate)
109 smx_activity_t comm = simcall_HANDLER_comm_irecv(simcall, receiver, mbox, dst_buff, dst_buff_size, match_fun,
110 copy_data_fun, data, rate);
111 SIMCALL_SET_MC_VALUE(simcall, 0);
112 simcall_HANDLER_comm_wait(simcall, comm, timeout);
115 XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_irecv(
116 smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, void* dst_buff, size_t* dst_buff_size,
117 simix_match_func_t match_fun, void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
118 void* data, double rate)
120 simgrid::kernel::activity::CommImplPtr this_synchro = simgrid::kernel::activity::CommImplPtr(
121 new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::RECEIVE));
122 XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get());
124 simgrid::kernel::activity::CommImplPtr other_comm;
125 // communication already done, get it inside the list of completed comms
126 if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) {
128 XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
129 // find a match in the list of already received comms
130 other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
131 this_synchro, /*done*/ true,
132 /*remove_matching*/ true);
133 // if not found, assume the receiver came first, register it to the mailbox in the classical way
134 if (not other_comm) {
135 XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request "
137 other_comm = std::move(this_synchro);
138 mbox->push(other_comm);
140 if (other_comm->surf_action_ && other_comm->remains() < 1e-12) {
141 XBT_DEBUG("comm %p has been already sent, and is finished, destroy it", other_comm.get());
142 other_comm->state_ = SIMIX_DONE;
143 other_comm->type = simgrid::kernel::activity::CommImpl::Type::DONE;
144 other_comm->mbox = nullptr;
148 /* Prepare a comm describing us, so that it gets passed to the user-provided filter of other side */
150 /* Look for communication activity matching our needs. We also provide a description of
151 * ourself so that the other side also gets a chance of choosing if it wants to match with us.
153 * If it is not found then push our communication into the rendez-vous point */
154 other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
155 this_synchro, /*done*/ false,
156 /*remove_matching*/ true);
158 if (other_comm == nullptr) {
159 XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue_.size());
160 other_comm = std::move(this_synchro);
161 mbox->push(other_comm);
163 XBT_DEBUG("Match my %p with the existing %p", this_synchro.get(), other_comm.get());
165 other_comm->state_ = SIMIX_READY;
166 other_comm->type = simgrid::kernel::activity::CommImpl::Type::READY;
168 receiver->comms.push_back(other_comm);
171 /* Setup communication synchro */
172 other_comm->dst_actor_ = receiver;
173 other_comm->dst_buff_ = dst_buff;
174 other_comm->dst_buff_size_ = dst_buff_size;
175 other_comm->dst_data_ = data;
177 if (rate > -1.0 && (other_comm->rate_ < 0.0 || rate < other_comm->rate_))
178 other_comm->rate_ = rate;
180 other_comm->match_fun = match_fun;
181 other_comm->copy_data_fun = copy_data_fun;
183 if (MC_is_active() || MC_record_replay_is_active()) {
184 other_comm->state_ = SIMIX_RUNNING;
191 void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_activity_t synchro, double timeout)
193 /* Associate this simcall to the wait synchro */
194 XBT_DEBUG("simcall_HANDLER_comm_wait, %p", synchro.get());
196 synchro->simcalls_.push_back(simcall);
197 simcall->issuer->waiting_synchro = synchro;
199 if (MC_is_active() || MC_record_replay_is_active()) {
200 int idx = SIMCALL_GET_MC_VALUE(simcall);
202 synchro->state_ = SIMIX_DONE;
204 /* If we reached this point, the wait simcall must have a timeout */
205 /* Otherwise it shouldn't be enabled and executed by the MC */
209 simgrid::kernel::activity::CommImplPtr comm =
210 boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
211 if (comm->src_actor_ == simcall->issuer)
212 comm->state_ = SIMIX_SRC_TIMEOUT;
214 comm->state_ = SIMIX_DST_TIMEOUT;
217 boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro)->finish();
221 /* If the synchro has already finish perform the error handling, */
222 /* otherwise set up a waiting timeout on the right side */
223 if (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING) {
224 boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro)->finish();
225 } else { /* we need a sleep action (even when there is no timeout) to be notified of host failures */
226 simgrid::kernel::resource::Action* sleep = simcall->issuer->get_host()->pimpl_cpu->sleep(timeout);
227 sleep->set_data(synchro.get());
229 simgrid::kernel::activity::CommImplPtr comm =
230 boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro);
231 if (simcall->issuer == comm->src_actor_)
232 comm->src_timeout_ = sleep;
234 comm->dst_timeout_ = sleep;
238 void simcall_HANDLER_comm_test(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm)
242 if (MC_is_active() || MC_record_replay_is_active()) {
243 res = comm->src_actor_ && comm->dst_actor_;
245 comm->state_ = SIMIX_DONE;
247 res = comm->state_ != SIMIX_WAITING && comm->state_ != SIMIX_RUNNING;
250 simcall_comm_test__set__result(simcall, res);
251 if (simcall_comm_test__get__result(simcall)) {
252 comm->simcalls_.push_back(simcall);
255 SIMIX_simcall_answer(simcall);
259 void simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::ActivityImplPtr comms[],
262 // The default result is -1 -- this means, "nothing is ready".
263 // It can be changed below, but only if something matches.
264 simcall_comm_testany__set__result(simcall, -1);
266 if (MC_is_active() || MC_record_replay_is_active()) {
267 int idx = SIMCALL_GET_MC_VALUE(simcall);
269 SIMIX_simcall_answer(simcall);
271 simgrid::kernel::activity::ActivityImplPtr synchro = comms[idx];
272 simcall_comm_testany__set__result(simcall, idx);
273 synchro->simcalls_.push_back(simcall);
274 synchro->state_ = SIMIX_DONE;
275 boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro)->finish();
280 for (std::size_t i = 0; i != count; ++i) {
281 simgrid::kernel::activity::ActivityImplPtr synchro = comms[i];
282 if (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING) {
283 simcall_comm_testany__set__result(simcall, i);
284 synchro->simcalls_.push_back(simcall);
285 boost::static_pointer_cast<simgrid::kernel::activity::CommImpl>(synchro)->finish();
289 SIMIX_simcall_answer(simcall);
292 static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall)
294 smx_activity_t* synchros = simcall_comm_waitany__get__comms(simcall);
295 size_t count = simcall_comm_waitany__get__count(simcall);
297 for (size_t i = 0; i < count; i++) {
298 // Remove the first occurence of simcall:
299 smx_activity_t& synchro = synchros[i];
300 auto j = boost::range::find(synchro->simcalls_, simcall);
301 if (j != synchro->simcalls_.end())
302 synchro->simcalls_.erase(j);
305 void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, smx_activity_t* synchros, size_t count, double timeout)
307 if (MC_is_active() || MC_record_replay_is_active()) {
309 xbt_die("Timeout not implemented for waitany in the model-checker");
310 int idx = SIMCALL_GET_MC_VALUE(simcall);
311 smx_activity_t& synchro = synchros[idx];
312 synchro->simcalls_.push_back(simcall);
313 simcall_comm_waitany__set__result(simcall, idx);
314 synchro->state_ = SIMIX_DONE;
320 simcall->timer = NULL;
322 simcall->timer = simgrid::simix::Timer::set(SIMIX_get_clock() + timeout, [simcall]() {
323 SIMIX_waitany_remove_simcall_from_actions(simcall);
324 simcall_comm_waitany__set__result(simcall, -1);
325 SIMIX_simcall_answer(simcall);
329 for (size_t i = 0; i < count; i++) {
330 /* associate this simcall to the the synchro */
331 smx_activity_t& synchro = synchros[i];
332 synchro->simcalls_.push_back(simcall);
334 /* see if the synchro is already finished */
335 if (synchro->state_ != SIMIX_WAITING && synchro->state_ != SIMIX_RUNNING) {
342 /******************************************************************************/
343 /* SIMIX_comm_copy_data callbacks */
344 /******************************************************************************/
345 static void (*SIMIX_comm_copy_data_callback)(simgrid::kernel::activity::CommImpl*, void*,
346 size_t) = &SIMIX_comm_copy_pointer_callback;
348 void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
350 XBT_DEBUG("Copy the data over");
351 memcpy(comm->dst_buff_, buff, buff_size);
352 if (comm->detached) { // if this is a detached send, the source buffer was duplicated by SMPI sender to make the
353 // original buffer available to the application ASAP
355 comm->src_buff_ = nullptr;
359 void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*, size_t))
361 SIMIX_comm_copy_data_callback = callback;
364 void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
366 xbt_assert((buff_size == sizeof(void*)), "Cannot copy %zu bytes: must be sizeof(void*)", buff_size);
367 *(void**)(comm->dst_buff_) = buff;
374 CommImpl::CommImpl(CommImpl::Type type) : type(type)
376 state_ = SIMIX_WAITING;
379 XBT_DEBUG("Create comm activity %p", this);
382 CommImpl::~CommImpl()
384 XBT_DEBUG("Really free communication %p", this);
388 if (detached && state_ != SIMIX_DONE) {
389 /* the communication has failed and was detached:
390 * we have to free the buffer */
392 clean_fun(src_buff_);
400 /** @brief Starts the simulation of a communication synchro. */
401 void CommImpl::start()
403 /* If both the sender and the receiver are already there, start the communication */
404 if (state_ == SIMIX_READY) {
406 s4u::Host* sender = src_actor_->get_host();
407 s4u::Host* receiver = dst_actor_->get_host();
409 surf_action_ = surf_network_model->communicate(sender, receiver, task_size_, rate_);
410 surf_action_->set_data(this);
411 state_ = SIMIX_RUNNING;
413 XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p)", this, sender->get_cname(),
414 receiver->get_cname(), surf_action_);
416 /* If a link is failed, detect it immediately */
417 if (surf_action_->get_state() == resource::Action::State::FAILED) {
418 XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", sender->get_cname(),
419 receiver->get_cname());
420 state_ = SIMIX_LINK_FAILURE;
423 } else if (src_actor_->is_suspended() || dst_actor_->is_suspended()) {
424 /* If any of the process is suspended, create the synchro but stop its execution,
425 it will be restarted when the sender process resume */
426 if (src_actor_->is_suspended())
427 XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the "
429 src_actor_->get_cname(), src_actor_->get_host()->get_cname());
431 XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the "
433 dst_actor_->get_cname(), dst_actor_->get_host()->get_cname());
435 surf_action_->suspend();
440 /** @brief Copy the communication data from the sender's buffer to the receiver's one */
441 void CommImpl::copy_data()
443 size_t buff_size = src_buff_size_;
444 /* If there is no data to copy then return */
445 if (not src_buff_ || not dst_buff_ || copied)
448 XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this,
449 src_actor_ ? src_actor_->get_host()->get_cname() : "a finished process", src_buff_,
450 dst_actor_ ? dst_actor_->get_host()->get_cname() : "a finished process", dst_buff_, buff_size);
452 /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
454 buff_size = std::min(buff_size, *(dst_buff_size_));
456 /* Update the receiver's buffer size to the copied amount */
458 *dst_buff_size_ = buff_size;
462 copy_data_fun(this, src_buff_, buff_size);
464 SIMIX_comm_copy_data_callback(this, src_buff_, buff_size);
467 /* Set the copied flag so we copy data only once */
468 /* (this function might be called from both communication ends) */
472 void CommImpl::suspend()
474 /* FIXME: shall we suspend also the timeout synchro? */
476 surf_action_->suspend();
477 /* if not created yet, the action will be suspended on creation, in CommImpl::start() */
480 void CommImpl::resume()
482 /*FIXME: check what happen with the timeouts */
484 surf_action_->resume();
485 /* in the other case, the synchro were not really suspended yet, see CommImpl::suspend() and CommImpl::start() */
488 void CommImpl::cancel()
490 /* if the synchro is a waiting state means that it is still in a mbox so remove from it and delete it */
491 if (state_ == SIMIX_WAITING) {
493 state_ = SIMIX_CANCELED;
494 } else if (not MC_is_active() /* when running the MC there are no surf actions */
495 && not MC_record_replay_is_active() && (state_ == SIMIX_READY || state_ == SIMIX_RUNNING)) {
496 surf_action_->cancel();
500 /** @brief get the amount remaining from the communication */
501 double CommImpl::remains()
503 return surf_action_->get_remains();
506 /** @brief This is part of the cleanup process, probably an internal command */
507 void CommImpl::cleanupSurf()
510 surf_action_->unref();
511 surf_action_ = nullptr;
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_ = SIMIX_SRC_TIMEOUT;
530 else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FINISHED)
531 state_ = SIMIX_DST_TIMEOUT;
532 else if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FAILED)
533 state_ = SIMIX_SRC_HOST_FAILURE;
534 else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FAILED)
535 state_ = SIMIX_DST_HOST_FAILURE;
536 else if (surf_action_ && surf_action_->get_state() == resource::Action::State::FAILED) {
537 state_ = SIMIX_LINK_FAILURE;
541 XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d", this, (int)state_,
542 src_actor_.get(), dst_actor_.get(), detached);
544 /* destroy the surf actions associated with the Simix communication */
547 /* if there are simcalls associated with the synchro, then answer them */
548 if (not simcalls_.empty()) {
553 void CommImpl::finish()
555 while (not simcalls_.empty()) {
556 smx_simcall_t simcall = simcalls_.front();
557 simcalls_.pop_front();
559 /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
560 * list. Afterwards, get the position of the actual synchro in the waitany list and return it as the result of the
563 if (simcall->call == SIMCALL_NONE) // FIXME: maybe a better way to handle this case
564 continue; // if process handling comm is killed
565 if (simcall->call == SIMCALL_COMM_WAITANY) {
566 SIMIX_waitany_remove_simcall_from_actions(simcall);
567 if (simcall->timer) {
568 simcall->timer->remove();
569 simcall->timer = nullptr;
571 if (not MC_is_active() && not MC_record_replay_is_active()) {
572 CommImpl** comms = simcall_comm_waitany__get__comms(simcall);
573 size_t count = simcall_comm_waitany__get__count(simcall);
574 CommImpl** element = std::find(comms, comms + count, this);
575 int rank = (element != comms + count) ? element - comms : -1;
576 simcall_comm_waitany__set__result(simcall, rank);
580 /* If the synchro is still in a rendez-vous point then remove from it */
584 XBT_DEBUG("CommImpl::finish(): synchro state = %d", static_cast<int>(state_));
586 /* Check out for errors */
588 if (not simcall->issuer->get_host()->is_on()) {
589 simcall->issuer->context_->iwannadie = true;
590 simcall->issuer->exception_ =
591 std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed"));
596 XBT_DEBUG("Communication %p complete!", this);
600 case SIMIX_SRC_TIMEOUT:
601 simcall->issuer->exception_ = std::make_exception_ptr(
602 simgrid::TimeoutError(XBT_THROW_POINT, "Communication timeouted because of the sender"));
605 case SIMIX_DST_TIMEOUT:
606 simcall->issuer->exception_ = std::make_exception_ptr(
607 simgrid::TimeoutError(XBT_THROW_POINT, "Communication timeouted because of the receiver"));
610 case SIMIX_SRC_HOST_FAILURE:
611 if (simcall->issuer == src_actor_)
612 simcall->issuer->context_->iwannadie = true;
614 simcall->issuer->exception_ =
615 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
618 case SIMIX_DST_HOST_FAILURE:
619 if (simcall->issuer == dst_actor_)
620 simcall->issuer->context_->iwannadie = true;
622 simcall->issuer->exception_ =
623 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
626 case SIMIX_LINK_FAILURE:
627 XBT_DEBUG("Link failure in synchro %p between '%s' and '%s': posting an exception to the issuer: %s (%p) "
629 this, src_actor_ ? src_actor_->get_host()->get_cname() : nullptr,
630 dst_actor_ ? dst_actor_->get_host()->get_cname() : nullptr, simcall->issuer->get_cname(),
631 simcall->issuer, detached);
632 if (src_actor_ == simcall->issuer) {
633 XBT_DEBUG("I'm source");
634 } else if (dst_actor_ == simcall->issuer) {
635 XBT_DEBUG("I'm dest");
637 XBT_DEBUG("I'm neither source nor dest");
639 simcall->issuer->throw_exception(
640 std::make_exception_ptr(simgrid::NetworkFailureException(XBT_THROW_POINT, "Link failure")));
644 if (simcall->issuer == dst_actor_)
645 simcall->issuer->exception_ = std::make_exception_ptr(
646 simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the sender"));
648 simcall->issuer->exception_ = std::make_exception_ptr(
649 simgrid::CancelException(XBT_THROW_POINT, "Communication canceled by the receiver"));
653 xbt_die("Unexpected synchro state in CommImpl::finish: %d", static_cast<int>(state_));
656 /* if there is an exception during a waitany or a testany, indicate the position of the failed communication */
657 if (simcall->issuer->exception_ &&
658 (simcall->call == SIMCALL_COMM_WAITANY || simcall->call == SIMCALL_COMM_TESTANY)) {
659 // First retrieve the rank of our failing synchro
662 if (simcall->call == SIMCALL_COMM_WAITANY) {
663 comms = simcall_comm_waitany__get__comms(simcall);
664 count = simcall_comm_waitany__get__count(simcall);
666 /* simcall->call == SIMCALL_COMM_TESTANY */
667 comms = simcall_comm_testany__get__comms(simcall);
668 count = simcall_comm_testany__get__count(simcall);
670 CommImpl** element = std::find(comms, comms + count, this);
671 int rank = (element != comms + count) ? element - comms : -1;
673 // In order to modify the exception we have to rethrow it:
675 std::rethrow_exception(simcall->issuer->exception_);
676 } catch (simgrid::TimeoutError& e) {
678 simcall->issuer->exception_ = std::make_exception_ptr(e);
679 } catch (simgrid::NetworkFailureException& e) {
681 simcall->issuer->exception_ = std::make_exception_ptr(e);
682 } catch (simgrid::CancelException& e) {
684 simcall->issuer->exception_ = std::make_exception_ptr(e);
688 simcall->issuer->waiting_synchro = nullptr;
689 simcall->issuer->comms.remove(this);
691 if (simcall->issuer == src_actor_) {
693 dst_actor_->comms.remove(this);
694 } else if (simcall->issuer == dst_actor_) {
696 src_actor_->comms.remove(this);
698 dst_actor_->comms.remove(this);
699 src_actor_->comms.remove(this);
703 if (simcall->issuer->get_host()->is_on())
704 SIMIX_simcall_answer(simcall);
706 simcall->issuer->context_->iwannadie = true;
710 } // namespace activity
711 } // namespace kernel
712 } // namespace simgrid