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 operations.
8 * We consider the following graph:
12 * With a small load each comm operation is followed by an exec operation.
13 * With a heavy load there is a burst of comm before the exec operation can even finish once.
16 #include "simgrid/plugins/operation.hpp"
17 #include "simgrid/s4u.hpp"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(operation_variable_load, "Messages specific for this s4u example");
21 static void variable_load(simgrid::plugins::OperationPtr op)
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::Operation::init();
43 auto tremblay = e.host_by_name("Tremblay");
44 auto jupiter = e.host_by_name("Jupiter");
47 auto comm = simgrid::plugins::CommOp::init("comm", 1e7, tremblay, jupiter);
48 auto exec = simgrid::plugins::ExecOp::init("exec", 1e9, jupiter);
50 // Create the graph by defining dependencies between operations
51 comm->add_successor(exec);
53 // Add a function to be called when operations end for log purpose
54 simgrid::plugins::Operation::on_end_cb([](const simgrid::plugins::Operation* op) {
55 XBT_INFO("Operation %s finished (%d)", op->get_name().c_str(), op->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