1 /* Copyright (c) 2006-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/s4u.hpp"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(dependencies, "Logging specific to this test");
10 int main(int argc, char** argv)
12 simgrid::s4u::Engine e(&argc, argv);
13 xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
14 e.load_platform(argv[1]);
16 simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) {
17 const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(&activity);
18 if (exec == nullptr) // Only Execs are concerned here
20 XBT_INFO("Exec '%s' start time: %f, finish time: %f", exec->get_cname(), exec->get_start_time(),
21 exec->get_finish_time());
24 /* creation of the activities and their dependencies */
25 simgrid::s4u::ExecPtr A = simgrid::s4u::Exec::init()->set_name("A")->vetoable_start();
26 simgrid::s4u::ExecPtr B = simgrid::s4u::Exec::init()->set_name("B")->vetoable_start();
27 simgrid::s4u::ExecPtr C = simgrid::s4u::Exec::init()->set_name("C")->vetoable_start();
28 simgrid::s4u::ExecPtr D = simgrid::s4u::Exec::init()->set_name("D")->vetoable_start();
38 /* shouldn't work and must raise an exception */
39 xbt_die("Hey, I can add a dependency between A and A!");
40 } catch (const std::invalid_argument& e) {
41 XBT_INFO("Caught attempt to self-dependency creation: %s", e.what());
45 B->add_successor(A); /* shouldn't work and must raise an exception */
46 xbt_die("Oh oh, I can add an already existing dependency!");
47 } catch (const std::invalid_argument& e) {
48 XBT_INFO("Caught attempt to add an already existing dependency: %s", e.what());
52 A->remove_successor(C); /* shouldn't work and must raise an exception */
53 xbt_die("Dude, I can remove an unknown dependency!");
54 } catch (const std::invalid_argument& e) {
55 XBT_INFO("Caught attempt to remove an unknown dependency: %s", e.what());
59 C->remove_successor(C); /* shouldn't work and must raise an exception */
60 xbt_die("Wow, I can remove a dependency between Task C and itself!");
61 } catch (const std::invalid_argument& e) {
62 XBT_INFO("Caught attempt to remove a self-dependency: %s", e.what());
65 /* scheduling parameters */
66 const auto hosts = e.get_all_hosts();
67 std::vector<simgrid::s4u::Host*> host_list = {hosts[2], hosts[4]};
68 std::vector<double> flops_amounts = {2000000, 1000000};
69 std::vector<double> bytes_amounts = {0, 2000000, 3000000, 0};
71 A->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
72 B->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
73 C->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
74 D->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);