From f626d51a2d88330d770175e039caa6dd0de9bd26 Mon Sep 17 00:00:00 2001 From: Takishipp Date: Mon, 9 Oct 2017 10:47:19 +0200 Subject: [PATCH] convert actor-startkilltime to s4u API --- examples/s4u/CMakeLists.txt | 13 ++-- examples/s4u/README.doc | 7 ++- .../s4u-actor-baseline_d.xml | 8 +++ .../actor-startkilltime/s4u-actor-kill_d.xml | 13 ++++ .../actor-startkilltime/s4u-actor-start_d.xml | 22 +++++++ .../s4u-actor-start_kill_d.xml | 22 +++++++ .../s4u-actor-startkilltime.cpp | 51 +++++++++++++++ .../s4u-actor-startkilltime.tesh | 63 +++++++++++++++++++ 8 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 examples/s4u/actor-startkilltime/s4u-actor-baseline_d.xml create mode 100644 examples/s4u/actor-startkilltime/s4u-actor-kill_d.xml create mode 100644 examples/s4u/actor-startkilltime/s4u-actor-start_d.xml create mode 100644 examples/s4u/actor-startkilltime/s4u-actor-start_kill_d.xml create mode 100644 examples/s4u/actor-startkilltime/s4u-actor-startkilltime.cpp create mode 100644 examples/s4u/actor-startkilltime/s4u-actor-startkilltime.tesh diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 0ee6b1e500..eade5ff501 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -1,7 +1,7 @@ foreach (example actions-comm actions-storage actor-create actor-daemon actor-kill actor-migration actor-suspend app-masterworker app-pingpong app-token-ring - async-wait async-waitany async-waitall + async-wait async-waitany async-waitall actor-startkilltime plugin-hostload io mutex) add_executable (s4u-${example} ${example}/s4u-${example}.cpp) target_link_libraries(s4u-${example} simgrid) @@ -34,7 +34,8 @@ set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany.tesh - ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall.tesh PARENT_SCOPE) + ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall.tesh + ${CMAKE_CURRENT_SOURCE_DIR}/actor-startkilltime/s4u-actor-startkilltime.tesh PARENT_SCOPE) set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u-actions-storage_d.xml @@ -44,7 +45,11 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml - ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml PARENT_SCOPE) + ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml + ${CMAKE_CURRENT_SOURCE_DIR}/actor-startkilltime/s4u-actor-baseline_d.xml + ${CMAKE_CURRENT_SOURCE_DIR}/actor-startkilltime/s4u-actor-kill_d.xml + ${CMAKE_CURRENT_SOURCE_DIR}/actor-startkilltime/s4u-actor-start_d.xml + ${CMAKE_CURRENT_SOURCE_DIR}/actor-startkilltime/s4u-actor-star_kill_d.xml PARENT_SCOPE) set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p0.txt ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm-split-p1.txt ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm.txt @@ -54,7 +59,7 @@ set(txt_files ${txt_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a foreach(example actions-comm actions-storage actor-create actor-daemon actor-kill actor-migration actor-suspend app-bittorrent app-masterworker app-pingpong app-token-ring - async-wait async-waitall async-waitany + async-wait async-waitall async-waitany actor-startkilltime dht-chord 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/README.doc b/examples/s4u/README.doc index 97be9a1597..03a5508cb7 100644 --- a/examples/s4u/README.doc +++ b/examples/s4u/README.doc @@ -38,7 +38,7 @@ documentation, but it should remain readable directly. Another good old example, where one Master process has a bunch of task to dispatch to a set of several Worker processes. -@section msg_ex_async Asynchronous communications +@section s4u_ex_async Asynchronous communications - Basic asynchronous communications. @ref examples/s4u/async-wait/s4u-async-wait.cpp \n @@ -79,6 +79,11 @@ documentation, but it should remain readable directly. @ref examples/s4u/actor-kill/s4u-actor-kill.cpp \n Actors can forcefully stop other actors with the @ref kill method. + - Controling the actor life cycle. + @ref examples/s4u/actor-startkilltime/s4u-actor-startkilltime.cpp \n + You can specify a start time and a kill time in the deployment + file. See all *_d.xml files in this directory. + - Migrating Actors. @ref examples/s4u/actor-migration/s4u-actor-migration.cpp \n Actors can move or be moved from a host to another with the @ref migrate method. diff --git a/examples/s4u/actor-startkilltime/s4u-actor-baseline_d.xml b/examples/s4u/actor-startkilltime/s4u-actor-baseline_d.xml new file mode 100644 index 0000000000..e24ccedf13 --- /dev/null +++ b/examples/s4u/actor-startkilltime/s4u-actor-baseline_d.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/examples/s4u/actor-startkilltime/s4u-actor-kill_d.xml b/examples/s4u/actor-startkilltime/s4u-actor-kill_d.xml new file mode 100644 index 0000000000..6d7d312410 --- /dev/null +++ b/examples/s4u/actor-startkilltime/s4u-actor-kill_d.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/examples/s4u/actor-startkilltime/s4u-actor-start_d.xml b/examples/s4u/actor-startkilltime/s4u-actor-start_d.xml new file mode 100644 index 0000000000..3d6934b178 --- /dev/null +++ b/examples/s4u/actor-startkilltime/s4u-actor-start_d.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/s4u/actor-startkilltime/s4u-actor-start_kill_d.xml b/examples/s4u/actor-startkilltime/s4u-actor-start_kill_d.xml new file mode 100644 index 0000000000..7292ca2fbb --- /dev/null +++ b/examples/s4u/actor-startkilltime/s4u-actor-start_kill_d.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/s4u/actor-startkilltime/s4u-actor-startkilltime.cpp b/examples/s4u/actor-startkilltime/s4u-actor-startkilltime.cpp new file mode 100644 index 0000000000..f8ba252b1b --- /dev/null +++ b/examples/s4u/actor-startkilltime/s4u-actor-startkilltime.cpp @@ -0,0 +1,51 @@ +/* Copyright (c) 2007-2016. 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 + #include + +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); + +/* Executed on process termination*/ +static int my_onexit(void* ignored1, void *ignored2) { + XBT_INFO("Exiting now (done sleeping or got killed)."); /* - Just display an informative message (see tesh file) */ + return 0; +} + +/* Just sleep until termination */ +class sleeper { + +public: + explicit sleeper(std::vector args) +{ + XBT_INFO("Hello! I go to sleep."); + simcall_process_on_exit(SIMIX_process_self(), my_onexit, NULL); + + simgrid::s4u::this_actor::sleep_for(std::stoi(args[1])); + +} +void operator()() +{ + XBT_INFO("Done sleeping."); +} +}; + +int main(int argc, char *argv[]) +{ + simgrid::s4u::Engine e(&argc, argv); + + xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" + "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); + + e.loadPlatform(argv[1]); /* - Load the platform description */ + e.registerFunction("sleeper"); + e.loadDeployment(argv[2]); /* - Deploy the sleeper processes with explicit start/kill times */ + + e.run(); /* - Run the simulation */ + + XBT_INFO("Simulation time %g", SIMIX_get_clock()); + return 0; +} diff --git a/examples/s4u/actor-startkilltime/s4u-actor-startkilltime.tesh b/examples/s4u/actor-startkilltime/s4u-actor-startkilltime.tesh new file mode 100644 index 0000000000..f8e7b5c58f --- /dev/null +++ b/examples/s4u/actor-startkilltime/s4u-actor-startkilltime.tesh @@ -0,0 +1,63 @@ +#! ./tesh + +p Test0 actor without time + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-startkilltime ${srcdir:=.}/cluster.xml ${srcdir:=.}/../s4u/actor-startkilltime/s4u-actor-baseline_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sleeper@node-0.acme.org) Hello! I go to sleep. +> [ 10.000000] (1:sleeper@node-0.acme.org) Done sleeping. +> [ 10.000000] (1:sleeper@node-0.acme.org) Exiting now (done sleeping or got killed). +> [ 10.000000] (0:maestro@) Simulation time 10 + +p Test1 actor with start time + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-startkilltime ${srcdir:=.}/cluster.xml ${srcdir:=.}/../s4u/actor-startkilltime/s4u-actor-start_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sleeper@node-0.acme.org) Hello! I go to sleep. +> [ 1.000000] (2:sleeper@node-1.acme.org) Hello! I go to sleep. +> [ 2.000000] (3:sleeper@node-2.acme.org) Hello! I go to sleep. +> [ 3.000000] (4:sleeper@node-3.acme.org) Hello! I go to sleep. +> [ 4.000000] (5:sleeper@node-4.acme.org) Hello! I go to sleep. +> [ 5.000000] (6:sleeper@node-5.acme.org) Hello! I go to sleep. +> [ 10.000000] (1:sleeper@node-0.acme.org) Done sleeping. +> [ 10.000000] (1:sleeper@node-0.acme.org) Exiting now (done sleeping or got killed). +> [ 11.000000] (2:sleeper@node-1.acme.org) Done sleeping. +> [ 11.000000] (2:sleeper@node-1.acme.org) Exiting now (done sleeping or got killed). +> [ 12.000000] (3:sleeper@node-2.acme.org) Done sleeping. +> [ 12.000000] (3:sleeper@node-2.acme.org) Exiting now (done sleeping or got killed). +> [ 13.000000] (4:sleeper@node-3.acme.org) Done sleeping. +> [ 13.000000] (4:sleeper@node-3.acme.org) Exiting now (done sleeping or got killed). +> [ 14.000000] (5:sleeper@node-4.acme.org) Done sleeping. +> [ 14.000000] (5:sleeper@node-4.acme.org) Exiting now (done sleeping or got killed). +> [ 15.000000] (6:sleeper@node-5.acme.org) Done sleeping. +> [ 15.000000] (6:sleeper@node-5.acme.org) Exiting now (done sleeping or got killed). +> [ 15.000000] (0:maestro@) Simulation time 15 + +p Test1 actor with kill time + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-startkilltime ${srcdir:=.}/cluster.xml ${srcdir:=.}/../s4u/actor-startkilltime/s4u-actor-kill_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sleeper@node-1.acme.org) Hello! I go to sleep. +> [ 0.000000] (2:sleeper@node-2.acme.org) Hello! I go to sleep. +> [ 0.000000] (3:sleeper@node-3.acme.org) Hello! I go to sleep. +> [ 6.000000] (1:sleeper@node-1.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (2:sleeper@node-2.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (3:sleeper@node-3.acme.org) Done sleeping. +> [ 6.000000] (3:sleeper@node-3.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (0:maestro@) Simulation time 6 + +p Test2 actor with start and kill times + +$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-startkilltime ${srcdir:=.}/cluster.xml ${srcdir:=.}/../s4u/actor-startkilltime/s4u-actor-start_kill_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:sleeper@node-0.acme.org) Hello! I go to sleep. +> [ 1.000000] (2:sleeper@node-1.acme.org) Hello! I go to sleep. +> [ 2.000000] (3:sleeper@node-2.acme.org) Hello! I go to sleep. +> [ 3.000000] (4:sleeper@node-3.acme.org) Hello! I go to sleep. +> [ 4.000000] (5:sleeper@node-4.acme.org) Hello! I go to sleep. +> [ 5.000000] (1:sleeper@node-0.acme.org) Exiting now (done sleeping or got killed). +> [ 5.000000] (6:sleeper@node-5.acme.org) Hello! I go to sleep. +> [ 6.000000] (2:sleeper@node-1.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (3:sleeper@node-2.acme.org) Done sleeping. +> [ 6.000000] (3:sleeper@node-2.acme.org) Exiting now (done sleeping or got killed). +> [ 7.000000] (4:sleeper@node-3.acme.org) Done sleeping. +> [ 7.000000] (4:sleeper@node-3.acme.org) Exiting now (done sleeping or got killed). +> [ 9.000000] (5:sleeper@node-4.acme.org) Exiting now (done sleeping or got killed). +> [ 10.000000] (6:sleeper@node-5.acme.org) Exiting now (done sleeping or got killed). +> [ 10.000000] (0:maestro@) Simulation time 10 -- 2.20.1