From: Martin Quinson Date: Thu, 14 Dec 2017 15:33:37 +0000 (+0100) Subject: convert another example to s4u, and move the MSG version away X-Git-Tag: v3.18~34 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/95cd4e6e0c85be242b34630726a82bf5e8e6be17 convert another example to s4u, and move the MSG version away --- diff --git a/.gitignore b/.gitignore index 4a02fc7f6e..1c84169eb9 100644 --- a/.gitignore +++ b/.gitignore @@ -130,7 +130,6 @@ examples/msg/cloud-two-tasks/cloud-two-tasks examples/msg/dht-chord/dht-chord examples/msg/dht-kademlia/dht-kademlia examples/msg/dht-pastry/dht-pastry -examples/msg/energy-consumption/energy-consumption examples/msg/energy-onoff/energy-onoff examples/msg/energy-vm/energy-vm examples/msg/platform-failures/platform-failures @@ -187,10 +186,10 @@ examples/s4u/cloud-simple/s4u-cloud-simple examples/s4u/dht-chord/s4u-dht-chord examples/s4u/energy-link/s4u-energy-link examples/s4u/energy-ptask/s4u-energy-ptask -examples/s4u/energy-pstate/s4u-energy-pstate examples/s4u/energy-vm/s4u-energy-vm examples/s4u/exec-async/s4u-exec-async examples/s4u/exec-basic/s4u-exec-basic +examples/s4u/exec-dvfs/s4u-exec-dvfs examples/s4u/exec-monitor/s4u-exec-monitor examples/s4u/exec-remote/s4u-exec-remote examples/s4u/io-file-system/s4u-io-file-system @@ -258,6 +257,7 @@ teshsuite/msg/async-waitall/async-waitall teshsuite/msg/async-waitany/async-waitany teshsuite/msg/cloud-sharing/cloud-sharing teshsuite/msg/concurrent_rw/concurrent_rw +teshsuite/msg/energy-consumption/energy-consumption teshsuite/msg/energy-pstate/energy-pstate teshsuite/msg/energy-ptask/energy-ptask teshsuite/msg/get_sender/get_sender diff --git a/examples/msg/CMakeLists.txt b/examples/msg/CMakeLists.txt index 9f577cb904..6b15794860 100644 --- a/examples/msg/CMakeLists.txt +++ b/examples/msg/CMakeLists.txt @@ -1,7 +1,7 @@ # C examples foreach(x app-masterworker app-token-ring cloud-capping cloud-masterworker cloud-migration - dht-pastry energy-consumption energy-onoff energy-vm platform-failures + dht-pastry energy-onoff energy-vm platform-failures plugin-hostload process-create synchro-semaphore trace-categories @@ -73,7 +73,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/a foreach(x app-chainsend app-masterworker app-token-ring cloud-capping cloud-masterworker cloud-migration dht-pastry dht-kademlia platform-failures - energy-consumption energy-onoff energy-vm + energy-onoff energy-vm plugin-hostload process-create synchro-semaphore) diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 21024edc7a..78cbb5f7ed 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -2,7 +2,7 @@ foreach (example actor-create actor-daemon actor-join actor-kill actor-lifetime app-chainsend app-masterworker app-pingpong app-token-ring async-wait async-waitany async-waitall cloud-simple - energy-link energy-pstate energy-ptask energy-vm + energy-exec energy-link energy-pstate energy-ptask energy-vm exec-async exec-basic exec-monitor exec-remote io-file-system io-file-remote io-storage-raw mutex @@ -72,7 +72,7 @@ foreach(example actor-create actor-daemon actor-join actor-kill actor-lifetime a async-wait async-waitall async-waitany cloud-simple dht-chord - energy-link energy-pstate energy-ptask energy-vm + energy-exec energy-link energy-pstate energy-ptask energy-vm exec-async exec-basic exec-monitor exec-remote platform-properties plugin-hostload mutex io-file-system io-file-remote io-storage-raw diff --git a/examples/s4u/README.doc b/examples/s4u/README.doc index adf97ff8e6..37eaa95c56 100644 --- a/examples/s4u/README.doc +++ b/examples/s4u/README.doc @@ -220,6 +220,11 @@ also the tesh files in the example directories for details. @section s4u_ex_energy Simulating the energy consumption + - Consumption due to the CPU + @ref examples/s4u/energy-exec/s4u-energy-exec.cpp \n + This example shows how to retrieve the amount of energy consumed + by the CPU during computations, and the impact of the pstate. + - Using Pstates on a host @ref examples/s4u/energy-pstate/s4u-energy-pstate.cpp and @ref examples/platforms/energy_platform.xml \n @@ -252,6 +257,7 @@ also the tesh files in the example directories for details. @example examples/s4u/app-token-ring/s4u-app-token-ring.cpp @example examples/s4u/app-masterworker/s4u-app-masterworker.cpp @example examples/s4u/app-pingpong/s4u-app-pingpong.cpp +@example examples/s4u/energy-exec/s4u-energy-exec.cpp @example examples/s4u/energy-pstate/s4u-energy-pstate.cpp @example examples/s4u/io-file-system/s4u-io-file-system.cpp @example examples/s4u/io-file-remote/s4u-io-file-remote.cpp diff --git a/examples/s4u/energy-exec/s4u-energy-exec.cpp b/examples/s4u/energy-exec/s4u-energy-exec.cpp new file mode 100644 index 0000000000..981e2c7d60 --- /dev/null +++ b/examples/s4u/energy-exec/s4u-energy-exec.cpp @@ -0,0 +1,81 @@ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "simgrid/s4u.hpp" +#include "simgrid/plugins/energy.h" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void dvfs() +{ + simgrid::s4u::Host* host1 = simgrid::s4u::Host::by_name("MyHost1"); + simgrid::s4u::Host* host2 = simgrid::s4u::Host::by_name("MyHost2"); + + XBT_INFO("Energetic profile: %s", host1->getProperty("watt_per_state")); + XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", host1->getSpeed(), + sg_host_get_consumed_energy(host1)); + + double start = simgrid::s4u::Engine::getClock(); + XBT_INFO("Sleep for 10 seconds"); + simgrid::s4u::this_actor::sleep_for(10); + XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E; Energy dissipated=%.2f J", + simgrid::s4u::Engine::getClock() - start, host1->getSpeed(), sg_host_get_consumed_energy(host1)); + + // Execute something + start = simgrid::s4u::Engine::getClock(); + double flopAmount = 100E6; + XBT_INFO("Run a task of %.0E flops", flopAmount); + simgrid::s4u::this_actor::execute(flopAmount); + XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW" + " depending on load; Energy dissipated=%.0f J", + simgrid::s4u::Engine::getClock() - start, host1->getSpeed(), + sg_host_get_wattmin_at(host1, host1->getPstate()), sg_host_get_wattmax_at(host1, host1->getPstate()), + sg_host_get_consumed_energy(host1)); + + // ========= Change power peak ========= + int pstate = 2; + host1->setPstate(pstate); + XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate, + host1->getPstateSpeed(pstate), host1->getSpeed()); + + // Run another task + start = simgrid::s4u::Engine::getClock(); + XBT_INFO("Run a task of %.0E flops", flopAmount); + simgrid::s4u::this_actor::execute(flopAmount); + XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", + simgrid::s4u::Engine::getClock() - start, host1->getSpeed(), sg_host_get_consumed_energy(host1)); + + start = simgrid::s4u::Engine::getClock(); + XBT_INFO("Sleep for 4 seconds"); + simgrid::s4u::this_actor::sleep_for(4); + XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", + simgrid::s4u::Engine::getClock() - start, host1->getSpeed(), sg_host_get_consumed_energy(host1)); + + // =========== Turn the other host off ========== + XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.", + sg_host_get_consumed_energy(host2)); + host2->turnOff(); + start = simgrid::s4u::Engine::getClock(); + simgrid::s4u::this_actor::sleep_for(10); + XBT_INFO("Done sleeping (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", + simgrid::s4u::Engine::getClock() - start, host1->getSpeed(), sg_host_get_consumed_energy(host1)); +} + +int main(int argc, char* argv[]) +{ + sg_host_energy_plugin_init(); + simgrid::s4u::Engine e(&argc, argv); + + xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); + + e.loadPlatform(argv[1]); + simgrid::s4u::Actor::createActor("dvfs_test", simgrid::s4u::Host::by_name("MyHost1"), dvfs); + + e.run(); + + XBT_INFO("End of simulation."); + + return 0; +} diff --git a/examples/s4u/energy-exec/s4u-energy-exec.tesh b/examples/s4u/energy-exec/s4u-energy-exec.tesh new file mode 100644 index 0000000000..4848fea27d --- /dev/null +++ b/examples/s4u/energy-exec/s4u-energy-exec.tesh @@ -0,0 +1,44 @@ +#! ./tesh + +p Testing the mechanism for computing host energy consumption + +$ ${bindir:=.}/s4u-energy-exec$EXEEXT ${platfdir}/energy_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:dvfs_test@MyHost1) Energetic profile: 100.0:120.0:200.0, 93.0:110.0:170.0, 90.0:105.0:150.0 +> [ 0.000000] (1:dvfs_test@MyHost1) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J +> [ 0.000000] (1:dvfs_test@MyHost1) Sleep for 10 seconds +> [ 10.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=1E+08; Energy dissipated=1000.00 J +> [ 10.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops +> [ 11.000000] (1:dvfs_test@MyHost1) Task done (duration: 1.00 s). Current peak speed=1E+08 flop/s; Current consumption: from 120W to 200W depending on load; Energy dissipated=1120 J +> [ 11.000000] (1:dvfs_test@MyHost1) ========= Requesting pstate 2 (speed should be of 2E+07 flop/s and is of 2E+07 flop/s) +> [ 11.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops +> [ 16.000000] (1:dvfs_test@MyHost1) Task done (duration: 5.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=1645 J +> [ 16.000000] (1:dvfs_test@MyHost1) Sleep for 4 seconds +> [ 20.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 4.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2005 J +> [ 20.000000] (1:dvfs_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated 2000 J so far. +> [ 30.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2905 J +> [ 30.000000] (0:maestro@) Total energy consumption: 8005.000000 Joules (used hosts: 5005.000000 Joules; unused/idle hosts: 3000.000000) +> [ 30.000000] (0:maestro@) End of simulation. +> [ 30.000000] (0:maestro@) Energy consumption of host MyHost1: 2905.000000 Joules +> [ 30.000000] (0:maestro@) Energy consumption of host MyHost2: 2100.000000 Joules +> [ 30.000000] (0:maestro@) Energy consumption of host MyHost3: 3000.000000 Joules + +$ ${bindir:=.}/s4u-energy-exec$EXEEXT ${platfdir}/energy_cluster.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --cfg=host/model:ptask_L07 +> [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'ptask_L07' +> [ 0.000000] (0:maestro@) Switching to the L07 model to handle parallel tasks. +> [ 0.000000] (1:dvfs_test@MyHost1) Energetic profile: 100.0:120.0:200.0, 93.0:110.0:170.0, 90.0:105.0:150.0 +> [ 0.000000] (1:dvfs_test@MyHost1) Initial peak speed=1E+08 flop/s; Energy dissipated =0E+00 J +> [ 0.000000] (1:dvfs_test@MyHost1) Sleep for 10 seconds +> [ 10.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=1E+08; Energy dissipated=1000.00 J +> [ 10.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops +> [ 11.000000] (1:dvfs_test@MyHost1) Task done (duration: 1.00 s). Current peak speed=1E+08 flop/s; Current consumption: from 120W to 200W depending on load; Energy dissipated=1120 J +> [ 11.000000] (1:dvfs_test@MyHost1) ========= Requesting pstate 2 (speed should be of 2E+07 flop/s and is of 2E+07 flop/s) +> [ 11.000000] (1:dvfs_test@MyHost1) Run a task of 1E+08 flops +> [ 16.000000] (1:dvfs_test@MyHost1) Task done (duration: 5.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=1645 J +> [ 16.000000] (1:dvfs_test@MyHost1) Sleep for 4 seconds +> [ 20.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 4.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2005 J +> [ 20.000000] (1:dvfs_test@MyHost1) Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated 2000 J so far. +> [ 30.000000] (1:dvfs_test@MyHost1) Done sleeping (duration: 10.00 s). Current peak speed=2E+07 flop/s; Energy dissipated=2905 J +> [ 30.000000] (0:maestro@) Total energy consumption: 5005.000000 Joules (used hosts: 5005.000000 Joules; unused/idle hosts: 0.000000) +> [ 30.000000] (0:maestro@) End of simulation. +> [ 30.000000] (0:maestro@) Energy consumption of host MyHost1: 2905.000000 Joules +> [ 30.000000] (0:maestro@) Energy consumption of host MyHost2: 2100.000000 Joules diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 0ecd2c655b..a505140014 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -5,7 +5,7 @@ foreach(x actions-comm actions-storage cloud-sharing cloud-two-tasks cloud-simple get_sender host_on_off host_on_off_recv host_on_off_processes process-daemon process-kill process-join process-lifetime process-migration process-suspend process-yield - energy-ptask energy-pstate platform-properties + energy-consumption energy-ptask energy-pstate platform-properties io-file io-raw-storage io-file-remote task-priority trace_integration) @@ -84,7 +84,7 @@ foreach(x get_sender task_destroy_cancel task_listen_from task_progress process-daemon process-kill process-join process-lifetime process-migration process-suspend process-yield - energy-ptask + energy-consumption energy-ptask io-file io-raw-storage io-file-remote platform-properties trace_integration) diff --git a/examples/msg/energy-consumption/energy-consumption.c b/teshsuite/msg/energy-consumption/energy-consumption.c similarity index 87% rename from examples/msg/energy-consumption/energy-consumption.c rename to teshsuite/msg/energy-consumption/energy-consumption.c index 87cb1d4480..662d7f66cb 100644 --- a/examples/msg/energy-consumption/energy-consumption.c +++ b/teshsuite/msg/energy-consumption/energy-consumption.c @@ -4,16 +4,16 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/msg.h" #include "simgrid/plugins/energy.h" +#include "simgrid/msg.h" XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); -static int dvfs(int argc, char *argv[]) +static int dvfs(int argc, char* argv[]) { msg_host_t host = MSG_host_by_name("MyHost1"); - XBT_INFO("Energetic profile: %s",MSG_host_get_property_value(host,"watt_per_state")); + XBT_INFO("Energetic profile: %s", MSG_host_get_property_value(host, "watt_per_state")); XBT_INFO("Initial peak speed=%.0E flop/s; Energy dissipated =%.0E J", MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); @@ -24,10 +24,10 @@ static int dvfs(int argc, char *argv[]) MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); // Run a task - start = MSG_get_clock(); - msg_task_t task1 = MSG_task_create ("t1", 100E6, 0, NULL); + start = MSG_get_clock(); + msg_task_t task1 = MSG_task_create("t1", 100E6, 0, NULL); XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1)); - MSG_task_execute (task1); + MSG_task_execute(task1); MSG_task_destroy(task1); XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Current consumption: from %.0fW to %.0fW" " depending on load; Energy dissipated=%.0f J", @@ -35,16 +35,16 @@ static int dvfs(int argc, char *argv[]) sg_host_get_wattmax_at(host, MSG_host_get_pstate(host)), sg_host_get_consumed_energy(host)); // ========= Change power peak ========= - int pstate=2; + int pstate = 2; MSG_host_set_pstate(host, pstate); XBT_INFO("========= Requesting pstate %d (speed should be of %.0E flop/s and is of %.0E flop/s)", pstate, MSG_host_get_power_peak_at(host, pstate), MSG_host_get_speed(host)); // Run a second task start = MSG_get_clock(); - task1 = MSG_task_create ("t2", 100E6, 0, NULL); + task1 = MSG_task_create("t2", 100E6, 0, NULL); XBT_INFO("Run a task of %.0E flops", MSG_task_get_flops_amount(task1)); - MSG_task_execute (task1); + MSG_task_execute(task1); MSG_task_destroy(task1); XBT_INFO("Task done (duration: %.2f s). Current peak speed=%.0E flop/s; Energy dissipated=%.0f J", MSG_get_clock() - start, MSG_host_get_speed(host), sg_host_get_consumed_energy(host)); @@ -57,7 +57,7 @@ static int dvfs(int argc, char *argv[]) // =========== Turn the other host off ========== XBT_INFO("Turning MyHost2 off, and sleeping another 10 seconds. MyHost2 dissipated %.0f J so far.", - sg_host_get_consumed_energy(MSG_host_by_name("MyHost2")) ); + sg_host_get_consumed_energy(MSG_host_by_name("MyHost2"))); MSG_host_off(MSG_host_by_name("MyHost2")); start = MSG_get_clock(); MSG_process_sleep(10); @@ -66,7 +66,7 @@ static int dvfs(int argc, char *argv[]) return 0; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { sg_host_energy_plugin_init(); MSG_init(&argc, argv); diff --git a/examples/msg/energy-consumption/energy-consumption.tesh b/teshsuite/msg/energy-consumption/energy-consumption.tesh similarity index 100% rename from examples/msg/energy-consumption/energy-consumption.tesh rename to teshsuite/msg/energy-consumption/energy-consumption.tesh