-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute.cpp
52 lines (44 loc) · 1.14 KB
/
compute.cpp
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
52
#include "parameters.h"
#include "simulation.h"
#include <stdio.h>
#include <string.h>
#include <signal.h>
#ifndef TMIN
#define TMIN 0.4
#endif
#ifndef TMAX
#define TMAX 1.8
#endif
#ifndef SEED
#define SEED 0
#endif
//char command='\0';
Simulation sim(DIMENSION, TMIN, TMAX, SEED);
volatile sig_atomic_t abortRun = 0;
void termination_handler(int signum)
{
abortRun=1;
}
void register_termination_handler()
{
struct sigaction new_action, old_action;
new_action.sa_handler = termination_handler;
sigemptyset(&new_action.sa_mask);
sigaction(SIGINT, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN) sigaction(SIGINT, &new_action, NULL);
sigaction(SIGHUP, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN) sigaction(SIGHUP, &new_action, NULL);
sigaction(SIGTERM, NULL, &old_action);
if (old_action.sa_handler != SIG_IGN) sigaction(SIGTERM, &new_action, NULL);
}
int main(int argc, char* argv[])
{
register_termination_handler();
sim.evolve(PRE_ITERATIONS);
printf("---> %i preiterations done.\n", PRE_ITERATIONS);
while(!abortRun) {
sim.evolve(ITERATIONS_PER_SAMPLE);
sim.sample();
}
printf("TERMINATING");
}