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_cb([](const 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::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) {
28 const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(&activity);
29 if (exec == nullptr) // Only Execs are concerned here
31 XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec->get_cname(), exec->get_start_time(),
32 exec->get_finish_time());
35 // Create a small DAG: parent->write_output->read_input->child
36 simgrid::s4u::ExecPtr parent = simgrid::s4u::Exec::init();
37 simgrid::s4u::IoPtr write_output = simgrid::s4u::Io::init();
38 simgrid::s4u::IoPtr read_input = simgrid::s4u::Io::init();
39 simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init();
40 parent->add_successor(write_output);
41 write_output->add_successor(read_input);
42 read_input->add_successor(child);
44 // Set the parameters (the name is for logging purposes only)
45 // + parent and chile end after 1 second
46 parent->set_name("parent")->set_flops_amount(bob->get_speed());
47 write_output->set_name("write")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::WRITE);
48 read_input->set_name("read")->set_size(1e9)->set_op_type(simgrid::s4u::Io::OpType::READ);
49 child->set_name("child")->set_flops_amount(carl->get_speed());
51 // Schedule and try to start the different activities
52 parent->set_host(bob)->vetoable_start();
53 write_output->set_disk(bob->get_disks().front())->vetoable_start();
54 read_input->set_disk(carl->get_disks().front())->vetoable_start();
55 child->set_host(carl)->vetoable_start();
59 XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());