Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Clang-tidy: readability-qualified-auto.
[simgrid.git] / examples / cpp / dag-comm / s4u-dag-comm.cpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <simgrid/plugins/file_system.h>
7 #include <simgrid/s4u.hpp>
8 #include <vector>
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11 namespace sg4 = simgrid::s4u;
12
13 int main(int argc, char* argv[])
14 {
15   sg4::Engine e(&argc, argv);
16   e.load_platform(argv[1]);
17
18   auto* tremblay = e.host_by_name("Tremblay");
19   auto* jupiter  = e.host_by_name("Jupiter");
20
21   // Display the details on vetoed activities
22   sg4::Exec::on_veto_cb([](sg4::Exec const& exec) {
23     XBT_INFO("Execution '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
24              (exec.dependencies_solved() ? "solved" : "NOT solved"), (exec.is_assigned() ? "assigned" : "NOT assigned"));
25   });
26   sg4::Comm::on_veto_cb([](sg4::Comm const& comm) {
27     XBT_INFO("Communication '%s' vetoed. Dependencies: %s; Ressources: %s", comm.get_cname(),
28              (comm.dependencies_solved() ? "solved" : "NOT solved"), (comm.is_assigned() ? "assigned" : "NOT assigned"));
29   });
30
31   sg4::Exec::on_completion_cb([](sg4::Exec const& exec) {
32     XBT_INFO("Exec '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(),
33              exec.get_finish_time());
34   });
35   sg4::Comm::on_completion_cb([](sg4::Comm const& comm) {
36     XBT_INFO("Comm '%s' is complete", comm.get_cname());
37   });
38
39   // Create a small DAG: parent->transfer->child
40   sg4::ExecPtr parent   = sg4::Exec::init();
41   sg4::CommPtr transfer = sg4::Comm::sendto_init();
42   sg4::ExecPtr child    = sg4::Exec::init();
43   parent->add_successor(transfer);
44   transfer->add_successor(child);
45
46   // Set the parameters (the name is for logging purposes only)
47   // + parent and child end after 1 second
48   parent->set_name("parent")->set_flops_amount(tremblay->get_speed())->start();
49   transfer->set_name("transfer")->set_payload_size(125e6)->start();
50   child->set_name("child")->set_flops_amount(jupiter->get_speed())->start();
51
52   // Schedule the different activities
53   parent->set_host(tremblay);
54   transfer->set_source(tremblay);
55   child->set_host(jupiter);
56   transfer->set_destination(jupiter);
57
58   e.run();
59
60   XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
61
62   return 0;
63 }