1 /* Copyright (c) 2006-2021. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/s4u.hpp"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(dag_failure, "Logging specific to this example");
11 int main(int argc, char** argv)
13 simgrid::s4u::Engine e(&argc, argv);
14 simgrid::s4u::Engine::set_config("host/model:ptask_L07");
15 e.load_platform(argv[1]);
17 auto* faulty = e.host_by_name("Faulty Host");
18 auto* safe = e.host_by_name("Safe Host");
19 simgrid::s4u::Exec::on_completion.connect([](simgrid::s4u::Exec const& exec) {
20 if (exec.get_state() == simgrid::s4u::Activity::State::FINISHED)
21 XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(),
22 exec.get_finish_time());
23 if (exec.get_state() == simgrid::s4u::Activity::State::FAILED) {
24 if (exec.is_parallel())
25 XBT_INFO("Activity '%s' has failed. %.f %% remain to be done", exec.get_cname(),
26 100 * exec.get_remaining_ratio());
28 XBT_INFO("Activity '%s' has failed. %.f flops remain to be done", exec.get_cname(), exec.get_remaining());
32 /* creation of a single Exec that will poorly fail when the workstation will stop */
33 XBT_INFO("First test: sequential Exec activity");
34 simgrid::s4u::ExecPtr exec =
35 simgrid::s4u::Exec::init()->set_name("Poor task")->set_flops_amount(2e10)->vetoable_start();
37 XBT_INFO("Schedule Activity '%s' on 'Faulty Host'", exec->get_cname());
38 exec->set_host(faulty);
40 /* Add a child Exec that depends on the Poor task' */
41 simgrid::s4u::ExecPtr child = simgrid::s4u::Exec::init()->set_name("Child")->set_flops_amount(2e10)->set_host(safe);
42 exec->add_successor(child);
43 child->vetoable_start();
45 XBT_INFO("Run the simulation");
48 XBT_INFO("let's unschedule Activity '%s' and reschedule it on the 'Safe Host'", exec->get_cname());
52 XBT_INFO("Run the simulation again");
55 XBT_INFO("Second test: parallel Exec activity");
56 exec = simgrid::s4u::Exec::init()->set_name("Poor parallel task")->set_flops_amounts({2e10, 2e10})->vetoable_start();
58 XBT_INFO("Schedule Activity '%s' on 'Safe Host' and 'Faulty Host'", exec->get_cname());
59 exec->set_hosts({safe, faulty});
61 /* Add a child Exec that depends on the Poor task' */
62 child = simgrid::s4u::Exec::init()->set_name("Child")->set_flops_amount(2e10)->set_host(safe);
63 exec->add_successor(child);
64 child->vetoable_start();
66 XBT_INFO("Run the simulation");
69 XBT_INFO("let's unschedule Activity '%s' and reschedule it only on the 'Safe Host'", exec->get_cname());
71 exec->set_flops_amount(4e10)->set_host(safe);
73 XBT_INFO("Run the simulation again");