Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0ae6ffadaa449ea4e5dcd650c0067982943ccf2e
[simgrid.git] / teshsuite / simix / stack_overflow / stack_overflow.c
1 /* stack_overflow -- simple program generating a stack overflow          */
2
3 /* Copyright (c) 2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "simgrid/platf.h"
10 #include "simgrid/simix.h"
11 #include "surf/surfxml_parse.h"
12 #include "xbt/log.h"
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "my log messages");
15
16 static unsigned collatz(unsigned c0, unsigned n)
17 {
18   unsigned x;
19   if (n == 0) {
20     x = c0;
21   } else {
22     x = collatz(c0, n - 1);
23     if (x % 2 == 0)
24       x = x / 2;
25     else
26       x = 3 * x + 1;
27   }
28   return x;
29 }
30
31 static int master(int argc, char *argv[])
32 {
33   XBT_INFO("Launching our nice bugged recursive function...");
34   unsigned i = 1;
35   do {
36     i *= 2;
37     unsigned res = collatz(i, i);
38     XBT_VERB("collatz(%u, %u) returned %u", i, i, res);
39   } while (i <= 0x80000000u);
40   return 0;
41 }
42
43 int main(int argc, char *argv[])
44 {
45   SIMIX_global_init(&argc, argv);
46
47   if (argc != 2) {
48     printf("Usage: %s platform_and_deployment.xml\n", argv[0]);
49     exit(EXIT_FAILURE);
50   }
51
52   SIMIX_function_register("master", master);
53   SIMIX_create_environment(argv[1]);
54   SIMIX_launch_application(argv[1]);
55   SIMIX_run();
56
57   return 0;
58 }