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)
* 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");
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 */
--- /dev/null
+#! ./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
* 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;
/*************
* Callbacks *
*************/
-XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
+XBT_PUBLIC(std::list<Cpu*>) getActionCpus(CpuAction *action);
/*********
* Model *
}
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) {