From a5bbe13316263eaae4611145de96efa7e0097333 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@gmail.com>
Date: Mon, 3 Feb 2025 10:26:13 +0100
Subject: [PATCH] Do not reset the delta times for snapshot triggers upon
 restarting the code

---
 src/engine.h        |  2 +-
 src/engine_config.c |  2 +-
 src/engine_io.c     | 16 ++++++++++------
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/engine.h b/src/engine.h
index 81c6fa0710..df4e8b534c 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -684,7 +684,7 @@ struct engine {
 /* Function prototypes, engine.c. */
 void engine_addlink(struct engine *e, struct link **l, struct task *t);
 void engine_barrier(struct engine *e);
-void engine_compute_next_snapshot_time(struct engine *e);
+void engine_compute_next_snapshot_time(struct engine *e, const int restart);
 void engine_compute_next_stf_time(struct engine *e);
 void engine_compute_next_fof_time(struct engine *e);
 void engine_compute_next_statistics_time(struct engine *e);
diff --git a/src/engine_config.c b/src/engine_config.c
index 74fc0d20d6..c3aa430f9c 100644
--- a/src/engine_config.c
+++ b/src/engine_config.c
@@ -789,7 +789,7 @@ void engine_config(int restart, int fof, struct engine *e,
 #endif
 
     /* Find the time of the first snapshot output */
-    engine_compute_next_snapshot_time(e);
+    engine_compute_next_snapshot_time(e, restart);
 
     /* Find the time of the first statistics output */
     engine_compute_next_statistics_time(e);
diff --git a/src/engine_io.c b/src/engine_io.c
index f8e97d8eee..5b3116998e 100644
--- a/src/engine_io.c
+++ b/src/engine_io.c
@@ -565,7 +565,7 @@ void engine_io(struct engine *e) {
 #endif
 
         /* ... and find the next output time */
-        engine_compute_next_snapshot_time(e);
+        engine_compute_next_snapshot_time(e, /*restart=*/0);
         break;
 
       case output_statistics:
@@ -752,15 +752,19 @@ void engine_set_and_verify_snapshot_triggers(struct engine *e) {
  * @brief Computes the next time (on the time line) for a dump
  *
  * @param e The #engine.
+ * @param restart Are we calling this upon a restart event?
  */
-void engine_compute_next_snapshot_time(struct engine *e) {
+void engine_compute_next_snapshot_time(struct engine *e, const int restart) {
 
   /* Do output_list file case */
   if (e->output_list_snapshots) {
     output_list_read_next_time(e->output_list_snapshots, e, "snapshots",
                                &e->ti_next_snapshot);
 
-    engine_set_and_verify_snapshot_triggers(e);
+    /* Unless we are restarting, check the allowed recording trigger time */
+    if (!restart) engine_set_and_verify_snapshot_triggers(e);
+
+    /* All done in the list case */
     return;
   }
 
@@ -818,8 +822,8 @@ void engine_compute_next_snapshot_time(struct engine *e) {
         message("Next snapshot time set to t=%e.", next_snapshot_time);
     }
 
-    /* Set the recording triggers accordingly for the next output */
-    engine_set_and_verify_snapshot_triggers(e);
+    /* Unless we are restarting, set the recording triggers accordingly for the next output */
+    if (!restart) engine_set_and_verify_snapshot_triggers(e);
   }
 }
 
@@ -1184,7 +1188,7 @@ void engine_init_output_lists(struct engine *e, struct swift_params *params,
     if (e->output_list_snapshots->select_output_on)
       output_list_check_selection(e->output_list_snapshots, output_options);
 
-    engine_compute_next_snapshot_time(e);
+    engine_compute_next_snapshot_time(e, /*restart=*/0);
 
     if (e->policy & engine_policy_cosmology)
       e->a_first_snapshot =
-- 
GitLab