Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Specialize the Activity on_veto, on_suspend and on_resume in AnyActivity to ease...
[simgrid.git] / examples / cpp / dag-io / s4u-dag-io.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   sg_storage_file_system_init();
17   e.load_platform(argv[1]);
18
19   auto bob  = e.host_by_name("bob");
20   auto carl = e.host_by_name("carl");
21
22   // Display the details on vetoed activities
23   sg4::Exec::on_veto_cb([](sg4::Exec const& exec) {
24     XBT_INFO("Exec '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
25              (exec.dependencies_solved() ? "solved" : "NOT solved"), (exec.is_assigned() ? "assigned" : "NOT assigned"));
26   });
27   sg4::Io::on_veto_cb([](sg4::Io const& io) {
28     XBT_INFO("Io '%s' vetoed. Dependencies: %s; Ressources: %s", io.get_cname(),
29              (io.dependencies_solved() ? "solved" : "NOT solved"), (io.is_assigned() ? "assigned" : "NOT assigned"));
30   });
31
32   sg4::Exec::on_completion_cb([](sg4::Exec const& exec) {
33     XBT_INFO("Exec '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(),
34              exec.get_finish_time());
35   });
36
37   // Create a small DAG: parent->write_output->read_input->child
38   sg4::ExecPtr parent     = sg4::Exec::init();
39   sg4::IoPtr write_output = sg4::Io::init();
40   sg4::IoPtr read_input   = sg4::Io::init();
41   sg4::ExecPtr child      = sg4::Exec::init();
42   parent->add_successor(write_output);
43   write_output->add_successor(read_input);
44   read_input->add_successor(child);
45
46   // Set the parameters (the name is for logging purposes only)
47   // + parent and chile end after 1 second
48   parent->set_name("parent")->set_flops_amount(bob->get_speed());
49   write_output->set_name("write")->set_size(1e9)->set_op_type(sg4::Io::OpType::WRITE);
50   read_input->set_name("read")->set_size(1e9)->set_op_type(sg4::Io::OpType::READ);
51   child->set_name("child")->set_flops_amount(carl->get_speed());
52
53   // Schedule and try to start the different activities
54   parent->set_host(bob)->start();
55   write_output->set_disk(bob->get_disks().front())->start();
56   read_input->set_disk(carl->get_disks().front())->start();
57   child->set_host(carl)->start();
58
59   e.run();
60
61   XBT_INFO("Simulation time %g", sg4::Engine::get_clock());
62
63   return 0;
64 }