Basilisk CFD
Adaptive Cartesian mesh PDE framework
Loading...
Searching...
No Matches
maxruntime.h
Go to the documentation of this file.
1/** @file maxruntime.h
2 */
3/**
4# Controlling the maximum runtime
5
6On parallel machines, runs are often not allowed to exceed a maximum
7duration (typically 24 hours). To avoid having the job terminated
8brutally by the queueing system, this module adds the option to exit
9gracefully after a given runtime.
10
11The maximum runtime is given as a command-line argument (typically in
12the running script given to the queueing system) using the standard
13format H:M:S (hours, minutes and seconds). This should match the
14wall-clock time requested from the queueing system.
15
16When this time minus 5 minutes (to allow for clean termination) is
17exceeded the state of the simulation is dumped in the "restart" file
18and the program terminates. */
19
20static double _maxruntime = HUGE;
21
22/** @brief Event: runtime (i += 10) */
23void event_runtime (void) {
25 if (perf.t >= _maxruntime - 300) { // we allow 5 minutes for termination
26 dump (file = "restart"); // so that we can restart
27 return 1; // exit
28 }
29}
30
31void maxruntime (int * argc, char * argv[])
32{
33 for (int i = 0; i < *argc; i++)
34 if (!strcmp (argv[i], "--maxruntime") || !strcmp (argv[i], "-m")) {
35 if (i + 1 < *argc) {
36 char * s = strtok (argv[i + 1], ":");
37 int n = 0;
38 _maxruntime = 0;
39 do {
41 n++;
42 } while ((s = strtok (NULL, ":")));
43 if (n > 3) {
44 fprintf (ferr, "maxruntime: TIME format must be H:M:S\n");
45 exit (1);
46 }
47 }
48 else {
49 fprintf (ferr, "usage: %s TIME\n", argv[i]);
50 exit (1);
51 }
52 *argc -= 2;
53 for (int j = i; j < *argc; j++)
54 argv[j] = argv[j + 2];
55 }
56}
int x
Definition common.h:76
#define HUGE
Definition common.h:6
define sysmalloc malloc define syscalloc calloc define sysrealloc realloc define sysfree free define systrdup strdup define file
Definition config.h:120
else return n
Definition curvature.h:101
scalar s
Definition embed-tree.h:56
*cs[i, 0, 0] a *[i -1, 0, 0] j
Definition embed.h:88
scalar int i
Definition embed.h:74
void maxruntime(int *argc, char *argv[])
Definition maxruntime.h:31
static double _maxruntime
Definition maxruntime.h:20
void event_runtime(void)
Event: runtime (i += 10)
Definition maxruntime.h:23
struct @16 perf
Performance statistics are stored in this structure.