X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e12f3566491108c4fe51bd553cc599951848e2b8..8c76d262ae03d6c121a50c49589ff5106653d0fb:/examples/s4u/async-waitany/s4u_async-waitany.cpp 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!");