From 8c76d262ae03d6c121a50c49589ff5106653d0fb Mon Sep 17 00:00:00 2001 From: Takishipp Date: Fri, 8 Sep 2017 14:30:53 +0200 Subject: [PATCH] Make some correction to the converted examples --- .../s4u/async-waitall/s4u_async-waitall.cpp | 2 +- .../s4u/async-waitany/s4u_async-waitany.cpp | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/s4u/async-waitall/s4u_async-waitall.cpp b/examples/s4u/async-waitall/s4u_async-waitall.cpp index c948ebb77b..492bc9477d 100644 --- a/examples/s4u/async-waitall/s4u_async-waitall.cpp +++ b/examples/s4u/async-waitall/s4u_async-waitall.cpp @@ -26,7 +26,7 @@ public: } void operator()() { - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName("receiver_mailbox"); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName("sender_mailbox"); simgrid::s4u::CommPtr* comms = new simgrid::s4u::CommPtr[number_of_tasks + receivers_count] ; for (int i = 0; i < number_of_tasks; i++) { diff --git a/examples/s4u/async-waitany/s4u_async-waitany.cpp b/examples/s4u/async-waitany/s4u_async-waitany.cpp index c41916a87b..26f711ec02 100644 --- a/examples/s4u/async-waitany/s4u_async-waitany.cpp +++ b/examples/s4u/async-waitany/s4u_async-waitany.cpp @@ -12,31 +12,35 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_waitany, "Messages specific for this msg example"); class sender { + long number_of_tasks = 0; /* - Number of tasks */ + long receivers_count = 0; /* - Number of workers */ + int diff_com = 0; + public: explicit sender(std::vector args) { xbt_assert(args.size()== 5, "This function expects 5 parameters from the XML deployment file"); - long number_of_tasks = xbt_str_parse_int(args[0].c_str(), "Invalid amount of tasks: %s"); - double task_comp_size = xbt_str_parse_double(args[1].c_str(), "Invalid computational size: %s"); - double task_comm_size = xbt_str_parse_double(args[2].c_str(), "Invalid communication size: %s"); - long receivers_count = xbt_str_parse_int(args[3].c_str(), "Invalid amount of receivers: %s"); - int diff_com = xbt_str_parse_int(args[4].c_str(), "Invalid value for diff_comm: %s"); + number_of_tasks = std::stol(args[0]); + double task_comp_size = std::stod(args[1]); + double task_comm_size = std::stod(args[2]); + receivers_count = std::stol(args[3]); + diff_com = std::stoi(args[4]); +} +void operator()() +{ std::vector comms; simgrid::s4u::CommPtr comm; simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName("receiver_mailbox"); /* First pack the communications in the dynar */ for (int i = 0; i < number_of_tasks; i++) { double coef = (diff_com == 0) ? 1 : (i + 1); - char mailbox[80]; char taskname[80]; snprintf(mailbox,79, "receiver-%ld", (i % receivers_count)); snprintf(taskname,79, "Task_%d", i); - comm = mbox->put_async((void*)taskname, 42.0); comms.push_back(comm); - XBT_INFO("Send to receiver-%ld %s comm_size %f", i % receivers_count, taskname, task_comm_size / coef); } /* Here we are waiting for the completion of all communications */ @@ -55,21 +59,22 @@ public: comm->wait(); comm = nullptr; } - -} -void operator()() -{ XBT_INFO("Goodbye now!"); } }; class receiver { + int id = 0; + int task_amount = 0; public: explicit receiver(std::vector args) { xbt_assert(args.size() == 2, "This function expects 2 parameters from the XML deployment file"); - int id = xbt_str_parse_int(args[0].c_str(), "ID should be numerical, not %s"); - int task_amount = xbt_str_parse_int(args[1].c_str(), "Invalid amount of tasks: %s"); + id = std::stoi(args[0]); + task_amount = std::stoi(args[1]); +} +void operator()() +{ void *received; std::vector comms; simgrid::s4u::CommPtr comm; @@ -92,9 +97,6 @@ public: } comms.clear(); comm = nullptr; -} -void operator()() -{ /* Here we tell to sender that all tasks are done */ simgrid::s4u::Mailbox::byName("finalize")->put(nullptr, 1); XBT_INFO("I'm done. See you!"); -- 2.20.1