From e2334f2600f6d03f43a79f9c3dc43c2fff21e115 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 7 Aug 2017 13:07:20 +0200 Subject: [PATCH] getting rid of bprintf raises a potential bug :-/ had to add a grace time on the master after sending the 'finalize' order to all workers. Without it, master and Bourassa end at the same time (last worker to be stopped). However, it seems the master finishes first and let bourassa in a 'running' state : Process 6 (worker@Bourassa): waiting for communication synchro 0x24bd6e0 () in state 0 to finish Commenting line 54 triggers the issue. --- .../app-masterworker/s4u_app-masterworker.cpp | 23 ++++++++----------- .../s4u_app-masterworker.tesh | 2 +- teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp | 6 ++--- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/examples/s4u/app-masterworker/s4u_app-masterworker.cpp b/examples/s4u/app-masterworker/s4u_app-masterworker.cpp index 8e13fc5a76..04102b739c 100644 --- a/examples/s4u/app-masterworker/s4u_app-masterworker.cpp +++ b/examples/s4u/app-masterworker/s4u_app-masterworker.cpp @@ -40,17 +40,18 @@ public: XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(), number_of_tasks, mailbox->getName()); - /* - Send the task to the @ref worker */ - char* payload = bprintf("%f", comp_size); - mailbox->put(payload, comm_size); + /* - Send the computation amount to the @ref worker */ + mailbox->put(static_cast(&comp_size), comm_size); } XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); for (int i = 0; i < workers_count; i++) { /* - Eventually tell all the workers to stop by sending a "finalize" task */ mailbox = simgrid::s4u::Mailbox::byName(std::string("worker-") + std::to_string(i % workers_count)); - mailbox->put(xbt_strdup("finalize"), 0); + double finalize = -1; + mailbox->put(static_cast(&finalize), 0); } + simgrid::s4u::this_actor::sleep_for(.1); // Grace time to ensure everyone finishes. } }; @@ -70,19 +71,15 @@ public: void operator()() { while (1) { /* The worker waits in an infinite loop for tasks sent by the \ref master */ - char* res = static_cast(mailbox->get()); - xbt_assert(res != nullptr, "MSG_task_get failed"); - - if (strcmp(res, "finalize") == 0) { /* - Exit if 'finalize' is received */ - xbt_free(res); + double* comp_size = static_cast(mailbox->get()); + xbt_assert(comp_size != nullptr, "MSG_task_get failed"); + if (*comp_size < 0) { /* - Exit if 'finalize' is received */ + XBT_INFO("I'm done. See you!"); break; } /* - Otherwise, process the task */ - double comp_size = std::stod(res); - xbt_free(res); - simgrid::s4u::this_actor::execute(comp_size); + simgrid::s4u::this_actor::execute(*comp_size); } - XBT_INFO("I'm done. See you!"); } }; diff --git a/examples/s4u/app-masterworker/s4u_app-masterworker.tesh b/examples/s4u/app-masterworker/s4u_app-masterworker.tesh index f9b20df3fa..ff2092d8bc 100644 --- a/examples/s4u/app-masterworker/s4u_app-masterworker.tesh +++ b/examples/s4u/app-masterworker/s4u_app-masterworker.tesh @@ -31,6 +31,6 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u_app-masterworker$EXEEXT ${srcdir:=.}/small_pla > [ 4.057541] (worker@Jupiter) I'm done. See you! > [ 4.083249] (worker@Fafard) I'm done. See you! > [ 4.931805] (worker@Ginette) I'm done. See you! -> [ 5.094868] (maestro@) Simulation time 5.09487 > [ 5.094868] (worker@Bourassa) I'm done. See you! +> [ 5.194868] (maestro@) Simulation time 5.19487 diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index 430bb73a21..68dfbc0728 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -50,7 +50,7 @@ static void sender(std::vector args) XBT_INFO("Sender spec: %s", args[0].c_str()); for (unsigned int test = 1; test <= args[0].size(); test++) { this_actor::sleep_until(test * 5 - 5); - char* mboxName = bprintf("Test #%u", test); + const char* mboxName = (std::string("Test #") + std::to_string(test)).c_str(); simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName); switch (args[0][test - 1]) { @@ -97,7 +97,7 @@ static void receiver(std::vector args) XBT_INFO("Receiver spec: %s", args[0].c_str()); for (unsigned int test = 1; test <= args[0].size(); test++) { this_actor::sleep_until(test * 5 - 5); - char* mboxName = bprintf("Test #%u", test); + const char* mboxName = (std::string("Test #") + std::to_string(test)).c_str(); simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName); void* received = nullptr; @@ -148,8 +148,6 @@ static void receiver(std::vector args) } xbt_assert(strcmp(static_cast(received), mboxName) == 0); - xbt_free(received); - xbt_free(mboxName); XBT_INFO("Test %u OK", test); } simgrid::s4u::this_actor::sleep_for(0.5); -- 2.20.1