From 73e4beb4449f27b7c17b6c3cdc5fb45612bceafc Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Thu, 1 Mar 2018 11:04:01 +0100
Subject: [PATCH] Print the min and max active time-bin at every time-step

---
 examples/main.c                            |  6 ++---
 examples/plot_scaling_results.py           |  4 ++--
 examples/plot_scaling_results_breakdown.py |  4 ++--
 src/engine.c                               | 28 +++++++++++++---------
 src/engine.h                               |  3 +++
 src/timeline.h                             | 19 +++++++++++++++
 6 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index 40cfca8499..7baf549c6e 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -845,9 +845,9 @@ int main(int argc, char *argv[]) {
 
   /* Legend */
   if (myrank == 0)
-    printf("# %6s %14s %14s %12s %12s %12s %16s [%s] %6s\n", "Step", "Time",
-           "Time-step", "Updates", "g-Updates", "s-Updates", "Wall-clock time",
-           clocks_getunit(), "Props");
+    printf("# %6s %14s %14s %9s %12s %12s %12s %16s [%s] %6s\n", "Step", "Time",
+           "Time-step", "Time-bins", "Updates", "g-Updates", "s-Updates",
+           "Wall-clock time", clocks_getunit(), "Props");
 
   /* File for the timers */
   if (with_verbose_timers) timers_open_file(myrank);
diff --git a/examples/plot_scaling_results.py b/examples/plot_scaling_results.py
index 9e938c720f..552fab9206 100755
--- a/examples/plot_scaling_results.py
+++ b/examples/plot_scaling_results.py
@@ -148,8 +148,8 @@ def parse_files():
     
     # Loop over all files for a given series and load the times
     for j in range(0,len(file_list)):
-      times = np.loadtxt(file_list[j],usecols=(6,))
-      updates = np.loadtxt(file_list[j],usecols=(3,))
+      times = np.loadtxt(file_list[j],usecols=(8,))
+      updates = np.loadtxt(file_list[j],usecols=(5,))
       totalTime[i].append(np.sum(times))
       
     sumTotal.append(np.sum(totalTime[i]))
diff --git a/examples/plot_scaling_results_breakdown.py b/examples/plot_scaling_results_breakdown.py
index 92a9564c32..e20b429c61 100755
--- a/examples/plot_scaling_results_breakdown.py
+++ b/examples/plot_scaling_results_breakdown.py
@@ -149,8 +149,8 @@ def parse_files():
    
     # Loop over all files for a given series and load the times
     for j in range(0,len(file_list)):
-      times = np.loadtxt(file_list[j],usecols=(6,), skiprows=11)
-      updates = np.loadtxt(file_list[j],usecols=(3,), skiprows=11)
+      times = np.loadtxt(file_list[j],usecols=(8,))
+      updates = np.loadtxt(file_list[j],usecols=(5,))
       totalTime[i].append(np.sum(times))
       
     sumTotal.append(np.sum(totalTime[i]))
diff --git a/src/engine.c b/src/engine.c
index ffb4d752ef..c48510b657 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4370,14 +4370,17 @@ void engine_step(struct engine *e) {
   if (e->nodeID == 0) {
 
     /* Print some information to the screen */
-    printf("  %6d %14e %14e %12zu %12zu %12zu %21.3f %6d\n", e->step, e->time,
-           e->time_step, e->updates, e->g_updates, e->s_updates,
-           e->wallclock_time, e->step_props);
+    printf("  %6d %14e %14e %4d %4d %12zu %12zu %12zu %21.3f %6d\n", e->step,
+           e->time, e->time_step, e->min_active_bin, e->max_active_bin,
+           e->updates, e->g_updates, e->s_updates, e->wallclock_time,
+           e->step_props);
     fflush(stdout);
 
-    fprintf(e->file_timesteps, "  %6d %14e %14e %12zu %12zu %12zu %21.3f %6d\n",
-            e->step, e->time, e->time_step, e->updates, e->g_updates,
-            e->s_updates, e->wallclock_time, e->step_props);
+    fprintf(e->file_timesteps,
+            "  %6d %14e %14e %4d %4d %12zu %12zu %12zu %21.3f %6d\n", e->step,
+            e->time, e->time_step, e->min_active_bin, e->max_active_bin,
+            e->updates, e->g_updates, e->s_updates, e->wallclock_time,
+            e->step_props);
     fflush(e->file_timesteps);
   }
 
@@ -4385,6 +4388,7 @@ void engine_step(struct engine *e) {
   e->ti_old = e->ti_current;
   e->ti_current = e->ti_end_min;
   e->max_active_bin = get_max_active_bin(e->ti_end_min);
+  e->min_active_bin = get_min_active_bin(e->ti_current, e->ti_old);
   e->step += 1;
   e->step_props = engine_step_prop_none;
 
@@ -5213,6 +5217,7 @@ void engine_init(
   e->time_begin = 0.;
   e->time_end = 0.;
   e->max_active_bin = num_time_bins;
+  e->min_active_bin = 1;
   e->internal_units = internal_units;
   e->timeFirstSnapshot =
       parser_get_param_double(params, "Snapshots:time_first");
@@ -5508,12 +5513,13 @@ void engine_config(int restart, struct engine *e,
           "Version: %s \n# "
           "Number of threads: %d\n# Number of MPI ranks: %d\n# Hydrodynamic "
           "scheme: %s\n# Hydrodynamic kernel: %s\n# No. of neighbours: %.2f "
-          "+/- %.4f\n# Eta: %f\n",
+          "+/- %.4f\n# Eta: %f\n# Config: %s\n# CFLAGS: %s\n",
           hostname(), git_branch(), git_revision(), compiler_name(),
           compiler_version(), e->nr_threads, e->nr_nodes, SPH_IMPLEMENTATION,
           kernel_name, e->hydro_properties->target_neighbours,
           e->hydro_properties->delta_neighbours,
-          e->hydro_properties->eta_neighbours);
+          e->hydro_properties->eta_neighbours, configuration_options(),
+          compilation_cflags());
 
       fprintf(e->file_timesteps,
               "# Step Properties: Rebuild=%d, Redistribute=%d, Repartition=%d, "
@@ -5523,9 +5529,9 @@ void engine_config(int restart, struct engine *e,
               engine_step_prop_snapshot, engine_step_prop_restarts);
 
       fprintf(e->file_timesteps,
-              "# %6s %14s %14s %12s %12s %12s %16s [%s] %6s\n", "Step", "Time",
-              "Time-step", "Updates", "g-Updates", "s-Updates",
-              "Wall-clock time", clocks_getunit(), "Props");
+              "# %6s %14s %14s %9s %12s %12s %12s %16s [%s] %6s\n", "Step",
+              "Time", "Time-step", "Time-bins", "Updates", "g-Updates",
+              "s-Updates", "Wall-clock time", clocks_getunit(), "Props");
       fflush(e->file_timesteps);
     }
   }
diff --git a/src/engine.h b/src/engine.h
index 3e29b9226f..0fa8ca93b8 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -142,6 +142,9 @@ struct engine {
   /* The highest active bin at this time */
   timebin_t max_active_bin;
 
+  /* The lowest active bin at this time */
+  timebin_t min_active_bin;
+
   /* Time step */
   double time_step;
 
diff --git a/src/timeline.h b/src/timeline.h
index 0f38ff3e94..66b2c9456f 100644
--- a/src/timeline.h
+++ b/src/timeline.h
@@ -40,6 +40,12 @@ typedef char timebin_t;
 /*! Fictious time-bin to hold inhibited particles */
 #define time_bin_inhibited (num_time_bins + 2)
 
+/*! Fictitious time-bin for particles not awaken */
+#define time_bin_not_awake (0)
+
+/*! Fictitious time-bin for particles woken up */
+#define time_bin_awake (-1)
+
 /**
  * @brief Returns the integer time interval corresponding to a time bin
  *
@@ -122,4 +128,17 @@ static INLINE timebin_t get_max_active_bin(integertime_t time) {
   return bin;
 }
 
+/**
+ * @brief Returns the lowest active time bin at a given point on the time line.
+ *
+ * @param ti_current The current point on the time line.
+ * @param ti_old The last synchronisation point on the time line.
+ */
+static INLINE timebin_t get_min_active_bin(integertime_t ti_current,
+                                           integertime_t ti_old) {
+
+  const timebin_t min_bin = get_max_active_bin(ti_current - ti_old);
+  return (ti_old > 0) ? min_bin : (min_bin - 1);
+}
+
 #endif /* SWIFT_TIMELINE_H */
-- 
GitLab