From f973c37e9cd9363e9eaeadd2c0324ed5204a6461 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Fri, 28 Apr 2017 17:48:10 +0100
Subject: [PATCH] Write one timer dumpfile per MPI rank.

---
 examples/main.c     |  2 +-
 src/runner.c        | 10 +++++-----
 src/runner_doiact.h |  2 +-
 src/timers.c        |  8 ++++++--
 src/timers.h        |  2 +-
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index afe8265c62..631117148a 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -616,7 +616,7 @@ int main(int argc, char *argv[]) {
            clocks_getunit());
 
   /* File for the timers */
-  if (with_verbose_timers) timers_open_file();
+  if (with_verbose_timers) timers_open_file(myrank);
 
   /* Main simulation loop */
   for (int j = 0; !engine_is_done(&e) && e.step - 1 != nsteps; j++) {
diff --git a/src/runner.c b/src/runner.c
index 854b002213..778eb0c7c6 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -1450,7 +1450,8 @@ void runner_do_end_force(struct runner *r, struct cell *c, int timer) {
  * @param clear_sorts Should we clear the sort flag and hence trigger a sort ?
  * @param timer Are we timing this ?
  */
-void runner_do_recv_part(struct runner *r, struct cell *c, int clear_sorts, int timer) {
+void runner_do_recv_part(struct runner *r, struct cell *c, int clear_sorts,
+                         int timer) {
 
 #ifdef WITH_MPI
 
@@ -1467,8 +1468,7 @@ void runner_do_recv_part(struct runner *r, struct cell *c, int clear_sorts, int
   float h_max = 0.f;
 
   /* Clear this cell's sorted mask. */
-  if(clear_sorts)
-    c->sorted = 0;
+  if (clear_sorts) c->sorted = 0;
 
   /* If this cell is a leaf, collect the particle data. */
   if (!c->split) {
@@ -1876,8 +1876,8 @@ void *runner_main(void *data) {
             free(t->buff);
           } else if (t->subtype == task_subtype_xv) {
             runner_do_recv_part(r, ci, 1, 1);
-	  } else if  (t->subtype == task_subtype_rho) {
-            runner_do_recv_part(r, ci, 0, 1);
+          } else if (t->subtype == task_subtype_rho) {
+            runner_do_recv_part(r, ci, 1, 1);
           } else if (t->subtype == task_subtype_gpart) {
             runner_do_recv_gpart(r, ci, 1);
           } else if (t->subtype == task_subtype_spart) {
diff --git a/src/runner_doiact.h b/src/runner_doiact.h
index 37684940e1..36d287c327 100644
--- a/src/runner_doiact.h
+++ b/src/runner_doiact.h
@@ -1187,7 +1187,7 @@ void DOPAIR2(struct runner *r, struct cell *ci, struct cell *cj) {
       error("particle shift diff exceeds dx_max_sort.");
   }
 #endif /* SWIFT_DEBUG_CHECKS */
-  
+
   /* Get some other useful values. */
   const double hi_max = ci->h_max * kernel_gamma - rshift;
   const double hj_max = cj->h_max * kernel_gamma;
diff --git a/src/timers.c b/src/timers.c
index 153f782da4..aa42eee14f 100644
--- a/src/timers.c
+++ b/src/timers.c
@@ -123,10 +123,14 @@ void timers_print(int step) {
 
 /**
  * @brief Opens the file to contain the timers info and print a header
+ *
+ * @param rank The MPI rank of the file.
  */
-void timers_open_file() {
+void timers_open_file(int rank) {
 
-  timers_file = fopen("timers.txt", "w");
+  char buff[100];
+  sprintf(buff, "timers_%d.txt", rank);
+  timers_file = fopen(buff, "w");
 
   fprintf(timers_file, "# timers: \n# step | ");
   for (int k = 0; k < timer_count; k++)
diff --git a/src/timers.h b/src/timers.h
index 23ae61b83f..08e983a947 100644
--- a/src/timers.h
+++ b/src/timers.h
@@ -118,7 +118,7 @@ INLINE static ticks timers_toc(unsigned int t, ticks tic) {
 /* Function prototypes. */
 void timers_reset_all();
 void timers_reset(unsigned long long mask);
-void timers_open_file();
+void timers_open_file(int rank);
 void timers_close_file();
 void timers_print(int step);
 
-- 
GitLab