From 289ba0381fd84fa42fd80455302814be2e2477be Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 6 Mar 2020 09:50:18 +0100 Subject: [PATCH] add C version of actor-stacksize example --- MANIFEST.in | 2 + examples/c/CMakeLists.txt | 8 +-- examples/c/actor-stacksize/actor-stacksize.c | 51 +++++++++++++++++++ .../c/actor-stacksize/actor-stacksize.tesh | 22 ++++++++ 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 examples/c/actor-stacksize/actor-stacksize.c create mode 100644 examples/c/actor-stacksize/actor-stacksize.tesh diff --git a/MANIFEST.in b/MANIFEST.in index 12638624ef..48b0ebc703 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -32,6 +32,8 @@ include examples/c/actor-lifetime/actor-lifetime.tesh include examples/c/actor-lifetime/actor-lifetime_d.xml include examples/c/actor-migrate/actor-migrate.c include examples/c/actor-migrate/actor-migrate.tesh +include examples/c/actor-stacksize/actor-stacksize.c +include examples/c/actor-stacksize/actor-stacksize.tesh include examples/c/actor-suspend/actor-suspend.c include examples/c/actor-suspend/actor-suspend.tesh include examples/c/actor-yield/actor-yield.c diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 48e8a61764..173b87caf9 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -2,8 +2,8 @@ ###################################################################### foreach(x - actor-create actor-daemon actor-exiting actor-join actor-kill actor-lifetime actor-migrate actor-suspend - actor-yield + actor-create actor-daemon actor-exiting actor-join actor-kill actor-lifetime actor-migrate actor-stacksize + actor-suspend actor-yield app-pingpong app-token-ring async-wait async-waitall async-waitany cloud-capping cloud-migration cloud-simple @@ -57,8 +57,8 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/actor-cr PARENT_SCOPE) foreach(x - actor-create actor-daemon actor-exiting actor-join actor-kill actor-lifetime actor-migrate actor-suspend - actor-yield + actor-create actor-daemon actor-exiting actor-join actor-kill actor-lifetime actor-migrate actor-stacksize + actor-suspend actor-yield app-chainsend app-pingpong app-token-ring async-wait async-waitall async-waitany cloud-capping cloud-migration cloud-simple diff --git a/examples/c/actor-stacksize/actor-stacksize.c b/examples/c/actor-stacksize/actor-stacksize.c new file mode 100644 index 0000000000..8155733a16 --- /dev/null +++ b/examples/c/actor-stacksize/actor-stacksize.c @@ -0,0 +1,51 @@ +/* Copyright (c) 2010-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. */ + +/* This code tests that we can change the stack-size between the actors creation. */ + +#include "simgrid/actor.h" +#include "simgrid/engine.h" +#include "simgrid/host.h" + +#include "xbt/config.h" +#include "xbt/log.h" + +XBT_LOG_NEW_DEFAULT_CATEGORY(actor_stacksize, "Messages specific for this example"); + +static void actor(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) +{ + XBT_INFO("Hello"); +} + +int main(int argc, char* argv[]) +{ + simgrid_init(&argc, argv); + simgrid_load_platform(argv[1]); + + // If you don't specify anything, you get the default size (8Mb) or the one passed on the command line + sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL); + + // You can use sg_cfg_set_int(key, value) to pass a size that will be parsed. That value will be used for any + // subsequent actors + sg_cfg_set_int("contexts/stack-size", 16384); + sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL); + sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL); + + sg_cfg_set_int("contexts/stack-size", 32 * 1024); + sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL); + sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL); + + // Or you can use set_stacksize() before starting the actor to modify only this one + sg_actor_t a = sg_actor_init("actor", sg_host_by_name("Tremblay")); + sg_actor_set_stacksize(a, 64 * 1024); + sg_actor_start(a, actor, 0, NULL); + + sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL); + + simgrid_run(); + XBT_INFO("Simulation time %g", simgrid_get_clock()); + + return 0; +} diff --git a/examples/c/actor-stacksize/actor-stacksize.tesh b/examples/c/actor-stacksize/actor-stacksize.tesh new file mode 100644 index 0000000000..c56a0dcc06 --- /dev/null +++ b/examples/c/actor-stacksize/actor-stacksize.tesh @@ -0,0 +1,22 @@ + +! ignore .*Using Boost contexts. Welcome to the 21th century. +! ignore .*Activating SYSV context factory +! ignore .*Using raw contexts. Because the glibc is just not good enough for us. + +$ ${bindir:=.}/actor-stacksize-c --log=simix_context.thresh:verbose --log=no_loc ${platfdir}/small_platform.xml +> [::(0) 0.000000] [simix_context/VERBOSE] Creating a context of stack 8Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 8Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 16Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 16Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 32Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 32Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 64Mb +> [0.000000] [simix_context/VERBOSE] Creating a context of stack 32Mb +> [Tremblay:actor:(1) 0.000000] [actor_stacksize/INFO] Hello +> [Tremblay:actor:(2) 0.000000] [actor_stacksize/INFO] Hello +> [Tremblay:actor:(3) 0.000000] [actor_stacksize/INFO] Hello +> [Tremblay:actor:(4) 0.000000] [actor_stacksize/INFO] Hello +> [Tremblay:actor:(5) 0.000000] [actor_stacksize/INFO] Hello +> [Tremblay:actor:(6) 0.000000] [actor_stacksize/INFO] Hello +> [Tremblay:actor:(7) 0.000000] [actor_stacksize/INFO] Hello +> [0.000000] [actor_stacksize/INFO] Simulation time 0 -- 2.20.1