From d0421fe3da3f258a0f36f7eb0148e757915b89f7 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 1 Dec 2017 13:09:14 +0100 Subject: [PATCH] add parallel_execute with timeout in s4u. convert the energy-ptask example to test it guess what? it just works ;) well tbh it has the same unvalid reads and uninitialised bytes issues as the MSG version --- examples/s4u/CMakeLists.txt | 4 +- .../s4u/energy-ptask/s4u-energy-ptask.cpp | 91 +++++++++++++++++++ .../s4u/energy-ptask/s4u-energy-ptask.tesh | 16 ++++ include/simgrid/s4u/Actor.hpp | 2 + src/s4u/s4u_actor.cpp | 9 +- 5 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 examples/s4u/energy-ptask/s4u-energy-ptask.cpp create mode 100644 examples/s4u/energy-ptask/s4u-energy-ptask.tesh diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 38866d4ead..6f9e6d91a8 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -2,7 +2,7 @@ foreach (example actions-comm actions-storage actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield app-masterworker app-pingpong app-token-ring async-wait async-waitany async-waitall - energy-link + energy-link energy-ptask plugin-hostload io mutex) add_executable (s4u-${example} ${example}/s4u-${example}.cpp) target_link_libraries(s4u-${example} simgrid) @@ -66,7 +66,7 @@ foreach(example actions-comm actions-storage app-bittorrent app-masterworker app-pingpong app-token-ring async-wait async-waitall async-waitany dht-chord - energy-link + energy-link energy-ptask plugin-hostload io mutex) ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u-${example}.tesh) endforeach() diff --git a/examples/s4u/energy-ptask/s4u-energy-ptask.cpp b/examples/s4u/energy-ptask/s4u-energy-ptask.cpp new file mode 100644 index 0000000000..e699015ed1 --- /dev/null +++ b/examples/s4u/energy-ptask/s4u-energy-ptask.cpp @@ -0,0 +1,91 @@ +/* Copyright (c) 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/plugins/energy.h" +#include +#include +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_energyptask, "Messages specific for this s4u example"); + +static void runner() +{ + /* Retrieve the list of all hosts as an array of hosts */ + int hosts_count = sg_host_count(); + simgrid::s4u::Host** hosts = sg_host_list(); + + XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, " + "and 10MB to exchange between each pair"); + double* computation_amounts = new double[hosts_count](); + double* communication_amounts = new double[hosts_count * hosts_count](); + + for (int i = 0; i < hosts_count; i++) + computation_amounts[i] = 1e9; // 1 Gflop + + for (int i = 0; i < hosts_count; i++) + for (int j = i + 1; j < hosts_count; j++) + communication_amounts[i * hosts_count + j] = 1e7; // 10 MB + + simgrid::s4u::this_actor::parallel_execute(hosts_count, hosts, computation_amounts, communication_amounts); + + XBT_INFO("We can do the same with a timeout of one second enabled."); + computation_amounts = new double[hosts_count](); + communication_amounts = new double[hosts_count * hosts_count](); + + for (int i = 0; i < hosts_count; i++) + computation_amounts[i] = 1e9; // 1 Gflop + + for (int i = 0; i < hosts_count; i++) + for (int j = i + 1; j < hosts_count; j++) + communication_amounts[i * hosts_count + j] = 1e7; // 10 MB + + try { + simgrid::s4u::this_actor::parallel_execute(hosts_count, hosts, computation_amounts, communication_amounts, + 1.0 /* timeout (in seconds)*/); + XBT_WARN("Woops, this did not timeout as expected... Please report that bug."); + } catch (xbt_ex& e) { + /* Do nothing this exception on timeout was expected */ + } + + XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)"); + computation_amounts = new double[hosts_count](); + for (int i = 0; i < hosts_count; i++) + computation_amounts[i] = 1e9; // 1 Gflop + simgrid::s4u::this_actor::parallel_execute(hosts_count, hosts, computation_amounts, nullptr /* no comm */); + + XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)"); + computation_amounts = new double[hosts_count](); + communication_amounts = new double[hosts_count * hosts_count](); + simgrid::s4u::this_actor::parallel_execute(hosts_count, hosts, computation_amounts, communication_amounts); + + XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", hosts[1]->getCname()); + computation_amounts = new double[1]{1e9}; + + simgrid::s4u::Host* remote[] = {hosts[1]}; + simgrid::s4u::this_actor::parallel_execute(1, remote, computation_amounts, nullptr); + + XBT_INFO("Goodbye now!"); + std::free(hosts); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + + xbt_assert(argc <= 3, "1Usage: %s [--energy]", argv[0]); + xbt_assert(argc >= 2, "2Usage: %s [--energy]", argv[0]); + + if (argc == 3 && argv[2][2] == 'e') + sg_host_energy_plugin_init(); + + e.loadPlatform(argv[1]); + + /* Pick a process, no matter which, from the platform file */ + simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("MyHost1"), runner); + + e.run(); + XBT_INFO("Simulation done."); + return 0; +} diff --git a/examples/s4u/energy-ptask/s4u-energy-ptask.tesh b/examples/s4u/energy-ptask/s4u-energy-ptask.tesh new file mode 100644 index 0000000000..121e734bf4 --- /dev/null +++ b/examples/s4u/energy-ptask/s4u-energy-ptask.tesh @@ -0,0 +1,16 @@ +#! ./tesh + +$ ${bindir:=.}/s4u-energy-ptask$EXEEXT ${srcdir:=.}/../platforms/energy_platform.xml --energy --cfg=host/model:ptask_L07 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 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: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) We can do the same with a timeout of one second enabled. +> [301.000000] (1:test@MyHost1) Then, build a parallel task involving only computations and no communication (1 Gflop per node) +> [311.000000] (1:test@MyHost1) Then, build a parallel task with no computation nor communication (synchro only) +> [311.000000] (1:test@MyHost1) Finally, trick the ptask to do a 'remote execution', on host MyHost2 +> [321.000000] (1:test@MyHost1) Goodbye now! +> [321.000000] (0:maestro@) Total energy consumption: 157960.888889 Joules (used hosts: 157960.888889 Joules; unused/idle hosts: 0.000000) +> [321.000000] (0:maestro@) Simulation done. +> [321.000000] (0:maestro@) Energy consumption of host MyHost1: 30560.888889 Joules +> [321.000000] (0:maestro@) Energy consumption of host MyHost2: 64200.000000 Joules +> [321.000000] (0:maestro@) Energy consumption of host MyHost3: 63200.000000 Joules diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index b43073fe4d..bca444cce0 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -309,6 +309,8 @@ XBT_PUBLIC(void) execute(double flop); XBT_PUBLIC(void) execute(double flop, double priority); XBT_PUBLIC(void) parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount); +XBT_PUBLIC(void) +parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount, double timeout); /** Block the actor until it gets a message from the given mailbox. * diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 0a77a229a2..02b8a9ae51 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -232,12 +232,19 @@ void execute(double flops) simcall_execution_wait(s); } -void execute(double flops,double priority) +void execute(double flops, double priority) { smx_activity_t s = simcall_execution_start(nullptr,flops,1 / priority/*priority*/,0./*bound*/); simcall_execution_wait(s); } +void parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount, double timeout) +{ + smx_activity_t s = + simcall_execution_parallel_start(nullptr, host_nb, host_list, flops_amount, bytes_amount, -1, timeout); + simcall_execution_wait(s); +} + void parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount) { smx_activity_t s = simcall_execution_parallel_start(nullptr, host_nb, host_list, flops_amount, bytes_amount, -1, -1); -- 2.20.1