From 124c1b7dbf449f23c49f05bb0cafc01410a31cfb Mon Sep 17 00:00:00 2001
From: Nicholas Frontiere <nfrontiere@anl.gov>
Date: Mon, 5 Feb 2024 09:46:28 -0600
Subject: [PATCH] adding MPI reduction and barrier to VELOC flush and shutdown
 calls

---
 GenericIO.h | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/GenericIO.h b/GenericIO.h
index 9832f1f..04df4cc 100644
--- a/GenericIO.h
+++ b/GenericIO.h
@@ -462,15 +462,24 @@ public:
   static void setNaturalDefaultPartition();
 
   static bool flushAll() {
+      bool ret = true;
 #ifdef GENERICIO_WITH_VELOC
-      return GenericFileIO_VELOC::flush();//With veloc do a blocking flush of anything outstanding and return if all outstanding tasks were successful
+      bool retLocal = GenericFileIO_VELOC::flush();//With veloc do a blocking flush of anything outstanding and return if all outstanding tasks were successful
+#ifndef GENERICIO_NO_MPI
+      MPI_Allreduce(&retLocal, &ret, 1, MPI_C_BOOL, MPI_LAND, MPI_COMM_WORLD);//Global reduction on if flush was successful 
+#else
+      ret = retLocal;
 #endif
-      return true;//by default return that flush was successful (as it does not do anything)
+#endif//GENERICIO_WITH_VELOC
+      return ret;//by default return that flush was successful (as it does not do anything)
   }
 
   static void shutdown() {
 #ifdef GENERICIO_WITH_VELOC
       GenericFileIO_VELOC::flush();
+#ifndef GENERICIO_NO_MPI
+      MPI_Barrier(MPI_COMM_WORLD);//Barrier to wait for all ranks to finish
+#endif
 #endif
   }
 
-- 
GitLab