From d6086f59ea8f9accd20b0e9f0a26b491a222a7eb Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Fri, 9 Aug 2019 14:20:42 +0200
Subject: [PATCH] Allow user to overwrite Scheduler parameters when restarting.

---
 src/engine.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/space.c  | 42 ------------------------------------------
 2 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/src/engine.c b/src/engine.c
index 33f94e9c16..7480c1ba71 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -130,6 +130,9 @@ int engine_rank;
 /** The current step of the engine as a global variable (for messages). */
 int engine_current_step;
 
+extern int engine_max_parts_per_ghost;
+extern int engine_max_sparts_per_ghost;
+
 /**
  * @brief Data collected from the cells at the end of a time-step
  */
@@ -5628,6 +5631,48 @@ void engine_config(int restart, int fof, struct engine *e,
   e->sched.mpi_message_limit =
       parser_get_opt_param_int(params, "Scheduler:mpi_message_limit", 4) * 1024;
 
+  /* Get the constants for the scheduler */
+  space_maxsize = parser_get_opt_param_int(params, "Scheduler:cell_max_size",
+                                           space_maxsize_default);
+  space_subsize_pair_hydro =
+      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_hydro",
+                               space_subsize_pair_hydro_default);
+  space_subsize_self_hydro =
+      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_hydro",
+                               space_subsize_self_hydro_default);
+  space_subsize_pair_stars =
+      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_stars",
+                               space_subsize_pair_stars_default);
+  space_subsize_self_stars =
+      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_stars",
+                               space_subsize_self_stars_default);
+  space_subsize_pair_grav =
+      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_grav",
+                               space_subsize_pair_grav_default);
+  space_subsize_self_grav =
+      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_grav",
+                               space_subsize_self_grav_default);
+  space_splitsize = parser_get_opt_param_int(
+      params, "Scheduler:cell_split_size", space_splitsize_default);
+  space_subdepth_diff_grav =
+      parser_get_opt_param_int(params, "Scheduler:cell_subdepth_diff_grav",
+                               space_subdepth_diff_grav_default);
+  space_extra_parts = parser_get_opt_param_int(
+      params, "Scheduler:cell_extra_parts", space_extra_parts_default);
+  space_extra_sparts = parser_get_opt_param_int(
+      params, "Scheduler:cell_extra_sparts", space_extra_sparts_default);
+  space_extra_gparts = parser_get_opt_param_int(
+      params, "Scheduler:cell_extra_gparts", space_extra_gparts_default);
+  space_extra_bparts = parser_get_opt_param_int(
+      params, "Scheduler:cell_extra_bparts", space_extra_bparts_default);
+
+  engine_max_parts_per_ghost =
+      parser_get_opt_param_int(params, "Scheduler:engine_max_parts_per_ghost",
+                               engine_max_parts_per_ghost_default);
+  engine_max_sparts_per_ghost =
+      parser_get_opt_param_int(params, "Scheduler:engine_max_sparts_per_ghost",
+                               engine_max_sparts_per_ghost_default);
+
   /* Allocate and init the threads. */
   if (swift_memalign("runners", (void **)&e->runners, SWIFT_CACHE_ALIGNMENT,
                      e->nr_threads * sizeof(struct runner)) != 0)
diff --git a/src/space.c b/src/space.c
index 250af5efaf..830081b276 100644
--- a/src/space.c
+++ b/src/space.c
@@ -4633,48 +4633,6 @@ void space_init(struct space *s, struct swift_params *params,
         "least %d",
         maxtcells, needtcells);
 
-  /* Get the constants for the scheduler */
-  space_maxsize = parser_get_opt_param_int(params, "Scheduler:cell_max_size",
-                                           space_maxsize_default);
-  space_subsize_pair_hydro =
-      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_hydro",
-                               space_subsize_pair_hydro_default);
-  space_subsize_self_hydro =
-      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_hydro",
-                               space_subsize_self_hydro_default);
-  space_subsize_pair_stars =
-      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_stars",
-                               space_subsize_pair_stars_default);
-  space_subsize_self_stars =
-      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_stars",
-                               space_subsize_self_stars_default);
-  space_subsize_pair_grav =
-      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_pair_grav",
-                               space_subsize_pair_grav_default);
-  space_subsize_self_grav =
-      parser_get_opt_param_int(params, "Scheduler:cell_sub_size_self_grav",
-                               space_subsize_self_grav_default);
-  space_splitsize = parser_get_opt_param_int(
-      params, "Scheduler:cell_split_size", space_splitsize_default);
-  space_subdepth_diff_grav =
-      parser_get_opt_param_int(params, "Scheduler:cell_subdepth_diff_grav",
-                               space_subdepth_diff_grav_default);
-  space_extra_parts = parser_get_opt_param_int(
-      params, "Scheduler:cell_extra_parts", space_extra_parts_default);
-  space_extra_sparts = parser_get_opt_param_int(
-      params, "Scheduler:cell_extra_sparts", space_extra_sparts_default);
-  space_extra_gparts = parser_get_opt_param_int(
-      params, "Scheduler:cell_extra_gparts", space_extra_gparts_default);
-  space_extra_bparts = parser_get_opt_param_int(
-      params, "Scheduler:cell_extra_bparts", space_extra_bparts_default);
-
-  engine_max_parts_per_ghost =
-      parser_get_opt_param_int(params, "Scheduler:engine_max_parts_per_ghost",
-                               engine_max_parts_per_ghost_default);
-  engine_max_sparts_per_ghost =
-      parser_get_opt_param_int(params, "Scheduler:engine_max_sparts_per_ghost",
-                               engine_max_sparts_per_ghost_default);
-
   if (verbose) {
     message("max_size set to %d split_size set to %d", space_maxsize,
             space_splitsize);
-- 
GitLab