From 101fcbed03bfeed4271fba2743468355ba004e79 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 25 Feb 2020 11:52:32 +0100 Subject: [PATCH] convert energy-ptask to energy-exec-ptask still have to make C and C++ match --- MANIFEST.in | 4 +- examples/c/CMakeLists.txt | 4 +- .../c/energy-exec-ptask/energy-exec-ptask.c | 105 ++++++++++++++++ .../energy-exec-ptask/energy-exec-ptask.tesh | 2 +- teshsuite/msg/CMakeLists.txt | 3 +- teshsuite/msg/energy-ptask/energy-ptask.c | 118 ------------------ 6 files changed, 111 insertions(+), 125 deletions(-) create mode 100644 examples/c/energy-exec-ptask/energy-exec-ptask.c rename teshsuite/msg/energy-ptask/energy-ptask.tesh => examples/c/energy-exec-ptask/energy-exec-ptask.tesh (90%) delete mode 100644 teshsuite/msg/energy-ptask/energy-ptask.c diff --git a/MANIFEST.in b/MANIFEST.in index a6e395b4b7..8e727c7365 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -63,6 +63,8 @@ include examples/c/cloud-migration/cloud-migration.c include examples/c/cloud-migration/cloud-migration.tesh include examples/c/cloud-simple/cloud-simple.c include examples/c/cloud-simple/cloud-simple.tesh +include examples/c/energy-exec-ptask/energy-exec-ptask.c +include examples/c/energy-exec-ptask/energy-exec-ptask.tesh include examples/c/energy-exec/energy-exec.c include examples/c/energy-exec/energy-exec.tesh include examples/c/energy-vm/energy-vm.c @@ -649,8 +651,6 @@ include teshsuite/msg/app-bittorrent/tracker.c include teshsuite/msg/app-bittorrent/tracker.h include teshsuite/msg/cloud-two-tasks/cloud-two-tasks.c include teshsuite/msg/cloud-two-tasks/cloud-two-tasks.tesh -include teshsuite/msg/energy-ptask/energy-ptask.c -include teshsuite/msg/energy-ptask/energy-ptask.tesh include teshsuite/msg/get_sender/get_sender.c include teshsuite/msg/get_sender/get_sender.tesh include teshsuite/msg/host_on_off_processes/host_on_off_processes.cpp diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 864d2cf02d..6ceedc41f1 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -7,7 +7,7 @@ foreach(x async-wait async-waitall async-waitany cloud-capping cloud-migration cloud-simple exec-dvfs - energy-exec energy-vm + energy-exec energy-exec-ptask energy-vm io-disk-raw io-file-remote plugin-hostload) add_executable (${x}-c EXCLUDE_FROM_ALL ${x}/${x}.c) @@ -60,7 +60,7 @@ foreach(x async-wait async-waitall async-waitany cloud-capping cloud-migration cloud-simple exec-dvfs - energy-exec energy-vm + energy-exec energy-exec-ptask energy-vm io-disk-raw io-file-remote plugin-hostload) ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms diff --git a/examples/c/energy-exec-ptask/energy-exec-ptask.c b/examples/c/energy-exec-ptask/energy-exec-ptask.c new file mode 100644 index 0000000000..f4e9888972 --- /dev/null +++ b/examples/c/energy-exec-ptask/energy-exec-ptask.c @@ -0,0 +1,105 @@ +/* Copyright (c) 2007-2020. 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/actor.h" +#include "simgrid/engine.h" +#include "simgrid/exec.h" +#include "simgrid/host.h" +#include "simgrid/plugins/energy.h" +#include "xbt/asserts.h" +#include "xbt/config.h" +#include "xbt/log.h" + +XBT_LOG_NEW_DEFAULT_CATEGORY(energy_exec_ptask, "Messages specific for this example"); + +static void runner(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) +{ + /* Retrieve the list of all hosts as an array of hosts */ + int host_count = sg_host_count(); + sg_host_t* 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 = (double*)calloc(host_count, sizeof(double)); + double* communication_amounts = (double*)calloc(host_count * host_count, sizeof(double)); + + for (int i = 0; i < host_count; i++) + computation_amounts[i] = 1e9; // 1 Gflop + + for (int i = 0; i < host_count; i++) + for (int j = i + 1; j < host_count; j++) + communication_amounts[i * host_count + j] = 1e7; // 10 MB + + sg_actor_parallel_execute(host_count, hosts, computation_amounts, communication_amounts); + + free(communication_amounts); + free(computation_amounts); + + XBT_INFO("We can do the same with a timeout of one second enabled."); + computation_amounts = (double*)calloc(host_count, sizeof(double)); + communication_amounts = (double*)calloc(host_count * host_count, sizeof(double)); + for (int i = 0; i < host_count; i++) + computation_amounts[i] = 1e9; // 1 Gflop + for (int i = 0; i < host_count; i++) + for (int j = i + 1; j < host_count; j++) + communication_amounts[i * host_count + j] = 1e7; // 10 MB + + sg_exec_t exec = sg_actor_parallel_exec_init(host_count, hosts, computation_amounts, communication_amounts); + sg_exec_wait_for(exec, 1 /* timeout (in seconds)*/); + free(communication_amounts); + free(computation_amounts); + + XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)"); + computation_amounts = (double*)calloc(host_count, sizeof(double)); + for (int i = 0; i < host_count; i++) + computation_amounts[i] = 1e9; // 1 Gflop + sg_actor_parallel_execute(host_count, hosts, computation_amounts, NULL); + free(computation_amounts); + + XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)"); + computation_amounts = (double*)calloc(host_count, sizeof(double)); + communication_amounts = (double*)calloc(host_count * host_count, sizeof(double)); + sg_actor_parallel_execute(host_count, hosts, computation_amounts, communication_amounts); + free(communication_amounts); + free(computation_amounts); + + XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", sg_host_get_name(hosts[1])); + computation_amounts = (double*)calloc(1, sizeof(double)); + computation_amounts[0] = 1e9; // 1 Gflop + sg_host_t remote[1]; + remote[0] = hosts[1]; + sg_actor_parallel_execute(1, remote, computation_amounts, NULL /* no comm */); + free(computation_amounts); + + XBT_INFO("Goodbye now!"); + free(hosts); +} + +int main(int argc, char* argv[]) +{ + simgrid_init(&argc, argv); + sg_cfg_set_string("host/model", "ptask_L07"); + + 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(); + + simgrid_load_platform(argv[1]); + + /* Pick a process, no matter which, from the platform file */ + sg_host_t* all_hosts = sg_host_list(); + sg_host_t first_host = all_hosts[0]; + free(all_hosts); + + sg_actor_t actor = sg_actor_init("test", first_host); + sg_actor_start(actor, runner, 0, NULL); + + simgrid_run(); + XBT_INFO("Simulation done."); + + return 0; +} diff --git a/teshsuite/msg/energy-ptask/energy-ptask.tesh b/examples/c/energy-exec-ptask/energy-exec-ptask.tesh similarity index 90% rename from teshsuite/msg/energy-ptask/energy-ptask.tesh rename to examples/c/energy-exec-ptask/energy-exec-ptask.tesh index 2ab7b15aa9..8f02000c45 100644 --- a/teshsuite/msg/energy-ptask/energy-ptask.tesh +++ b/examples/c/energy-exec-ptask/energy-exec-ptask.tesh @@ -1,6 +1,6 @@ #!/usr/bin/env tesh -$ ${bindir:=.}/energy-ptask ${platfdir:=.}/energy_platform.xml --energy "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ ${bindir:=.}/energy-exec-ptask-c ${platfdir:=.}/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) We can do the same with a timeout of one second enabled. diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index e7b005467c..a1f800bc73 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -2,7 +2,7 @@ foreach(x cloud-two-tasks get_sender process-lifetime - energy-ptask platform-properties + platform-properties io-file task-priority trace_integration) @@ -72,7 +72,6 @@ if(enable_msg) get_sender task_destroy_cancel task_listen_from task_progress process-lifetime - energy-ptask io-file platform-properties task-priority diff --git a/teshsuite/msg/energy-ptask/energy-ptask.c b/teshsuite/msg/energy-ptask/energy-ptask.c deleted file mode 100644 index c1bed6c9be..0000000000 --- a/teshsuite/msg/energy-ptask/energy-ptask.c +++ /dev/null @@ -1,118 +0,0 @@ -/* Copyright (c) 2007-2020. 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 "simgrid/msg.h" - -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); - -/** @addtogroup MSG_examples - * - * - energy-ptask/energy-ptask.c: Demonstrates the use of @ref MSG_parallel_task_create, to create special - * tasks that run on several hosts at the same time. The resulting simulations are very close to what can be - * achieved in @ref SD_API, but still allows one to use the other features of MSG (it'd be cool to be able to mix - * interfaces, but it's not possible ATM). - */ - -static int runner(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) -{ - /* Retrieve the list of all hosts as an array of hosts */ - int host_count = MSG_get_host_number(); - msg_host_t* hosts = xbt_dynar_to_array(MSG_hosts_as_dynar()); - - 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 = xbt_new0(double, host_count); - double* communication_amounts = xbt_new0(double, host_count* host_count); - - for (int i = 0; i < host_count; i++) - computation_amounts[i] = 1e9; // 1 Gflop - - for (int i = 0; i < host_count; i++) - for (int j = i + 1; j < host_count; j++) - communication_amounts[i * host_count + j] = 1e7; // 10 MB - - msg_task_t ptask = - MSG_parallel_task_create("parallel task", host_count, hosts, computation_amounts, communication_amounts, NULL); - MSG_parallel_task_execute(ptask); - MSG_task_destroy(ptask); - xbt_free(communication_amounts); - xbt_free(computation_amounts); - - XBT_INFO("We can do the same with a timeout of one second enabled."); - computation_amounts = xbt_new0(double, host_count); - communication_amounts = xbt_new0(double, host_count* host_count); - for (int i = 0; i < host_count; i++) - computation_amounts[i] = 1e9; // 1 Gflop - for (int i = 0; i < host_count; i++) - for (int j = i + 1; j < host_count; j++) - communication_amounts[i * host_count + j] = 1e7; // 10 MB - ptask = - MSG_parallel_task_create("parallel task", host_count, hosts, computation_amounts, communication_amounts, NULL); - msg_error_t errcode = MSG_parallel_task_execute_with_timeout(ptask, 1 /* timeout (in seconds)*/); - xbt_assert(errcode == MSG_TIMEOUT, "Woops, this did not timeout as expected... Please report that bug."); - MSG_task_destroy(ptask); - xbt_free(communication_amounts); - xbt_free(computation_amounts); - - XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)"); - computation_amounts = xbt_new0(double, host_count); - for (int i = 0; i < host_count; i++) - computation_amounts[i] = 1e9; // 1 Gflop - ptask = MSG_parallel_task_create("parallel exec", host_count, hosts, computation_amounts, NULL /* no comm */, NULL); - MSG_parallel_task_execute(ptask); - MSG_task_destroy(ptask); - xbt_free(computation_amounts); - - XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)"); - computation_amounts = xbt_new0(double, host_count); - communication_amounts = xbt_new0(double, host_count* host_count); /* memset to 0 by xbt_new0 */ - ptask = - MSG_parallel_task_create("parallel sync", host_count, hosts, computation_amounts, communication_amounts, NULL); - MSG_parallel_task_execute(ptask); - MSG_task_destroy(ptask); - xbt_free(communication_amounts); - xbt_free(computation_amounts); - - XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", MSG_host_get_name(hosts[1])); - computation_amounts = xbt_new0(double, 1); - computation_amounts[0] = 1e9; // 1 Gflop - msg_host_t* remote = xbt_new(msg_host_t, 1); - remote[0] = hosts[1]; - ptask = MSG_parallel_task_create("remote exec", 1, remote, computation_amounts, NULL /* no comm */, NULL); - MSG_parallel_task_execute(ptask); - MSG_task_destroy(ptask); - xbt_free(remote); - xbt_free(computation_amounts); - - XBT_INFO("Goodbye now!"); - xbt_free(hosts); - return 0; -} - -int main(int argc, char* argv[]) -{ - MSG_init(&argc, argv); - MSG_config("host/model", "ptask_L07"); - - 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(); - - MSG_create_environment(argv[1]); - - /* Pick a process, no matter which, from the platform file */ - xbt_dynar_t all_hosts = MSG_hosts_as_dynar(); - msg_host_t first_host = xbt_dynar_getfirst_as(all_hosts, msg_host_t); - xbt_dynar_free(&all_hosts); - - MSG_process_create("test", runner, NULL, first_host); - msg_error_t res = MSG_main(); - XBT_INFO("Simulation done."); - - return res != MSG_OK; -} -- 2.20.1