From 0ea13a6f9a0de84452770086c1ea71ef6204ba5a Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Wed, 21 Mar 2018 13:47:41 +0800
Subject: [PATCH] Turn on structure finding by passing '-x' to command line
 when running SWIFT. Off by default.

---
 examples/main.c | 10 ++++++++--
 src/engine.c    |  4 ++--
 src/engine.h    |  3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index 4c62bea2e8..811b2d9469 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -104,6 +104,7 @@ void print_help_message() {
   printf("  %2s %14s %s\n", "-v", "[12]", "Increase the level of verbosity:");
   printf("  %2s %14s %s\n", "", "", "1: MPI-rank 0 writes,");
   printf("  %2s %14s %s\n", "", "", "2: All MPI-ranks write.");
+  printf("  %2s %14s %s\n", "-x", "", "Run with structure finding.");
   printf("  %2s %14s %s\n", "-y", "{int}",
          "Time-step frequency at which task graphs are dumped.");
   printf("  %2s %14s %s\n", "-Y", "{int}",
@@ -192,6 +193,7 @@ int main(int argc, char *argv[]) {
   int with_fp_exceptions = 0;
   int with_drift_all = 0;
   int with_mpole_reconstruction = 0;
+  int with_structure_finding = 0;
   int verbose = 0;
   int nr_threads = 1;
   int with_verbose_timers = 0;
@@ -203,7 +205,7 @@ int main(int argc, char *argv[]) {
 
   /* Parse the parameters */
   int c;
-  while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:rsSt:Tv:y:Y:")) != -1)
+  while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:rsSt:Tv:xy:Y:")) != -1)
     switch (c) {
       case 'a':
 #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA)
@@ -291,6 +293,9 @@ int main(int argc, char *argv[]) {
           return 1;
         }
         break;
+      case 'x':
+        with_structure_finding = 1;
+        break;
       case 'y':
         if (sscanf(optarg, "%d", &dump_tasks) != 1) {
           if (myrank == 0) printf("Error parsing dump_tasks (-y). \n");
@@ -772,6 +777,7 @@ int main(int argc, char *argv[]) {
     if (with_cooling) engine_policies |= engine_policy_cooling;
     if (with_sourceterms) engine_policies |= engine_policy_sourceterms;
     if (with_stars) engine_policies |= engine_policy_stars;
+    if (with_structure_finding) engine_policies |= engine_policy_structure_finding;
 
     /* Initialize the engine with the space and policies. */
     if (myrank == 0) clocks_gettime(&tic);
@@ -844,7 +850,7 @@ int main(int argc, char *argv[]) {
     engine_print_stats(&e);
 
     /* Call VELOCIraptor before first step. */
-    invoke_velociraptor(&e);
+    if(with_structure_finding) invoke_velociraptor(&e);
   }
 
   /* Legend */
diff --git a/src/engine.c b/src/engine.c
index 0745921711..e39d8ccb80 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4515,7 +4515,7 @@ void engine_step(struct engine *e) {
   }
 
   /* Invoke VELOCIraptor every 250 timesteps thereafter. */
-  if (e->step%250 == 0) invoke_velociraptor(e);
+  if ((e->policy & engine_policy_structure_finding) && e->step%250 == 0) invoke_velociraptor(e);
 
   /* Now apply all the collected time step updates and particle counts. */
   collectgroup1_apply(&e->collect_group1, e);
@@ -5337,7 +5337,7 @@ void engine_config(int restart, struct engine *e,
   engine_rank = nodeID;
 
   /* Initialise VELOCIraptor. */
-  init_velociraptor(e);
+  if (e->policy & engine_policy_structure_finding) init_velociraptor(e);
   
   /* Get the number of queues */
   int nr_queues =
diff --git a/src/engine.h b/src/engine.h
index 0fa8ca93b8..e95a2c950e 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -69,7 +69,8 @@ enum engine_policy {
   engine_policy_reconstruct_mpoles = (1 << 12),
   engine_policy_cooling = (1 << 13),
   engine_policy_sourceterms = (1 << 14),
-  engine_policy_stars = (1 << 15)
+  engine_policy_stars = (1 << 15),
+  engine_policy_structure_finding = (1 << 16)
 };
 #define engine_maxpolicy 15
 extern const char *engine_policy_names[];
-- 
GitLab