1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /* This example demonstrates how to create a variable load for tasks.
8 * We consider the following graph:
12 * With a small load each comm task is followed by an exec task.
13 * With a heavy load there is a burst of comm before the exec task can even finish once.
16 #include "simgrid/plugins/task.hpp"
17 #include "simgrid/s4u.hpp"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(task_variable_load, "Messages specific for this s4u example");
21 static void variable_load(simgrid::plugins::TaskPtr t)
23 XBT_INFO("--- Small load ---");
24 for (int i = 0; i < 3; i++) {
26 simgrid::s4u::this_actor::sleep_for(100);
28 simgrid::s4u::this_actor::sleep_until(1000);
29 XBT_INFO("--- Heavy load ---");
30 for (int i = 0; i < 3; i++) {
32 simgrid::s4u::this_actor::sleep_for(1);
36 int main(int argc, char* argv[])
38 simgrid::s4u::Engine e(&argc, argv);
39 e.load_platform(argv[1]);
40 simgrid::plugins::Task::init();
43 auto* tremblay = e.host_by_name("Tremblay");
44 auto* jupiter = e.host_by_name("Jupiter");
47 auto comm = simgrid::plugins::CommTask::init("comm", 1e7, tremblay, jupiter);
48 auto exec = simgrid::plugins::ExecTask::init("exec", 1e9, jupiter);
50 // Create the graph by defining dependencies between tasks
51 comm->add_successor(exec);
53 // Add a function to be called when tasks end for log purpose
54 simgrid::plugins::Task::on_end_cb([](const simgrid::plugins::Task* t) {
55 XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count());
58 // Create the actor that will inject load during the simulation
59 simgrid::s4u::Actor::create("input", tremblay, variable_load, comm);
61 // Start the simulation