Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge the merges of merges
authorGabriel Corona <gabriel.corona@loria.fr>
Thu, 17 Mar 2016 08:35:46 +0000 (09:35 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Thu, 17 Mar 2016 08:37:45 +0000 (09:37 +0100)
Maybe we should avoid this merging madness…

examples/msg/parallel_task/CMakeLists.txt
examples/msg/parallel_task/parallel_task.c
examples/msg/parallel_task/parallel_task_energy.tesh [new file with mode: 0644]
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/plugins/energy.cpp

index 257ddc3..a8a8bb7 100644 (file)
@@ -3,5 +3,8 @@ target_link_libraries(parallel_task simgrid)
 
 ADD_TESH_FACTORIES(msg-ptask "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/parallel_task/parallel_task.tesh)
 
+ADD_TESH_FACTORIES(msg-ptask-energy "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg --cd ${CMAKE_BINARY_DIR}/examples/msg ${CMAKE_HOME_DIRECTORY}/examples/msg/parallel_task/parallel_task_energy.tesh)
+
+set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/parallel_task.tesh  PARENT_SCOPE)
 set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/parallel_task.tesh  PARENT_SCOPE)
 set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/parallel_task.c     PARENT_SCOPE)
index 3308119..46990fa 100644 (file)
@@ -5,6 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/msg.h"
+#include "simgrid/plugins/energy.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
 
@@ -70,7 +71,12 @@ int main(int argc, char *argv[])
   MSG_init(&argc, argv);
   MSG_config("host/model", "ptask_L07");
 
-  xbt_assert(argc > 1, "Usage: %s <platform file>", argv[0]);
+  xbt_assert(argc <= 3, "1Usage: %s <platform file> [--energy]", argv[0]);
+  xbt_assert(argc >= 2, "2Usage: %s <platform file> [--energy]", argv[0]);
+
+  if(argc == 3 && argv[2][2] == 'e')
+    sg_energy_plugin_init();
+
   MSG_create_environment(argv[1]);
 
   /* Pick a process, no matter which, from the platform file */
diff --git a/examples/msg/parallel_task/parallel_task_energy.tesh b/examples/msg/parallel_task/parallel_task_energy.tesh
new file mode 100644 (file)
index 0000000..d0d2d91
--- /dev/null
@@ -0,0 +1,12 @@
+#! ./tesh
+
+$ $SG_TEST_EXENV parallel_task/parallel_task$EXEEXT ${srcdir:=.}/../platforms/energy_platform.xml --energy "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks.
+> [  0.000000] (1:test@MyHost1) First, build a classical parallel task, with 1 Gflop to execute on each node, and 10MB to exchange between each pair
+> [300.000000] (1:test@MyHost1) Then, build a parallel task involving only computations and no communication (1 Gflop per node)
+> [310.000000] (1:test@MyHost1) Finally, trick the ptask to do a 'remote execution', on host MyHost2
+> [320.000000] (1:test@MyHost1) Goodbye now!
+> [320.000000] (0:maestro@) Simulation done.
+> [320.000000] (0:maestro@) Total energy of host MyHost1: 34000.000000 Joules
+> [320.000000] (0:maestro@) Total energy of host MyHost2: 35000.000000 Joules
+> [320.000000] (0:maestro@) Total energy of host MyHost3: 34000.000000 Joules
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) {