From: Martin Quinson Date: Mon, 6 Aug 2018 00:22:45 +0000 (+0200) Subject: cosmetics in these examples X-Git-Tag: v3_21~291 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3aa9f166d5fd4420c937eb424e42c1cdfeee5b4e cosmetics in these examples --- diff --git a/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp b/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp index cd172d8f3c..65bf93f11f 100644 --- a/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp +++ b/examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp @@ -3,50 +3,46 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "xbt/sysdep.h" #include -#include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this s4u example"); class Master { - long number_of_tasks = 0; /* - Number of tasks */ - double comp_size = 0; /* - Task compute cost */ - double comm_size = 0; /* - Task communication size */ - long workers_count = 0; /* - Number of workers */ + long tasks_count = 0; + double compute_cost = 0; + double communicate_cost = 0; + long workers_count = 0; simgrid::s4u::MailboxPtr mailbox = nullptr; public: explicit Master(std::vector args) { - xbt_assert(args.size() == 5, "The master function expects 4 arguments from the XML deployment file"); + xbt_assert(args.size() == 5, "The master actor expects 4 arguments from the XML deployment file"); - number_of_tasks = std::stol(args[1]); - comp_size = std::stod(args[2]); - comm_size = std::stod(args[3]); - workers_count = std::stol(args[4]); + workers_count = std::stol(args[1]); + tasks_count = std::stol(args[2]); + compute_cost = std::stod(args[3]); + communicate_cost = std::stod(args[4]); - XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks); + XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, tasks_count); } void operator()() { - for (int i = 0; i < number_of_tasks; i++) { /* For each task to be executed: */ - /* - Select a @ref worker in a round-robin way */ + for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */ + /* - Select a worker in a round-robin way */ mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i % workers_count)); - if (number_of_tasks < 10000 || (number_of_tasks < 100000 && i % 10000 == 0) || i % 100000 == 0) - XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(), - number_of_tasks, mailbox->get_cname()); - - /* - Send the computation amount to the @ref worker */ - mailbox->put(new double(comp_size), comm_size); + /* - Send the computation amount to the worker */ + if (tasks_count < 10000 || (tasks_count < 100000 && i % 10000 == 0) || i % 100000 == 0) + XBT_INFO("Sending task %d of %ld to mailbox '%s'", i, tasks_count, mailbox->get_cname()); + mailbox->put(new double(compute_cost), communicate_cost); } - XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); + XBT_INFO("All tasks have been dispatched. Request all workers to stop."); for (int i = 0; i < workers_count; i++) { - /* - Eventually tell all the workers to stop by sending a "finalize" task */ - mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i % workers_count)); + /* The workers stop when receiving a negative compute_cost */ + mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i)); mailbox->put(new double(-1.0), 0); } } @@ -67,37 +63,38 @@ public: void operator()() { - while (1) { /* The worker waits in an infinite loop for tasks sent by the @ref master */ - 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 */ - simgrid::s4u::this_actor::execute(comp_size); - } + double compute_cost; + do { + double* msg = static_cast(mailbox->get()); + compute_cost = *msg; + delete msg; + + if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */ + simgrid::s4u::this_actor::execute(compute_cost); + + } while (compute_cost > 0); /* Stop when receiving an invalid compute_cost */ + + XBT_INFO("Exiting now."); } }; int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); - xbt_assert(argc > 2, - "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment.xml\n", - argv[0], argv[0]); + xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]); - e.load_platform(argv[1]); /* Load the platform description */ - e.register_actor("master"); /* Register the class representing the actors */ + /* Register the classes representing the actors */ + e.register_actor("master"); e.register_actor("worker"); - e.load_deployment(argv[2]); /* Deploy the application */ - e.run(); /** - Run the simulation */ + /* Load the platform description and then deploy the application */ + e.load_platform(argv[1]); + e.load_deployment(argv[2]); + + /* Run the simulation */ + e.run(); - XBT_INFO("Simulation time %g", e.get_clock()); + XBT_INFO("Simulation is over"); return 0; } diff --git a/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp b/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp index b0ff1ddc92..c90c96557a 100644 --- a/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp +++ b/examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp @@ -3,82 +3,81 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "xbt/sysdep.h" #include -#include -XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this s4u example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this example"); static void master(std::vector args) { - xbt_assert(args.size() == 5, "The master function expects 4 arguments from the XML deployment file"); + xbt_assert(args.size() == 5, "The master function expects 4 arguments"); - long number_of_tasks = std::stol(args[1]); - double comp_size = std::stod(args[2]); /* - Task compute cost */ - double comm_size = std::stod(args[3]); /* - Task communication size */ - long workers_count = std::stol(args[4]); + long workers_count = std::stol(args[1]); + long tasks_count = std::stol(args[2]); + double compute_cost = std::stod(args[3]); + double communication_cost = std::stod(args[4]); - XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks); + XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, tasks_count); - simgrid::s4u::MailboxPtr mailbox = nullptr; + for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */ + /* - Select a worker in a round-robin way */ + std::string worker_rank = std::to_string(i % workers_count); + std::string mailbox_name = std::string("worker-") + worker_rank; + simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); - for (int i = 0; i < number_of_tasks; i++) { /* For each task to be executed: */ - /* - Select a @ref worker in a round-robin way */ - mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i % workers_count)); - - if (number_of_tasks < 10000 || (number_of_tasks < 100000 && i % 10000 == 0) || i % 100000 == 0) - XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(), - number_of_tasks, mailbox->get_cname()); - - /* - Send the computation amount to the @ref worker */ - mailbox->put(new double(comp_size), comm_size); + /* - Send the computation cost to that worker */ + XBT_INFO("Sending task %d of %ld to mailbox '%s'", i, tasks_count, mailbox->get_cname()); + mailbox->put(new double(compute_cost), communication_cost); } - XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); + XBT_INFO("All tasks have been dispatched. Request all workers to stop."); for (int i = 0; i < workers_count; i++) { - /* - Eventually tell all the workers to stop by sending a "finalize" task */ - mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(i % workers_count)); + /* The workers stop when receiving a negative compute_cost */ + std::string mailbox_name = std::string("worker-") + std::to_string(i); + simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + mailbox->put(new double(-1.0), 0); } } static void worker(std::vector args) { - xbt_assert(args.size() == 2, "The worker expects a single argument from the XML deployment file: " - "its worker ID (its numerical rank)"); + xbt_assert(args.size() == 2, "The worker expects a single argument"); long id = std::stol(args[1]); - simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(id)); - - while (1) { /* The worker waits in an infinite loop for tasks sent by the @ref master */ - 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 */ - simgrid::s4u::this_actor::execute(comp_size); - } + + const std::string mailbox_name = std::string("worker-") + std::to_string(id); + simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + + double compute_cost; + do { + double* msg = static_cast(mailbox->get()); + compute_cost = *msg; + delete msg; + + if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */ + simgrid::s4u::this_actor::execute(compute_cost); + + } while (compute_cost > 0); /* Stop when receiving an invalid compute_cost */ + + XBT_INFO("Exiting now."); } int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); - xbt_assert(argc > 2, - "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment.xml\n", - argv[0], argv[0]); + xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]); - e.load_platform(argv[1]); /* Load the platform description */ + /* Register the functions representing the actors */ e.register_function("master", &master); e.register_function("worker", &worker); - e.load_deployment(argv[2]); /* Deploy the application */ - e.run(); /** - Run the simulation */ + /* Load the platform description and then deploy the application */ + e.load_platform(argv[1]); + e.load_deployment(argv[2]); + + /* Run the simulation */ + e.run(); - XBT_INFO("Simulation time %g", e.get_clock()); + XBT_INFO("Simulation is over"); return 0; } diff --git a/examples/s4u/app-masterworkers/s4u-app-masterworkers.tesh b/examples/s4u/app-masterworkers/s4u-app-masterworkers.tesh index 4ea65c393b..a0f32d6956 100644 --- a/examples/s4u/app-masterworkers/s4u-app-masterworkers.tesh +++ b/examples/s4u/app-masterworkers/s4u-app-masterworkers.tesh @@ -3,66 +3,64 @@ p Testing a simple master/workers example application ! output sort 19 -$ $SG_TEST_EXENV ${bindir:=.}/s4u-app-masterworkers-class$EXEEXT ${platfdir}/small_platform_with_routers.xml s4u-app-masterworkers_d.xml --cfg=network/crosstraffic:0 --trace "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" -> [ 0.000000] (maestro@) Configuration change: Set 'network/crosstraffic' to '0' +$ $SG_TEST_EXENV ${bindir:=.}/s4u-app-masterworkers-class$EXEEXT ${platfdir}/small_platform.xml s4u-app-masterworkers_d.xml --trace "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" > [ 0.000000] (master@Tremblay) Got 5 workers and 20 tasks to process -> [ 0.000000] (master@Tremblay) Sending "Task_0" (of 20) to mailbox "worker-0" -> [ 0.002265] (master@Tremblay) Sending "Task_1" (of 20) to mailbox "worker-1" -> [ 0.164270] (master@Tremblay) Sending "Task_2" (of 20) to mailbox "worker-2" -> [ 0.316349] (master@Tremblay) Sending "Task_3" (of 20) to mailbox "worker-3" -> [ 0.434977] (master@Tremblay) Sending "Task_4" (of 20) to mailbox "worker-4" -> [ 0.562492] (master@Tremblay) Sending "Task_5" (of 20) to mailbox "worker-0" -> [ 0.564757] (master@Tremblay) Sending "Task_6" (of 20) to mailbox "worker-1" -> [ 0.981618] (master@Tremblay) Sending "Task_7" (of 20) to mailbox "worker-2" -> [ 1.133696] (master@Tremblay) Sending "Task_8" (of 20) to mailbox "worker-3" -> [ 1.584703] (master@Tremblay) Sending "Task_9" (of 20) to mailbox "worker-4" -> [ 1.721105] (master@Tremblay) Sending "Task_10" (of 20) to mailbox "worker-0" -> [ 1.723370] (master@Tremblay) Sending "Task_11" (of 20) to mailbox "worker-1" -> [ 1.885375] (master@Tremblay) Sending "Task_12" (of 20) to mailbox "worker-2" -> [ 2.037454] (master@Tremblay) Sending "Task_13" (of 20) to mailbox "worker-3" -> [ 2.734429] (master@Tremblay) Sending "Task_14" (of 20) to mailbox "worker-4" -> [ 2.879718] (master@Tremblay) Sending "Task_15" (of 20) to mailbox "worker-0" -> [ 2.881983] (master@Tremblay) Sending "Task_16" (of 20) to mailbox "worker-1" -> [ 3.043989] (master@Tremblay) Sending "Task_17" (of 20) to mailbox "worker-2" -> [ 3.196067] (master@Tremblay) Sending "Task_18" (of 20) to mailbox "worker-3" -> [ 3.884155] (master@Tremblay) Sending "Task_19" (of 20) to mailbox "worker-4" -> [ 4.038331] (master@Tremblay) All tasks have been dispatched. Let's tell everybody the computation is over. -> [ 4.038526] (worker@Tremblay) I'm done. See you! -> [ 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! +> [ 0.000000] (master@Tremblay) Sending task 0 of 20 to mailbox 'worker-0' +> [ 0.002265] (master@Tremblay) Sending task 1 of 20 to mailbox 'worker-1' +> [ 0.171420] (master@Tremblay) Sending task 2 of 20 to mailbox 'worker-2' +> [ 0.329817] (master@Tremblay) Sending task 3 of 20 to mailbox 'worker-3' +> [ 0.453549] (master@Tremblay) Sending task 4 of 20 to mailbox 'worker-4' +> [ 0.586168] (master@Tremblay) Sending task 5 of 20 to mailbox 'worker-0' +> [ 0.588433] (master@Tremblay) Sending task 6 of 20 to mailbox 'worker-1' +> [ 0.995917] (master@Tremblay) Sending task 7 of 20 to mailbox 'worker-2' +> [ 1.154314] (master@Tremblay) Sending task 8 of 20 to mailbox 'worker-3' +> [ 1.608379] (master@Tremblay) Sending task 9 of 20 to mailbox 'worker-4' +> [ 1.749885] (master@Tremblay) Sending task 10 of 20 to mailbox 'worker-0' +> [ 1.752150] (master@Tremblay) Sending task 11 of 20 to mailbox 'worker-1' +> [ 1.921304] (master@Tremblay) Sending task 12 of 20 to mailbox 'worker-2' +> [ 2.079701] (master@Tremblay) Sending task 13 of 20 to mailbox 'worker-3' +> [ 2.763209] (master@Tremblay) Sending task 14 of 20 to mailbox 'worker-4' +> [ 2.913601] (master@Tremblay) Sending task 15 of 20 to mailbox 'worker-0' +> [ 2.915867] (master@Tremblay) Sending task 16 of 20 to mailbox 'worker-1' +> [ 3.085021] (master@Tremblay) Sending task 17 of 20 to mailbox 'worker-2' +> [ 3.243418] (master@Tremblay) Sending task 18 of 20 to mailbox 'worker-3' +> [ 3.918038] (master@Tremblay) Sending task 19 of 20 to mailbox 'worker-4' +> [ 4.077318] (master@Tremblay) All tasks have been dispatched. Request all workers to stop. +> [ 4.077513] (worker@Tremblay) Exiting now. +> [ 4.096528] (worker@Jupiter) Exiting now. +> [ 4.122236] (worker@Fafard) Exiting now. +> [ 4.965689] (worker@Ginette) Exiting now. +> [ 5.133855] (maestro@) Simulation is over +> [ 5.133855] (worker@Bourassa) Exiting now. ! output sort 19 -$ $SG_TEST_EXENV ${bindir:=.}/s4u-app-masterworkers-fun$EXEEXT ${platfdir}/small_platform_with_routers.xml s4u-app-masterworkers_d.xml --cfg=network/crosstraffic:0 --trace "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" -> [ 0.000000] (maestro@) Configuration change: Set 'network/crosstraffic' to '0' +$ $SG_TEST_EXENV ${bindir:=.}/s4u-app-masterworkers-fun$EXEEXT ${platfdir}/small_platform.xml s4u-app-masterworkers_d.xml --trace "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" > [ 0.000000] (master@Tremblay) Got 5 workers and 20 tasks to process -> [ 0.000000] (master@Tremblay) Sending "Task_0" (of 20) to mailbox "worker-0" -> [ 0.002265] (master@Tremblay) Sending "Task_1" (of 20) to mailbox "worker-1" -> [ 0.164270] (master@Tremblay) Sending "Task_2" (of 20) to mailbox "worker-2" -> [ 0.316349] (master@Tremblay) Sending "Task_3" (of 20) to mailbox "worker-3" -> [ 0.434977] (master@Tremblay) Sending "Task_4" (of 20) to mailbox "worker-4" -> [ 0.562492] (master@Tremblay) Sending "Task_5" (of 20) to mailbox "worker-0" -> [ 0.564757] (master@Tremblay) Sending "Task_6" (of 20) to mailbox "worker-1" -> [ 0.981618] (master@Tremblay) Sending "Task_7" (of 20) to mailbox "worker-2" -> [ 1.133696] (master@Tremblay) Sending "Task_8" (of 20) to mailbox "worker-3" -> [ 1.584703] (master@Tremblay) Sending "Task_9" (of 20) to mailbox "worker-4" -> [ 1.721105] (master@Tremblay) Sending "Task_10" (of 20) to mailbox "worker-0" -> [ 1.723370] (master@Tremblay) Sending "Task_11" (of 20) to mailbox "worker-1" -> [ 1.885375] (master@Tremblay) Sending "Task_12" (of 20) to mailbox "worker-2" -> [ 2.037454] (master@Tremblay) Sending "Task_13" (of 20) to mailbox "worker-3" -> [ 2.734429] (master@Tremblay) Sending "Task_14" (of 20) to mailbox "worker-4" -> [ 2.879718] (master@Tremblay) Sending "Task_15" (of 20) to mailbox "worker-0" -> [ 2.881983] (master@Tremblay) Sending "Task_16" (of 20) to mailbox "worker-1" -> [ 3.043989] (master@Tremblay) Sending "Task_17" (of 20) to mailbox "worker-2" -> [ 3.196067] (master@Tremblay) Sending "Task_18" (of 20) to mailbox "worker-3" -> [ 3.884155] (master@Tremblay) Sending "Task_19" (of 20) to mailbox "worker-4" -> [ 4.038331] (master@Tremblay) All tasks have been dispatched. Let's tell everybody the computation is over. -> [ 4.038526] (worker@Tremblay) I'm done. See you! -> [ 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! +> [ 0.000000] (master@Tremblay) Sending task 0 of 20 to mailbox 'worker-0' +> [ 0.002265] (master@Tremblay) Sending task 1 of 20 to mailbox 'worker-1' +> [ 0.171420] (master@Tremblay) Sending task 2 of 20 to mailbox 'worker-2' +> [ 0.329817] (master@Tremblay) Sending task 3 of 20 to mailbox 'worker-3' +> [ 0.453549] (master@Tremblay) Sending task 4 of 20 to mailbox 'worker-4' +> [ 0.586168] (master@Tremblay) Sending task 5 of 20 to mailbox 'worker-0' +> [ 0.588433] (master@Tremblay) Sending task 6 of 20 to mailbox 'worker-1' +> [ 0.995917] (master@Tremblay) Sending task 7 of 20 to mailbox 'worker-2' +> [ 1.154314] (master@Tremblay) Sending task 8 of 20 to mailbox 'worker-3' +> [ 1.608379] (master@Tremblay) Sending task 9 of 20 to mailbox 'worker-4' +> [ 1.749885] (master@Tremblay) Sending task 10 of 20 to mailbox 'worker-0' +> [ 1.752150] (master@Tremblay) Sending task 11 of 20 to mailbox 'worker-1' +> [ 1.921304] (master@Tremblay) Sending task 12 of 20 to mailbox 'worker-2' +> [ 2.079701] (master@Tremblay) Sending task 13 of 20 to mailbox 'worker-3' +> [ 2.763209] (master@Tremblay) Sending task 14 of 20 to mailbox 'worker-4' +> [ 2.913601] (master@Tremblay) Sending task 15 of 20 to mailbox 'worker-0' +> [ 2.915867] (master@Tremblay) Sending task 16 of 20 to mailbox 'worker-1' +> [ 3.085021] (master@Tremblay) Sending task 17 of 20 to mailbox 'worker-2' +> [ 3.243418] (master@Tremblay) Sending task 18 of 20 to mailbox 'worker-3' +> [ 3.918038] (master@Tremblay) Sending task 19 of 20 to mailbox 'worker-4' +> [ 4.077318] (master@Tremblay) All tasks have been dispatched. Request all workers to stop. +> [ 4.077513] (worker@Tremblay) Exiting now. +> [ 4.096528] (worker@Jupiter) Exiting now. +> [ 4.122236] (worker@Fafard) Exiting now. +> [ 4.965689] (worker@Ginette) Exiting now. +> [ 5.133855] (maestro@) Simulation is over +> [ 5.133855] (worker@Bourassa) Exiting now. diff --git a/examples/s4u/app-masterworkers/s4u-app-masterworkers_d.xml b/examples/s4u/app-masterworkers/s4u-app-masterworkers_d.xml index feadead6cd..3d93a78b7e 100644 --- a/examples/s4u/app-masterworkers/s4u-app-masterworkers_d.xml +++ b/examples/s4u/app-masterworkers/s4u-app-masterworkers_d.xml @@ -3,10 +3,10 @@ - + + -