File: actor-stacksize.c

package info (click to toggle)
simgrid 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 38,980 kB
  • sloc: cpp: 123,583; ansic: 66,779; python: 8,358; java: 6,406; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,337; perl: 1,436; makefile: 105; lisp: 49; javascript: 7; sed: 6
file content (51 lines) | stat: -rw-r--r-- 1,811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright (c) 2010-2025. 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(int argc, 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;
}