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 tasks.
8 * We model the following graph:
10 * exec1 -> comm -> exec2
12 * exec1 and exec2 are execution tasks.
13 * comm is a communication task.
16 #include "simgrid/s4u/Task.hpp"
17 #include "simgrid/s4u.hpp"
18 #include <simgrid/plugins/file_system.h>
20 XBT_LOG_NEW_DEFAULT_CATEGORY(task_simple, "Messages specific for this task example");
21 namespace sg4 = simgrid::s4u;
23 int main(int argc, char* argv[])
25 sg4::Engine e(&argc, argv);
26 e.load_platform(argv[1]);
29 auto* bob = e.host_by_name("bob");
30 auto* carl = e.host_by_name("carl");
33 auto exec1 = sg4::ExecTask::init("exec1", 1e9, bob);
34 auto exec2 = sg4::ExecTask::init("exec2", 1e9, carl);
35 auto write = sg4::IoTask::init("write", 1e7, bob->get_disks().front(), sg4::Io::OpType::WRITE);
36 auto read = sg4::IoTask::init("read", 1e7, carl->get_disks().front(), sg4::Io::OpType::READ);
38 // Create the graph by defining dependencies between tasks
39 exec1->add_successor(write);
40 write->add_successor(read);
41 read->add_successor(exec2);
43 // Add a function to be called when tasks end for log purpose
44 sg4::Task::on_end_cb([](const sg4::Task* t) {
45 XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count());
48 // Enqueue two executions for task exec1
49 exec1->enqueue_execs(2);
51 // Start the simulation