Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'chiller-plugin' into 'master'
[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 #include <xbt/log.h>
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(chiller_simple, "Messages specific for this s4u example");
12 namespace sg4 = simgrid::s4u;
13
14 static void manager(simgrid::plugins::ChillerPtr c)
15 {
16   XBT_INFO("Initial state: ");
17   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
18            c->get_energy_consumed());
19
20   XBT_INFO("The machines slowly heat up the room.");
21   simgrid::s4u::this_actor::sleep_until(400);
22   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
23            c->get_energy_consumed());
24   simgrid::s4u::this_actor::sleep_until(800);
25   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
26            c->get_energy_consumed());
27   simgrid::s4u::this_actor::sleep_until(1000);
28   XBT_INFO("The Chiller now compensates the heat generated by the machines.");
29   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
30            c->get_energy_consumed());
31   simgrid::s4u::this_actor::sleep_until(1200);
32   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
33            c->get_energy_consumed());
34
35   XBT_INFO("Let's compute something.");
36   sg4::this_actor::exec_async(1e10);
37   simgrid::s4u::this_actor::sleep_until(1250);
38   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
39            c->get_energy_consumed());
40
41   simgrid::s4u::this_actor::sleep_until(1300);
42   XBT_INFO("Computation done.");
43
44   simgrid::s4u::this_actor::sleep_until(1400);
45   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
46            c->get_energy_consumed());
47
48   XBT_INFO("Now let's stress the chiller by decreasing the goal temperature to 23°C.");
49   c->set_goal_temp(23);
50   simgrid::s4u::this_actor::sleep_until(1600);
51   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
52            c->get_energy_consumed());
53   simgrid::s4u::this_actor::sleep_until(1800);
54   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
55            c->get_energy_consumed());
56   simgrid::s4u::this_actor::sleep_until(2000);
57   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
58            c->get_energy_consumed());
59   simgrid::s4u::this_actor::sleep_until(2200);
60   XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
61            c->get_energy_consumed());
62 }
63
64 int main(int argc, char* argv[])
65 {
66   sg4::Engine e(&argc, argv);
67   e.load_platform(argv[1]);
68   sg_host_energy_plugin_init();
69
70   auto chiller = simgrid::plugins::Chiller::init("Chiller", 294, 1006, 0.2, 0.9, 23, 24, 1000);
71   chiller->add_host(e.host_by_name("MyHost1"));
72   chiller->add_host(e.host_by_name("MyHost2"));
73   chiller->add_host(e.host_by_name("MyHost3"));
74   sg4::Actor::create("sender", e.host_by_name("MyHost1"), manager, chiller);
75
76   e.run();
77   return 0;
78 }