X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/dceed88b84f4c8dccf94f8031cc9ba635eaf75da..7224ac739b068ae7fc2f1a811eb7ee6410e1f7fe:/examples/s4u/app-masterworker/s4u_app-masterworker.cpp diff --git a/examples/s4u/app-masterworker/s4u_app-masterworker.cpp b/examples/s4u/app-masterworker/s4u_app-masterworker.cpp index 66c380f244..c0ce006b50 100644 --- a/examples/s4u/app-masterworker/s4u_app-masterworker.cpp +++ b/examples/s4u/app-masterworker/s4u_app-masterworker.cpp @@ -38,18 +38,17 @@ public: if (number_of_tasks < 10000 || i % 10000 == 0) XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(), - number_of_tasks, mailbox->name()); + 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(new double(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); + mailbox->put(new double(-1.0), 0); } } }; @@ -70,19 +69,17 @@ 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* task = static_cast(mailbox->get()); + xbt_assert(task != nullptr, "mailbox->get() failed"); + double comp_size = *task; + delete task; + if (comp_size < 0) { /* - Exit when -1.0 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); } - XBT_INFO("I'm done. See you!"); } };