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 demonstrate basic use of the operation plugin.
8 * We model the following graph:
10 * exec1 -> comm -> exec2
12 * exec1 and exec2 are execution operations.
13 * comm is a communication operation.
16 #include <simgrid/plugins/file_system.h>
17 #include "simgrid/plugins/operation.hpp"
18 #include "simgrid/s4u.hpp"
20 XBT_LOG_NEW_DEFAULT_CATEGORY(operation_simple, "Messages specific for this operation example");
22 int main(int argc, char* argv[])
24 simgrid::s4u::Engine e(&argc, argv);
25 sg_storage_file_system_init();
26 e.load_platform(argv[1]);
27 simgrid::plugins::Operation::init();
30 auto bob = e.host_by_name("bob");
31 auto carl = e.host_by_name("carl");
34 auto exec1 = simgrid::plugins::ExecOp::init("exec1", 1e9, bob);
35 auto exec2 = simgrid::plugins::ExecOp::init("exec2", 1e9, carl);
36 auto write = simgrid::plugins::IoOp::init("write", 1e7, bob->get_disks().front(), simgrid::s4u::Io::OpType::WRITE);
37 auto read = simgrid::plugins::IoOp::init("read", 1e7, carl->get_disks().front(), simgrid::s4u::Io::OpType::READ);
39 // Create the graph by defining dependencies between operations
40 exec1->add_successor(write);
41 write->add_successor(read);
42 read->add_successor(exec2);
44 // Add a function to be called when operations end for log purpose
45 simgrid::plugins::Operation::on_end_cb([](const simgrid::plugins::Operation* op) {
46 XBT_INFO("Operation %s finished (%d)", op->get_name().c_str(), op->get_count());
49 // Enqueue two executions for operation exec1
50 exec1->enqueue_execs(2);
52 // Start the simulation