#include "simgrid/plugins/chiller.hpp"
#include "simgrid/plugins/energy.h"
#include "simgrid/s4u.hpp"
-#include <xbt/log.h>
XBT_LOG_NEW_DEFAULT_CATEGORY(chiller_simple, "Messages specific for this s4u example");
namespace sg4 = simgrid::s4u;
-static void manager(simgrid::plugins::ChillerPtr c)
+static void display_chiller(simgrid::plugins::ChillerPtr c)
{
- XBT_INFO("Initial state: ");
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
-
- XBT_INFO("The machines slowly heat up the room.");
- simgrid::s4u::this_actor::sleep_until(400);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
- simgrid::s4u::this_actor::sleep_until(800);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
- simgrid::s4u::this_actor::sleep_until(1000);
- XBT_INFO("The Chiller now compensates the heat generated by the machines.");
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
- simgrid::s4u::this_actor::sleep_until(1200);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
+ XBT_INFO("%s: Power: %.2fW T_in: %.2f°C Energy consumed: %.2fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
c->get_energy_consumed());
+}
- XBT_INFO("Let's compute something.");
- sg4::this_actor::exec_async(1e10);
- simgrid::s4u::this_actor::sleep_until(1250);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
+static void manager(simgrid::plugins::ChillerPtr c)
+{
+ display_chiller(c);
- simgrid::s4u::this_actor::sleep_until(1300);
- XBT_INFO("Computation done.");
+ simgrid::s4u::this_actor::sleep_for(c->get_time_to_goal_temp());
+ XBT_INFO("The input temperature is now equal to the goal temperature. After this point the Chiller will compensate "
+ "heat with electrical power.");
+ display_chiller(c);
- simgrid::s4u::this_actor::sleep_until(1400);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
+ simgrid::s4u::this_actor::sleep_for(1);
+ display_chiller(c);
+ XBT_INFO("Let's compute something.");
+ sg4::this_actor::execute(1e10);
+ XBT_INFO("Computation done.");
+ display_chiller(c);
XBT_INFO("Now let's stress the chiller by decreasing the goal temperature to 23°C.");
c->set_goal_temp(23);
- simgrid::s4u::this_actor::sleep_until(1600);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
- simgrid::s4u::this_actor::sleep_until(1800);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
- simgrid::s4u::this_actor::sleep_until(2000);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
- simgrid::s4u::this_actor::sleep_until(2200);
- XBT_INFO("%s: Power: %fW T_in: %f°C Energy consumed: %fJ", c->get_cname(), c->get_power(), c->get_temp_in(),
- c->get_energy_consumed());
+
+ simgrid::s4u::this_actor::sleep_for(1);
+ display_chiller(c);
+
+ simgrid::s4u::this_actor::sleep_for(c->get_time_to_goal_temp());
+ XBT_INFO("The input temperature is back to the goal temperature.");
+ display_chiller(c);
+
+ simgrid::s4u::this_actor::sleep_for(1);
+ display_chiller(c);
}
int main(int argc, char* argv[])
chiller->add_host(e.host_by_name("MyHost1"));
chiller->add_host(e.host_by_name("MyHost2"));
chiller->add_host(e.host_by_name("MyHost3"));
- sg4::Actor::create("sender", e.host_by_name("MyHost1"), manager, chiller);
+ sg4::Actor::create("manager", e.host_by_name("MyHost1"), manager, chiller);
e.run();
return 0;