From 6b5f1566ac7126ef079d7861c17dd4ea460dec8c Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Tue, 19 Sep 2023 23:05:24 +0200
Subject: [PATCH] Add a command line option to set parallel checker database
 filename

---
 src/dev_utils/ParallelChecker.hpp | 26 +++++++++++++++++++++++++-
 src/utils/PugsUtils.cpp           |  5 +++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/dev_utils/ParallelChecker.hpp b/src/dev_utils/ParallelChecker.hpp
index 82525d00f..fa204d134 100644
--- a/src/dev_utils/ParallelChecker.hpp
+++ b/src/dev_utils/ParallelChecker.hpp
@@ -43,7 +43,7 @@ class ParallelChecker
   Mode m_mode  = Mode::automatic;
   size_t m_tag = 0;
 
-  std::string m_filename = "testme/parallel_checker.h5";
+  std::string m_filename = "parallel_checker.h5";
 
   ParallelChecker() = default;
 
@@ -680,12 +680,36 @@ class ParallelChecker
     return *m_instance;
   }
 
+  Mode
+  mode() const
+  {
+    return m_mode;
+  }
+
   void
   setMode(const Mode& mode)
   {
+    if (m_tag != 0) {
+      throw UnexpectedError("Cannot modify parallel checker mode if it was already used");
+    }
     m_mode = mode;
   }
 
+  const std::string&
+  filename() const
+  {
+    return m_filename;
+  }
+
+  void
+  setFilename(const std::string& filename)
+  {
+    if (m_tag != 0) {
+      throw UnexpectedError("Cannot modify parallel checker file if it was already used");
+    }
+    m_filename = filename;
+  }
+
   bool
   isWriting() const
   {
diff --git a/src/utils/PugsUtils.cpp b/src/utils/PugsUtils.cpp
index b54135bb0..e4e905765 100644
--- a/src/utils/PugsUtils.cpp
+++ b/src/utils/PugsUtils.cpp
@@ -89,6 +89,7 @@ initialize(int& argc, char* argv[])
   int nb_threads      = -1;
 
   ParallelChecker::Mode pc_mode = ParallelChecker::Mode::automatic;
+  std::string pc_filename       = ParallelChecker::instance().filename();
 
   std::string filename;
   {
@@ -134,6 +135,9 @@ initialize(int& argc, char* argv[])
                   "Parallel checker mode (auto: sequential write/parallel read) [default: auto]")
       ->transform(CLI::CheckedTransformer(pc_mode_map));
 
+    app.add_option("--parallel-checker-file", pc_filename,
+                   "Parallel checker filename   [default: " + pc_filename + "]");
+
     int mpi_split_color = -1;
     app.add_option("--mpi-split-color", mpi_split_color, "Sets the MPI split color value (for MPMD applications)")
       ->check(CLI::Range(0, std::numeric_limits<decltype(mpi_split_color)>::max()));
@@ -178,6 +182,7 @@ initialize(int& argc, char* argv[])
   }
 
   ParallelChecker::instance().setMode(pc_mode);
+  ParallelChecker::instance().setFilename(pc_filename);
 
   if (ConsoleManager::showPreamble()) {
     std::cout << "----------------- " << rang::fg::green << "pugs exec info" << rang::fg::reset
-- 
GitLab