examples/s4u/actor-yield/s4u-actor-yield
examples/s4u/app-bittorrent/s4u-bittorrent
examples/s4u/app-chainsend/s4u-app-chainsend
-examples/s4u/app-masterworker/s4u-app-masterworker
+examples/s4u/app-masterworkers/s4u-app-masterworkers-class
+examples/s4u/app-masterworkers/s4u-app-masterworkers-fun
examples/s4u/app-pingpong/s4u-app-pingpong
examples/s4u/app-token-ring/s4u-app-token-ring
examples/s4u/async-wait/s4u-async-wait
examples/s4u/io-file-system/s4u-io-file-system
examples/s4u/io-storage-raw/s4u-io-storage-raw
examples/s4u/mutex/s4u-mutex
+examples/s4u/platform-failures/s4u-platform-failures
examples/s4u/platform-properties/s4u-platform-properties
examples/s4u/plugin-hostload/s4u-plugin-hostload
examples/s4u/replay-comm/s4u-replay-comm
# the same at the bottom of the file as well.
foreach (example actor-create actor-daemon actor-join actor-kill
actor-lifetime actor-migration actor-suspend actor-yield
- app-chainsend app-masterworker app-pingpong app-token-ring
+ app-chainsend app-pingpong app-token-ring
async-wait async-waitany async-waitall
cloud-capping cloud-migration cloud-simple
energy-exec energy-boot energy-link energy-vm
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u-${example}.cpp)
endforeach()
+# MASTERWORKERS EXAMPLE
+foreach(variant fun class)
+ add_executable (s4u-app-masterworkers-${variant} app-masterworkers/s4u-app-masterworkers-${variant}.cpp)
+ target_link_libraries(s4u-app-masterworkers-${variant} simgrid)
+ set_target_properties(s4u-app-masterworkers-${variant} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/app-masterworkers)
+
+ set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/masterworkers-fun/s4u-masterworkers-${variant}.cpp)
+endforeach()
+set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/masterworkers-fun/s4u-masterworkers.tesh)
+
+
# CHORD EXAMPLE
add_executable (s4u-dht-chord dht-chord/s4u-dht-chord.cpp dht-chord/s4u-dht-chord-node.cpp)
target_link_libraries(s4u-dht-chord simgrid)
${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/actor-yield/s4u-actor-yield_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent_d.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/s4u-app-masterworker_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworkers/s4u-app-masterworkers_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml
foreach(example actor-create actor-daemon actor-join actor-kill
actor-lifetime actor-migration actor-suspend actor-yield
- app-bittorrent app-chainsend app-masterworker app-pingpong app-token-ring
+ app-bittorrent app-chainsend app-masterworkers app-pingpong app-token-ring
async-wait async-waitall async-waitany
cloud-capping cloud-migration cloud-simple
dht-chord dht-kademlia
+++ /dev/null
-#!/usr/bin/env tesh
-
-p Testing a simple master/worker example application (mailbox version)
-
-! output sort 19
-$ $SG_TEST_EXENV ${bindir:=.}/s4u-app-masterworker$EXEEXT ${platfdir}/small_platform_with_routers.xml s4u-app-masterworker_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'
-> [ 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!
-
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",
+ xbt_assert(argc > 2,
+ "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n",
argv[0], argv[0]);
e.load_platform(argv[1]); /* Load the platform description */
--- /dev/null
+/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved. */
+
+/* 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 <simgrid/s4u.hpp>
+#include <string>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this s4u example");
+
+static void master(std::vector<std::string> args)
+{
+ xbt_assert(args.size() == 5, "The master function expects 4 arguments from the XML deployment file");
+
+ 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]);
+
+ XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks);
+
+ simgrid::s4u::MailboxPtr mailbox = nullptr;
+
+ 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);
+ }
+
+ 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::by_name(std::string("worker-") + std::to_string(i % workers_count));
+ mailbox->put(new double(-1.0), 0);
+ }
+}
+
+static void worker(std::vector<std::string> args)
+{
+ xbt_assert(args.size() == 2, "The worker expects a single argument from the XML deployment file: "
+ "its worker ID (its numerical rank)");
+ 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<double*>(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);
+ }
+}
+
+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]);
+
+ e.load_platform(argv[1]); /* Load the platform description */
+ e.register_function("master", &master);
+ e.register_function("worker", &worker);
+ e.load_deployment(argv[2]); /* Deploy the application */
+
+ e.run(); /** - Run the simulation */
+
+ XBT_INFO("Simulation time %g", e.get_clock());
+
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+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'
+> [ 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!
+
+! 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'
+> [ 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!
+