Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
079d7c5b39afeecaa2350adaea0b8e6864951aa0
[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   XBT_INFO("The machines slowly heat up the room.");
20   simgrid::s4u::this_actor::sleep_until(1000);
21   XBT_INFO("The Chiller now compensates the heat generated by the machines.");
22   simgrid::s4u::this_actor::sleep_until(1200);
23   XBT_INFO("Let's compute something.");
24   sg4::this_actor::exec_async(1e10);
25   simgrid::s4u::this_actor::sleep_until(1300);
26   XBT_INFO("Computation done.");
27   simgrid::s4u::this_actor::sleep_until(1400);
28   XBT_INFO("Now let's stress the chiller by decreasing the goal temperature to 23°C.");
29   c->set_goal_temp(23);
30
31   simgrid::s4u::this_actor::sleep_until(1900);
32   simgrid::s4u::this_actor::sleep_until(2000);
33   simgrid::s4u::this_actor::sleep_until(2100);
34 }
35
36 int main(int argc, char* argv[])
37 {
38   sg4::Engine e(&argc, argv);
39   e.load_platform(argv[1]);
40   sg_host_energy_plugin_init();
41
42   auto chiller = simgrid::plugins::Chiller::init("Chiller", 294, 1006, 0.2, 0.9, 23, 24, 1000);
43   chiller->add_host(e.host_by_name("MyHost1"));
44   chiller->add_host(e.host_by_name("MyHost2"));
45   chiller->add_host(e.host_by_name("MyHost3"));
46   sg4::Actor::create("sender", e.host_by_name("MyHost1"), manager, chiller);
47   chiller->on_power_change_cb([](simgrid::plugins::Chiller* c) {
48     XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
49              c->get_energy_consumed());
50   });
51
52   e.run();
53   return 0;
54 }