Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics: define and use the sg4 namespace as a shortcut to simgrid::s4u
[simgrid.git] / examples / s4u / actor-stacksize / s4u-actor-stacksize.cpp
1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 /* This code tests that we can change the stack-size between the actors creation. */
7
8 #include <simgrid/s4u.hpp>
9 namespace sg4 = simgrid::s4u;
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
12
13 static void actor()
14 {
15   XBT_INFO("Hello");
16 }
17
18 int main(int argc, char* argv[])
19 {
20   sg4::Engine e(&argc, argv);
21   e.load_platform(argv[1]);
22
23   // If you don't specify anything, you get the default size (8Mb) or the one passed on the command line
24   sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor);
25
26   // You can use set_config(string) to pass a size that will be parsed. That value will be used for any subsequent
27   // actors
28   sg4::Engine::set_config("contexts/stack-size:16384");
29   sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor);
30   sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor);
31
32   // You can use set_config(key, value) for the same effect.
33   sg4::Engine::set_config("contexts/stack-size", 32 * 1024);
34   sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor);
35   sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor);
36
37   // Or you can use set_stacksize() before starting the actor to modify only this one
38   sg4::Actor::init("actor", sg4::Host::by_name("Tremblay"))->set_stacksize(64 * 1024)->start(actor);
39   sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor);
40
41   e.run();
42   XBT_INFO("Simulation time %g", e.get_clock());
43
44   return 0;
45 }