From 17cf77885eba4b63870e7486f3f51a922fbd5b91 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Fri, 29 Jan 2016 13:01:19 +0000
Subject: [PATCH] Added timers to the init tasks

---
 src/runner.c | 42 +++++++++++++++++++++++++++++-------------
 src/runner.h |  2 +-
 src/timers.h |  1 +
 3 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/runner.c b/src/runner.c
index 98f9574412..f286326cfa 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -489,31 +489,47 @@ void runner_dogsort(struct runner *r, struct cell *c, int flags, int clock) {
  * @param c The cell.
  */
 
-void runner_doinit(struct runner *r, struct cell *c) {
+void runner_doinit(struct runner *r, struct cell *c, int timer) {
 
   struct part *p, *parts = c->parts;
   const int count = c->count;
   const float t_end = r->e->time;
+
+  TIMER_TIC;
   
   /* Recurse? */
   if (c->split) {
     for (int k = 0; k < 8; k++)
-      if (c->progeny[k] != NULL) runner_doinit(r, c->progeny[k]);
+      if (c->progeny[k] != NULL) runner_doinit(r, c->progeny[k], 0);
     return;
   }
+  else {
   
-  /* Loop over the parts in this cell. */
-  for (int i = 0; i < count; i++) {
-
-    /* Get a direct pointer on the part. */
-    p = &parts[i];
-
-    if (p->t_end <= t_end) {
-
-      /* Get ready for a density calculation */
-      hydro_init_part(p);
+    /* Loop over the parts in this cell. */
+    for (int i = 0; i < count; i++) {
+      
+      /* Get a direct pointer on the part. */
+      p = &parts[i];
+      
+      if (p->t_end <= t_end) {
+	
+	/* Get ready for a density calculation */
+	hydro_init_part(p);
+      }
     }
   }
+
+  if (timer) {
+#ifdef TIMER_VERBOSE
+    message("runner %02i: %i parts at depth %i took %.3f ms.", r->id, c->count,
+            c->depth, ((double)TIMER_TOC(timer_init)) / CPU_TPS * 1000);
+    fflush(stdout);
+#else
+    TIMER_TOC(timer_init);
+#endif
+  }
+
+  
 }
 
 /**
@@ -1026,7 +1042,7 @@ void *runner_main(void *data) {
             error("Unknown task subtype.");
           break;
         case task_type_init:
-          runner_doinit(r, ci);
+          runner_doinit(r, ci, 1);
           break;
         case task_type_ghost:
           runner_doghost(r, ci);
diff --git a/src/runner.h b/src/runner.h
index 366c4f7af6..ff2f93db6e 100644
--- a/src/runner.h
+++ b/src/runner.h
@@ -52,7 +52,7 @@ void runner_dosort(struct runner *r, struct cell *c, int flag, int clock);
 void runner_dogsort(struct runner *r, struct cell *c, int flag, int clock);
 void runner_dokick(struct runner *r, struct cell *c, int timer);
 void runner_dodrift(struct runner *r, struct cell *c, int timer);
-void runner_doinit(struct runner *r, struct cell *c);
+void runner_doinit(struct runner *r, struct cell *c, int timer);
 void *runner_main(void *data);
 
 #endif /* SWIFT_RUNNER_H */
diff --git a/src/timers.h b/src/timers.h
index 4ae56e5e67..95db02c5b8 100644
--- a/src/timers.h
+++ b/src/timers.h
@@ -27,6 +27,7 @@
 enum {
   timer_none = 0,
   timer_prepare,
+  timer_init,
   timer_drift,
   timer_kick,
   timer_dosort,
-- 
GitLab