1 /* Copyright (c) 2007-2021. 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 #include <simgrid/plugins/file_system.h>
7 #include <simgrid/s4u.hpp>
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
12 int main(int argc, char* argv[])
14 simgrid::s4u::Engine e(&argc, argv);
15 sg_storage_file_system_init();
16 e.load_platform(argv[1]);
18 auto bob = e.host_by_name("bob");
19 auto carl = e.host_by_name("carl");
21 // Display the details on vetoed activities
22 simgrid::s4u::Activity::on_veto.connect([](simgrid::s4u::Activity& a) {
23 XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(),
24 (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned"));
27 simgrid::s4u::Exec::on_completion.connect([](simgrid::s4u::Exec const& exec) {
28 XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(),
29 exec.get_finish_time());
32 // Create a small DAG: parent->write_output->read_input->child
33 simgrid::s4u::ExecPtr parent = simgrid::s4u::Exec::init();
34 simgrid::s4u::IoPtr write_output = simgrid::s4u::Io::init();
35 simgrid::s4u::IoPtr read_input = simgrid::s4u::Io::init();
36 simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init();
37 parent->add_successor(write_output);
38 write_output->add_successor(read_input);
39 read_input->add_successor(child);
41 // Set the parameters (the name is for logging purposes only)
42 // + parent and chile end after 1 second
43 parent->set_name("parent")->set_flops_amount(bob->get_speed());
44 write_output->set_name("write")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::WRITE);
45 read_input->set_name("read")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::READ);
46 child->set_name("child")->set_flops_amount(carl->get_speed());
48 // Schedule and try to start the different activities
49 parent->set_host(bob)->vetoable_start();
50 write_output->set_disk(bob->get_disks().front())->vetoable_start();
51 read_input->set_disk(carl->get_disks().front())->vetoable_start();
52 child->set_host(carl)->vetoable_start();
56 XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());