Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Energy were not computed correctly for parallel tasks.
authorDavid Glesser <david.glesser@imag.fr>
Wed, 16 Mar 2016 17:25:02 +0000 (18:25 +0100)
committerDavid Glesser <david.glesser@imag.fr>
Wed, 16 Mar 2016 18:06:16 +0000 (19:06 +0100)
The change of computing states were only reported to the first host of the parallel task.

src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/plugins/energy.cpp

index e084657..ccdad63 100644 (file)
@@ -26,10 +26,15 @@ namespace surf {
  * Callbacks *
  *************/
 
-Cpu *getActionCpu(CpuAction *action) {
-  return static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var
-                       (action->getModel()->getMaxminSystem(),
-                       action->getVariable(), 0)));
+std::list<Cpu*> getActionCpus(CpuAction *action) {
+  std::list<Cpu*> retlist;
+  lmm_system_t sys = action->getModel()->getMaxminSystem();
+  int llen = lmm_get_number_of_cnst_from_var(sys, action->getVariable());
+
+  for(int i = 0; i<llen; i++) {
+    retlist.push_back( (Cpu*)(lmm_constraint_id( lmm_get_cnst_from_var(sys, action->getVariable(), i) )) );
+  }
+  return retlist;
 }
 
 simgrid::xbt::signal<void(CpuAction*, e_surf_action_state_t, e_surf_action_state_t)> cpuActionStateChangedCallbacks;
index 5aa2b4b..bb4ceec 100644 (file)
@@ -25,7 +25,7 @@ class CpuPlugin;
 /*************
  * Callbacks *
  *************/
-XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
+XBT_PUBLIC(std::list<Cpu*>) getActionCpus(CpuAction *action);
 
 /*********
  * Model *
index c972873..c0aa357 100644 (file)
@@ -206,16 +206,22 @@ static void onCreation(simgrid::s4u::Host& host) {
 }
 
 static void onActionStateChange(simgrid::surf::CpuAction *action, e_surf_action_state_t previous) {
-  const char *name = getActionCpu(action)->getName();
-  simgrid::surf::HostImpl *host = sg_host_by_name(name)->extension<simgrid::surf::HostImpl>();
-  simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
-  if (vm) // If it's a VM, take the corresponding PM
-    host = vm->getPm()->extension<simgrid::surf::HostImpl>();
-
-  HostEnergy *host_energy = host->p_host->extension<HostEnergy>();
-
-  if(host_energy->last_updated < surf_get_clock())
-    host_energy->update();
+  std::list<simgrid::surf::Cpu*> cpus = getActionCpus(action);
+  for(simgrid::surf::Cpu* cpu : cpus) {
+    const char *name = cpu->getName();
+    sg_host_t sghost = sg_host_by_name(name);
+    if(sghost == NULL)
+      continue;
+    simgrid::surf::HostImpl *host = sghost->extension<simgrid::surf::HostImpl>();
+    simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
+    if (vm) // If it's a VM, take the corresponding PM
+      host = vm->getPm()->extension<simgrid::surf::HostImpl>();
+
+    HostEnergy *host_energy = host->p_host->extension<HostEnergy>();
+
+    if(host_energy->last_updated < surf_get_clock())
+      host_energy->update();
+  }
 }
 
 static void onHostStateChange(simgrid::s4u::Host &host) {