Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'upstream/master' into issue95
[simgrid.git] / teshsuite / s4u / dependencies / dependencies.cpp
1 /* Copyright (c) 2006-2021. 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/s4u.hpp"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(dependencies, "Logging specific to this test");
9
10 int main(int argc, char** argv)
11 {
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]);
15
16   simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) {
17     const auto* exec = dynamic_cast<simgrid::s4u::Exec*>(&activity);
18     if (exec == nullptr) // Only Execs are concerned here
19       return;
20     XBT_INFO("Exec '%s' start time: %f, finish time: %f", exec->get_cname(), exec->get_start_time(),
21              exec->get_finish_time());
22   });
23
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();
29
30   B->add_successor(A);
31   C->add_successor(A);
32   D->add_successor(B);
33   D->add_successor(C);
34   B->add_successor(C);
35
36   try {
37     A->add_successor(A);
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());
42   }
43
44   try {
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());
49   }
50
51   try {
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());
56   }
57
58   try {
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());
63   }
64
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};
70
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);
75
76   e.run();
77   return 0;
78 }