Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve chiller example. remove on_power_change signal. add get_time_to_goal_temp
[simgrid.git] / examples / cpp / chiller-simple / s4u-chiller-simple.cpp
1 /* Copyright (c) 2017-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/plugins/chiller.hpp"
7 #include "simgrid/plugins/energy.h"
8 #include "simgrid/s4u.hpp"
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(chiller_simple, "Messages specific for this s4u example");
11 namespace sg4 = simgrid::s4u;
12
13 void display_chiller(simgrid::plugins::ChillerPtr c)
14 {
15   XBT_INFO("%s: Power: %.2fW T_in: %.2f°C Energy consumed: %.2fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
16            c->get_energy_consumed());
17 }
18
19 static void manager(simgrid::plugins::ChillerPtr c)
20 {
21   display_chiller(c);
22
23   simgrid::s4u::this_actor::sleep_for(c->get_time_to_goal_temp());
24   XBT_INFO("The input temperature is now equal to the goal temperature. After this point the Chiller will compensate "
25            "heat with electrical power.");
26   display_chiller(c);
27
28   simgrid::s4u::this_actor::sleep_for(1);
29   display_chiller(c);
30
31   XBT_INFO("Let's compute something.");
32   sg4::this_actor::execute(1e10);
33   XBT_INFO("Computation done.");
34   display_chiller(c);
35   XBT_INFO("Now let's stress the chiller by decreasing the goal temperature to 23°C.");
36   c->set_goal_temp(23);
37
38   simgrid::s4u::this_actor::sleep_for(1);
39   display_chiller(c);
40
41   simgrid::s4u::this_actor::sleep_for(c->get_time_to_goal_temp());
42   XBT_INFO("The input temperature is back to the goal temperature.");
43   display_chiller(c);
44
45   simgrid::s4u::this_actor::sleep_for(1);
46   display_chiller(c);
47 }
48
49 int main(int argc, char* argv[])
50 {
51   sg4::Engine e(&argc, argv);
52   e.load_platform(argv[1]);
53   sg_host_energy_plugin_init();
54
55   auto chiller = simgrid::plugins::Chiller::init("Chiller", 294, 1006, 0.2, 0.9, 23, 24, 1000);
56   chiller->add_host(e.host_by_name("MyHost1"));
57   chiller->add_host(e.host_by_name("MyHost2"));
58   chiller->add_host(e.host_by_name("MyHost3"));
59   sg4::Actor::create("manager", e.host_by_name("MyHost1"), manager, chiller);
60
61   e.run();
62   return 0;
63 }