From c3277aeaa7731338d044b6e5fea82b6bb01f7703 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Tue, 22 Oct 2019 16:48:12 +0200
Subject: [PATCH] Changed the name of the time-step limiter policy. Added a
 time-step synchronization policy.

---
 examples/main.c        | 14 ++++++++++----
 src/cell.c             |  8 ++++----
 src/engine.c           |  5 +++--
 src/engine.h           |  5 +++--
 src/engine_maketasks.c |  6 +++---
 src/engine_marktasks.c |  2 +-
 src/space.c            |  2 +-
 src/timeline.h         |  1 -
 8 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index b0e7ed8450..2b7861b1dd 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -163,7 +163,8 @@ int main(int argc, char *argv[]) {
   int with_star_formation = 0;
   int with_feedback = 0;
   int with_black_holes = 0;
-  int with_limiter = 0;
+  int with_timestep_limiter = 0;
+  int with_timestep_sync = 0;
   int with_fp_exceptions = 0;
   int with_drift_all = 0;
   int with_mpole_reconstruction = 0;
@@ -219,7 +220,9 @@ int main(int argc, char *argv[]) {
           NULL, 0, 0),
       OPT_BOOLEAN('x', "velociraptor", &with_structure_finding,
                   "Run with structure finding.", NULL, 0, 0),
-      OPT_BOOLEAN(0, "limiter", &with_limiter, "Run with time-step limiter.",
+      OPT_BOOLEAN(0, "limiter", &with_timestep_limiter,
+                  "Run with time-step limiter.", NULL, 0, 0),
+      OPT_BOOLEAN(0, "sync", &with_timestep_sync, "Run with time-step sync.",
                   NULL, 0, 0),
 
       OPT_GROUP("  Control options:\n"),
@@ -555,7 +558,8 @@ int main(int argc, char *argv[]) {
 #ifdef WITH_MPI
   if (with_mpole_reconstruction && nr_nodes > 1)
     error("Cannot reconstruct m-poles every step over MPI (yet).");
-  if (with_limiter) error("Can't run with time-step limiter over MPI (yet)");
+  if (with_timestep_limiter)
+    error("Can't run with time-step limiter over MPI (yet)");
 #ifdef WITH_LOGGER
   error("Can't run with the particle logger over MPI (yet)");
 #endif
@@ -1105,7 +1109,9 @@ int main(int argc, char *argv[]) {
       engine_policies |= engine_policy_external_gravity;
     if (with_cosmology) engine_policies |= engine_policy_cosmology;
     if (with_temperature) engine_policies |= engine_policy_temperature;
-    if (with_limiter) engine_policies |= engine_policy_limiter;
+    if (with_timestep_limiter)
+      engine_policies |= engine_policy_timestep_limiter;
+    if (with_timestep_sync) engine_policies |= engine_policy_timestep_sync;
     if (with_cooling) engine_policies |= engine_policy_cooling;
     if (with_stars) engine_policies |= engine_policy_stars;
     if (with_star_formation) engine_policies |= engine_policy_star_formation;
diff --git a/src/cell.c b/src/cell.c
index b8c2e9132c..551872489a 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -2915,7 +2915,7 @@ void cell_activate_stars_sorts(struct cell *c, int sid, struct scheduler *s) {
 void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
                                        struct scheduler *s) {
   const struct engine *e = s->space->e;
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
 
   /* Store the current dx_max and h_max values. */
   ci->hydro.dx_max_part_old = ci->hydro.dx_max_part;
@@ -3011,7 +3011,7 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
                                        struct scheduler *s,
                                        const int with_star_formation) {
   const struct engine *e = s->space->e;
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
 
   /* Store the current dx_max and h_max values. */
   ci->stars.dx_max_part_old = ci->stars.dx_max_part;
@@ -3381,7 +3381,7 @@ void cell_activate_subcell_external_grav_tasks(struct cell *ci,
 int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) {
   struct engine *e = s->space->e;
   const int nodeID = e->nodeID;
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
 
 #ifdef WITH_MPI
   const int with_star_formation = e->policy & engine_policy_star_formation;
@@ -3787,7 +3787,7 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s,
                             const int with_star_formation) {
 
   struct engine *e = s->space->e;
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
   const int nodeID = e->nodeID;
   int rebuild = 0;
 
diff --git a/src/engine.c b/src/engine.c
index ab7b4269da..a145133289 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -117,7 +117,8 @@ const char *engine_policy_names[] = {"none",
                                      "feedback",
                                      "black holes",
                                      "fof search",
-                                     "time-step limiter"};
+                                     "time-step limiter",
+                                     "time-step sync"};
 
 /** The rank of the engine as a global variable (for messages). */
 int engine_rank;
@@ -1353,7 +1354,7 @@ int engine_estimate_nr_tasks(const struct engine *e) {
 #endif
 #endif
   }
-  if (e->policy & engine_policy_limiter) {
+  if (e->policy & engine_policy_timestep_limiter) {
     n1 += 18;
     n2 += 1;
   }
diff --git a/src/engine.h b/src/engine.h
index 772f4c5330..65402b49ad 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -79,9 +79,10 @@ enum engine_policy {
   engine_policy_feedback = (1 << 18),
   engine_policy_black_holes = (1 << 19),
   engine_policy_fof = (1 << 20),
-  engine_policy_limiter = (1 << 21)
+  engine_policy_timestep_limiter = (1 << 21),
+  engine_policy_timestep_sync = (1 << 22)
 };
-#define engine_maxpolicy 22
+#define engine_maxpolicy 23
 extern const char *engine_policy_names[engine_maxpolicy + 1];
 
 /**
diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c
index e4ae4d569f..7b4e0107b0 100644
--- a/src/engine_maketasks.c
+++ b/src/engine_maketasks.c
@@ -792,7 +792,7 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
 
   struct scheduler *s = &e->sched;
   const int with_star_formation = (e->policy & engine_policy_star_formation);
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
 
   /* Are we at the top-level? */
   if (c->top == c && c->nodeID == e->nodeID) {
@@ -1023,7 +1023,7 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c,
   const int with_cooling = (e->policy & engine_policy_cooling);
   const int with_star_formation = (e->policy & engine_policy_star_formation);
   const int with_black_holes = (e->policy & engine_policy_black_holes);
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
 
   /* Are we are the level where we create the stars' resort tasks?
    * If the tree is shallow, we need to do this at the super-level if the
@@ -1809,7 +1809,7 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
   struct scheduler *sched = &e->sched;
   const int nodeID = e->nodeID;
   const int with_cooling = (e->policy & engine_policy_cooling);
-  const int with_limiter = (e->policy & engine_policy_limiter);
+  const int with_limiter = (e->policy & engine_policy_timestep_limiter);
   const int with_feedback = (e->policy & engine_policy_feedback);
   const int with_black_holes = (e->policy & engine_policy_black_holes);
 #ifdef EXTRA_HYDRO_LOOP
diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c
index fb6b5cf6f9..307520ad50 100644
--- a/src/engine_marktasks.c
+++ b/src/engine_marktasks.c
@@ -69,7 +69,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
   struct scheduler *s = (struct scheduler *)(((size_t *)extra_data)[2]);
   struct engine *e = (struct engine *)((size_t *)extra_data)[0];
   const int nodeID = e->nodeID;
-  const int with_limiter = e->policy & engine_policy_limiter;
+  const int with_limiter = e->policy & engine_policy_timestep_limiter;
   const int with_star_formation = e->policy & engine_policy_star_formation;
 #ifdef WITH_MPI
   const int with_feedback = e->policy & engine_policy_feedback;
diff --git a/src/space.c b/src/space.c
index 443e67968a..b38b3efff9 100644
--- a/src/space.c
+++ b/src/space.c
@@ -5347,7 +5347,7 @@ void space_check_limiter_mapper(void *map_data, int nr_parts,
   /* Unpack the data */
   struct part *restrict parts = (struct part *)map_data;
   const struct space *s = (struct space *)extra_data;
-  const int with_limiter = (s->e->policy & engine_policy_limiter);
+  const int with_limiter = (s->e->policy & engine_policy_timestep_limiter);
 
   /* Verify that all limited particles have been treated */
   for (int k = 0; k < nr_parts; k++) {
diff --git a/src/timeline.h b/src/timeline.h
index b6136f1d55..0f94321101 100644
--- a/src/timeline.h
+++ b/src/timeline.h
@@ -53,7 +53,6 @@ typedef int8_t timebin_t;
 /* Maximal difference in time-bins between neighbouring particles */
 #define time_bin_neighbour_max_delta_bin 2
 
-
 /**
  * @brief Returns the integer time interval corresponding to a time bin
  *
-- 
GitLab