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.hpp"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(task_simple, "Messages specific for this task example");
20 namespace sg4 = simgrid::s4u;
22 int main(int argc, char* argv[])
24 sg4::Engine e(&argc, argv);
25 e.load_platform(argv[1]);
28 auto* tremblay = e.host_by_name("Tremblay");
29 auto* jupiter = e.host_by_name("Jupiter");
32 auto exec1 = sg4::ExecTask::init("exec1", 1e9, tremblay);
33 auto exec2 = sg4::ExecTask::init("exec2", 1e9, jupiter);
34 auto comm = sg4::CommTask::init("comm", 1e7, tremblay, jupiter);
36 // Create the graph by defining dependencies between tasks
37 exec1->add_successor(comm);
38 comm->add_successor(exec2);
40 // Add a function to be called when tasks end for log purpose
41 sg4::Task::on_completion_cb(
42 [](const sg4::Task* t) { XBT_INFO("Task %s finished (%d)", t->get_name().c_str(), t->get_count()); });
44 // Enqueue two firings for task exec1
45 exec1->enqueue_firings(2);
47 // Start the simulation