diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 36da7a1e9971e03124927d0dbb7fe0ca52772eb1..046ad0da52e772d406220573d4b09213c31c0a52 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -78,6 +78,7 @@ InitialConditions: # Parameters controlling restarts Restarts: enable: 1 # (Optional) whether to enable dumping restarts at fixed intervals. + save: 1 # (Optional) whether to save copies of the previous set of restart files (named .prev) onexit: 0 # (Optional) whether to dump restarts on exit (*needs enable*) subdir: restart # (Optional) name of subdirectory for restart files. basename: swift # (Optional) prefix used in naming restart files. diff --git a/src/engine.c b/src/engine.c index 7967bdf01aa726655326998eb020a0ed0492ba31..9349aa7e4e9a32147b8a6c9790c77709091791d8 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5569,6 +5569,9 @@ void engine_config(int restart, struct engine *e, /* Whether restarts are enabled. Yes by default. Can be changed on restart. */ e->restart_dump = parser_get_opt_param_int(params, "Restarts:enable", 1); + /* Whether to save backup copies of the previous restart files. */ + e->restart_save = parser_get_opt_param_int(params, "Restarts:save", 1); + /* Whether restarts should be dumped on exit. Not by default. Can be changed * on restart. */ e->restart_onexit = parser_get_opt_param_int(params, "Restarts:onexit", 0); diff --git a/src/engine.h b/src/engine.h index 25d82a5705aa78757df4bf6b2c880b71f111375b..67ca66c12fc56b55fd25091b24635c837c567f92 100644 --- a/src/engine.h +++ b/src/engine.h @@ -296,6 +296,9 @@ struct engine { /* Whether to dump restart files. */ int restart_dump; + /* Whether to save previous generation of restart files. */ + int restart_save; + /* Whether to dump restart files after the last step. */ int restart_onexit; diff --git a/src/restart.c b/src/restart.c index 0d248adda30bf2e4cd9eedb5f9159b1b1e5137ed..881250fd237a3ce5b0bb3b549939f335660cd2a6 100644 --- a/src/restart.c +++ b/src/restart.c @@ -128,8 +128,8 @@ void restart_locate_free(int nfiles, char **files) { */ void restart_write(struct engine *e, const char *filename) { - /* Backup the existing restart file. XXX configure this. */ - restart_save_previous(filename); + /* Save a backup the existing restart file, if requested. */ + if (e->restart_save) restart_save_previous(filename); FILE *stream = fopen(filename, "w"); if (stream == NULL) @@ -289,7 +289,7 @@ int restart_stop_now(const char *dir, int cleanup) { /** * @brief check if a file with the given name exists and rename to - * <filename>.prev. Used to move old restart files before overwriting. + * {filename}.prev. Used to move old restart files before overwriting. * * Does nothing if the file does not exist. *