From 1592b25522bc32b6b9e6b8accfeaa212fb98fd1f Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Tue, 27 Nov 2018 14:50:50 +0000
Subject: [PATCH] Now we have ticks all the time the statistics and fixed costs
 estimates can be permanently available

Switch costs to time based, rather than some arbitrary scaling, makes comparisons more straight-forward
---
 examples/main.c | 12 +++++++-----
 src/scheduler.c |  3 +--
 src/task.c      | 13 ++++---------
 3 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index 69b0fcd55c..df2b30c743 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -328,9 +328,11 @@ int main(int argc, char *argv[]) {
         }
 #ifndef SWIFT_DEBUG_TASKS
         if (dump_tasks) {
-          error(
-              "Task dumping is only possible if SWIFT was configured with the "
-              "--enable-task-debugging option.");
+          if (myrank == 0) {
+            message("WARNING: complete task dumps are only created when "
+                    "configured with --enable-task-debugging. "
+                    "Basic task statistics will be output.");
+          }
         }
 #endif
         break;
@@ -1085,15 +1087,15 @@ int main(int argc, char *argv[]) {
     if (force_stop || (e.restart_onexit && e.step - 1 == nsteps))
       engine_dump_restarts(&e, 0, 1);
 
-#ifdef SWIFT_DEBUG_TASKS
     /* Dump the task data using the given frequency. */
     if (dump_tasks && (dump_tasks == 1 || j % dump_tasks == 1)) {
+#ifdef SWIFT_DEBUG_TASKS
       task_dump_all(&e, j + 1);
+#endif
 
       /* Generate the task statistics. */
       task_dump_stats(&e, j + 1);
     }
-#endif
 
 #ifdef SWIFT_DEBUG_THREADPOOL
     /* Dump the task data using the given frequency. */
diff --git a/src/scheduler.c b/src/scheduler.c
index d4ac89ddca..1cd65bc154 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -1816,13 +1816,12 @@ void scheduler_reweight(struct scheduler *s, int verbose) {
   /* Run through the tasks backwards and set their weights. */
   for (int k = nr_tasks - 1; k >= 0; k--) {
     struct task *t = &tasks[tid[k]];
-    float cost;
+    float cost = 0.f;
     t->weight = 0.f;
 
     for (int j = 0; j < t->nr_unlock_tasks; j++)
       if (t->unlock_tasks[j]->weight > t->weight)
         t->weight = t->unlock_tasks[j]->weight;
-    float cost = 0.f;
 
     const float count_i = (t->ci != NULL) ? t->ci->hydro.count : 0.f;
     const float count_j = (t->cj != NULL) ? t->cj->hydro.count : 0.f;
diff --git a/src/task.c b/src/task.c
index 62e00d9765..51998182ab 100644
--- a/src/task.c
+++ b/src/task.c
@@ -702,7 +702,6 @@ void task_dump_all(struct engine *e, int step) {
  */
 void task_dump_stats(struct engine *e, int step) {
 
-#ifdef SWIFT_DEBUG_TASKS
   char dumpfile[40];
   snprintf(dumpfile, 40, "thread_stats-step%d.dat", step);
 
@@ -725,7 +724,6 @@ void task_dump_stats(struct engine *e, int step) {
   }
 
   double total[1] = {0.0};
-  double minmin[1] = {DBL_MAX};
   for (int l = 0; l < e->sched.nr_tasks; l++) {
     int type = e->sched.tasks[l].type;
 
@@ -745,7 +743,6 @@ void task_dump_stats(struct engine *e, int step) {
         max[type][subtype] = dt;
       }
       total[0] += dt;
-      if (dt < minmin[0]) minmin[0] = dt;
     }
   }
 
@@ -773,10 +770,6 @@ void task_dump_stats(struct engine *e, int step) {
                    MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
   if (res != MPI_SUCCESS) mpi_error(res, "Failed to reduce task total time");
 
-  res = MPI_Reduce((engine_rank == 0 ? MPI_IN_PLACE : minmin), minmin, 1,
-                   MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
-  if (res != MPI_SUCCESS) mpi_error(res, "Failed to reduce task global min");
-
   if (engine_rank == 0) {
 #endif
 
@@ -790,7 +783,10 @@ void task_dump_stats(struct engine *e, int step) {
         if (sum[j][k] > 0.0) {
           double mean = sum[j][k] / (double)count[j][k];
           double perc = 100.0 * sum[j][k] / total[0];
-          int fixed_cost = (int)mean / minmin[0];
+
+          /* Fixed cost is in .1ns as we want to compare between runs in
+           * some absolute units. */
+          int fixed_cost = (int)(clocks_from_ticks(mean) * 10000.f);
           fprintf(dfile,
                   "%15s/%-10s %10d %14.2f %14.2f %14.2f %14.2f %14.2f %10d\n",
                   taskID, subtaskID_names[k], count[j][k], min[j][k], max[j][k],
@@ -806,5 +802,4 @@ void task_dump_stats(struct engine *e, int step) {
   }
 #endif
 
-#endif  // SWIFT_DEBUG_TASKS
 }
-- 
GitLab