From 510bbef90f4f9133fea26bd9072a39082a710f85 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Thu, 19 Sep 2019 15:07:53 +0100
Subject: [PATCH] Forgot bcast is not synchronous, so we need a barrier to stop
 loops running ahead

---
 mpiuse.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mpiuse.c b/mpiuse.c
index 115ee43..093a52b 100644
--- a/mpiuse.c
+++ b/mpiuse.c
@@ -197,8 +197,10 @@ void mpiuse_dump_logs(int nranks, const char *dumpfile) {
      * one-by-one. */
     int kk = k;
     MPI_Bcast(&kk, 1, MPI_INT, 0, MPI_COMM_WORLD);
+    message("Bcast says: %d/%d/%d", kk, k, myrank);
 
-    if (k == myrank) {
+    if (kk == myrank) {
+        message("Dumping from rank: %d/%d/%d", kk, k, myrank);
 
       /* Open file and position at end. */
       fd = fopen(dumpfile, "a");
@@ -223,6 +225,9 @@ void mpiuse_dump_logs(int nranks, const char *dumpfile) {
       }
       fclose(fd);
     }
+
+    /* Need to stay in step. */
+    MPI_Barrier(MPI_COMM_WORLD);
   }
 }
 
-- 
GitLab