From d686bd7fb60842fb5871a3e98f7bbe363722ed0a Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Mon, 20 Nov 2023 09:15:41 -1000 Subject: [PATCH] tweaks --- src/wrench/simgrid_S4U_util/S4U_CommPort.cpp | 70 +++++++++++-------- .../BareMetalComputeServiceOneActionTests.cpp | 5 +- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/wrench/simgrid_S4U_util/S4U_CommPort.cpp b/src/wrench/simgrid_S4U_util/S4U_CommPort.cpp index c84964257e..ff40e4f9a2 100755 --- a/src/wrench/simgrid_S4U_util/S4U_CommPort.cpp +++ b/src/wrench/simgrid_S4U_util/S4U_CommPort.cpp @@ -24,6 +24,7 @@ #include #include #include "wrench/exceptions/ExecutionException.h" +#include "wrench/failure_causes/FatalFailure.h" WRENCH_LOG_CATEGORY(wrench_core_commport, "CommPort"); @@ -78,28 +79,6 @@ namespace wrench { std::unique_ptr S4U_CommPort::getMessage(bool log) { return this->getMessage(-1, log); -#if 0 - if (this == S4U_CommPort::NULL_COMMPORT) { - throw std::invalid_argument("S4U_CommPort::getMessage(): Cannot be called with NULL_COMMPORT"); - } - - if (log) WRENCH_DEBUG("Getting a message from commport '%s'", this->s4u_mb->get_cname()); - SimulationMessage *msg; - try { - // msg = static_cast(commport->get()); - msg = this->s4u_mb->get(-1); - } catch (simgrid::NetworkFailureException &e) { - throw ExecutionException(std::make_shared( - NetworkError::RECEIVING, NetworkError::FAILURE, this->s4u_mb->get_cname())); - } - -#ifdef MESSAGE_MANAGER - MessageManager::removeReceivedMessage(this, msg); -#endif - - WRENCH_DEBUG("Received a '%s' message from commport %s", msg->getName().c_str(), this->s4u_mb->get_cname()); - return std::unique_ptr(msg); -#endif } /** @@ -120,19 +99,52 @@ namespace wrench { if (log) WRENCH_DEBUG("Getting a message from commport '%s' with timeout %lf sec", this->s4u_mb->get_cname(), timeout); SimulationMessage *msg; + simgrid::s4u::ActivitySet pending_receives; + auto mb_comm = this->s4u_mb->get_async(&msg); + pending_receives.push(mb_comm); + + auto mq_comm = this->s4u_mq->get_async(&msg); + + simgrid::s4u::ActivityPtr finished_recv = nullptr; try { - msg = this->s4u_mb->get(timeout); - } catch (simgrid::NetworkFailureException &e) { - throw ExecutionException(std::make_shared( - NetworkError::RECEIVING, NetworkError::FAILURE, this->s4u_mb->get_name())); + // Wait for one activity to complete + finished_recv = pending_receives.wait_any_for(timeout); + // msg = this->s4u_mb->get(timeout); } catch (simgrid::TimeoutException &e) { - throw ExecutionException(std::make_shared( - NetworkError::RECEIVING, NetworkError::TIMEOUT, this->s4u_mb->get_name())); + mb_comm->cancel(); +// mq_comm->cancel(); + throw ExecutionException(std::make_shared(NetworkError::RECEIVING, NetworkError::TIMEOUT, this->name)); + } catch (simgrid::Exception &e) { + auto failed_recv = pending_receives.get_failed_activity(); + if (failed_recv == mb_comm) { +// mq_comm->cancel(); +// mb_comm.reset(); + throw ExecutionException(std::make_shared( + NetworkError::RECEIVING, NetworkError::FAILURE, this->name)); + } else { + mb_comm->cancel(); + throw ExecutionException(std::make_shared("A communication on a MQ should never fail")); + } + } + + if (finished_recv == mb_comm) { + mb_comm->wait(); + } else { + std::cerr << "WTF\n"; } +// } catch (simgrid::NetworkFailureException &e) { +// throw ExecutionException(std::make_shared( +// NetworkError::RECEIVING, NetworkError::FAILURE, this->s4u_mb->get_name())); +// } catch (simgrid::TimeoutException &e) { +// throw ExecutionException(std::make_shared( +// NetworkError::RECEIVING, NetworkError::TIMEOUT, this->s4u_mb->get_name())); +// } + + #ifdef MESSAGE_MANAGER - MessageManager::removeReceivedMessage(this, msg); + MessageManager::removeReceivedMessage(this, msg); #endif WRENCH_DEBUG("Received a '%s' message from commport '%s'", msg->getName().c_str(), this->s4u_mb->get_cname()); diff --git a/test/services/compute_services/bare_metal_compound_jobs/BareMetalComputeServiceOneActionTests.cpp b/test/services/compute_services/bare_metal_compound_jobs/BareMetalComputeServiceOneActionTests.cpp index b699485675..7af914a9cd 100755 --- a/test/services/compute_services/bare_metal_compound_jobs/BareMetalComputeServiceOneActionTests.cpp +++ b/test/services/compute_services/bare_metal_compound_jobs/BareMetalComputeServiceOneActionTests.cpp @@ -317,10 +317,10 @@ void BareMetalComputeServiceOneActionTest::do_Noop_test() { // Create and initialize a simulation auto simulation = wrench::Simulation::createSimulation(); - int argc = 1; + int argc = 2; auto argv = (char **) calloc(argc, sizeof(char *)); argv[0] = strdup("one_action_test"); - // argv[1] = strdup("--wrench-full-log"); + argv[1] = strdup("--wrench-full-log"); ASSERT_NO_THROW(simulation->init(&argc, argv)); @@ -356,6 +356,7 @@ void BareMetalComputeServiceOneActionTest::do_Noop_test() { // Running a "do nothing" simulation ASSERT_NO_THROW(simulation->launch()); + std::cerr << "END OF SIMULATION\n"; for (int i = 0; i < argc; i++)