Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / s4u / dependencies / dependencies.cpp
1 /* Copyright (c) 2006-2023. 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 engine(&argc, argv);
13   xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]);
14   engine.load_platform(argv[1]);
15
16   simgrid::s4u::Exec::on_completion_cb([](simgrid::s4u::Exec const& exec) {
17     XBT_INFO("Exec '%s' start time: %f, finish time: %f", exec.get_cname(), exec.get_start_time(),
18              exec.get_finish_time());
19   });
20
21   /* creation of the activities and their dependencies */
22   simgrid::s4u::ExecPtr A = simgrid::s4u::Exec::init()->set_name("A")->start();
23   simgrid::s4u::ExecPtr B = simgrid::s4u::Exec::init()->set_name("B")->start();
24   simgrid::s4u::ExecPtr C = simgrid::s4u::Exec::init()->set_name("C")->start();
25   simgrid::s4u::ExecPtr D = simgrid::s4u::Exec::init()->set_name("D")->start();
26
27   B->add_successor(A);
28   C->add_successor(A);
29   D->add_successor(B);
30   D->add_successor(C);
31   B->add_successor(C);
32
33   try {
34     A->add_successor(A);
35     /* shouldn't work and must raise an exception */
36     xbt_die("Hey, I can add a dependency between A and A!");
37   } catch (const std::invalid_argument& e) {
38     XBT_INFO("Caught attempt to self-dependency creation: %s", e.what());
39   }
40
41   try {
42     B->add_successor(A); /* shouldn't work and must raise an exception */
43     xbt_die("Oh oh, I can add an already existing dependency!");
44   } catch (const std::invalid_argument& e) {
45     XBT_INFO("Caught attempt to add an already existing dependency: %s", e.what());
46   }
47
48   try {
49     A->remove_successor(C); /* shouldn't work and must raise an exception */
50     xbt_die("Dude, I can remove an unknown dependency!");
51   } catch (const std::invalid_argument& e) {
52     XBT_INFO("Caught attempt to remove an unknown dependency: %s", e.what());
53   }
54
55   try {
56     C->remove_successor(C); /* shouldn't work and must raise an exception */
57     xbt_die("Wow, I can remove a dependency between Task C and itself!");
58   } catch (const std::invalid_argument& e) {
59     XBT_INFO("Caught attempt to remove a self-dependency: %s", e.what());
60   }
61
62   /* scheduling parameters */
63   const auto hosts                           = engine.get_all_hosts();
64   std::vector<simgrid::s4u::Host*> host_list = {hosts[2], hosts[4]};
65   std::vector<double> flops_amounts          = {2000000, 1000000};
66   std::vector<double> bytes_amounts          = {0, 2000000, 3000000, 0};
67
68   A->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
69   B->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
70   C->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
71   D->set_flops_amounts(flops_amounts)->set_bytes_amounts(bytes_amounts)->set_hosts(host_list);
72
73   engine.run();
74   return 0;
75 }