Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / c / actor-stacksize / actor-stacksize.c
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/actor.h"
9 #include "simgrid/engine.h"
10 #include "simgrid/host.h"
11
12 #include "xbt/config.h"
13 #include "xbt/log.h"
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_stacksize, "Messages specific for this example");
16
17 static void actor(int argc, char* argv[])
18 {
19   XBT_INFO("Hello");
20 }
21
22 int main(int argc, char* argv[])
23 {
24   simgrid_init(&argc, argv);
25   simgrid_load_platform(argv[1]);
26
27   // If you don't specify anything, you get the default size (8Mb) or the one passed on the command line
28   sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL);
29
30   // You can use sg_cfg_set_int(key, value) to pass a size that will be parsed. That value will be used for any
31   // subsequent actors
32   sg_cfg_set_int("contexts/stack-size", 16384);
33   sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL);
34   sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL);
35
36   sg_cfg_set_int("contexts/stack-size", 32 * 1024);
37   sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL);
38   sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL);
39
40   // Or you can use set_stacksize() before starting the actor to modify only this one
41   sg_actor_t a = sg_actor_init("actor", sg_host_by_name("Tremblay"));
42   sg_actor_set_stacksize(a, 64 * 1024);
43   sg_actor_start(a, actor, 0, NULL);
44
45   sg_actor_create("actor", sg_host_by_name("Tremblay"), actor, 0, NULL);
46
47   simgrid_run();
48   XBT_INFO("Simulation time %g", simgrid_get_clock());
49
50   return 0;
51 }