Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add possibility for a battery to be a simple connector and an example. add power...
[simgrid.git] / examples / cpp / chiller-simple / s4u-chiller-simple.cpp
index c5a45b3..079d7c5 100644 (file)
@@ -16,49 +16,21 @@ static void manager(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(),
-           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());
-
   simgrid::s4u::this_actor::sleep_until(1300);
   XBT_INFO("Computation done.");
-
   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());
-
   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(1900);
   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_until(2100);
 }
 
 int main(int argc, char* argv[])
@@ -72,6 +44,10 @@ int main(int argc, char* argv[])
   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);
+  chiller->on_power_change_cb([](simgrid::plugins::Chiller* c) {
+    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());
+  });
 
   e.run();
   return 0;