From 8decdc205887a2e531f8392a843e0edfef51898f Mon Sep 17 00:00:00 2001
From: Thomas <purcell@fhi-berlin.mpg.de>
Date: Wed, 1 Sep 2021 09:17:31 +0200
Subject: [PATCH] Try to resolve the Input file loading issue in some gcov
 tests

mpi barriers not seeming to work alone
---
 .gitlab-ci.yml             | 71 +++-----------------------------------
 src/inputs/InputParser.cpp | 24 +++++++++----
 src/inputs/InputParser.hpp |  2 +-
 3 files changed, 22 insertions(+), 75 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 77c7ae77..07b8d40b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -170,26 +170,7 @@ test-intel-bin-param:
     - export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
     - export OMP_NUM_THREADS=1
     - cd tests/exec_test/default/
-    - mpiexec -n 1 ../../../intel_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../classification/
-    - mpiexec -n 1 ../../../intel_param_py/bin/sisso++
-    - python check_model.py
-    - cd ../gen_proj
-    - mpiexec -n 2 ../../../intel_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../log_reg
-    - mpiexec -n 2 ../../../intel_param_py/bin/sisso++
-    - python check_model.py
-    - cd ../max_corr
-    - mpiexec -n 2 ../../../intel_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../param
-    - mpiexec -n 2 ../../../intel_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../reparam
-    - mpiexec -n 2 ../../../intel_param_py/bin/sisso++
-    - python check_model.py
+    - for direc in ../*/; do cd $direc; mpiexec -n 1 ../../../intel_param_py/bin/sisso++; python check_model.py; done
     - cd ../../../
 
 test-intel-bin-base:
@@ -206,19 +187,7 @@ test-intel-bin-base:
     - export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
     - export OMP_NUM_THREADS=1
     - cd tests/exec_test/default/
-    - mpiexec -n 1 ../../../intel_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../classification/
-    - mpiexec -n 1 ../../../intel_py/bin/sisso++
-    - python check_model.py
-    - cd ../gen_proj
-    - mpiexec -n 2 ../../../intel_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../log_reg
-    - mpiexec -n 2 ../../../intel_py/bin/sisso++
-    - python check_model.py
-    - cd ../max_corr
-    - mpiexec -n 2 ../../../intel_py/bin/sisso++
+    - for direc in ../*/; do cd $direc; if [[ $direc != *"param"* ]]; then mpiexec -n 1 ../../../intel_py/bin/sisso++; python check_model.py; fi; done
     - cd ../../../
 
 build-gnu-base:
@@ -343,26 +312,7 @@ test-gnu-bin-param:
     - export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_gnu_param_py_env/lib/python3.7/site-packages/
     - export OMP_NUM_THREADS=1
     - cd tests/exec_test/default/
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../classification/
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python check_model.py
-    - cd ../gen_proj
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../log_reg
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python check_model.py
-    - cd ../max_corr
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../param
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../reparam
-    - mpiexec -n 1 ../../../gnu_param_py/bin/sisso++
-    - python check_model.py
+    - for direc in ../*/; do cd $direc; mpiexec -n 1 ../../../gnu_param_py/bin/sisso++; python check_model.py; done
     - cd ../../../
 
 test-gnu-bin-base:
@@ -375,20 +325,7 @@ test-gnu-bin-base:
     - export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_gnu_py_env/lib/python3.7/site-packages/
     - export OMP_NUM_THREADS=1
     - cd tests/exec_test/default/
-    - mpiexec -n 1 ../../../gnu_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../classification/
-    - mpiexec -n 1 ../../../gnu_py/bin/sisso++
-    - python check_model.py
-    - cd ../gen_proj
-    - mpiexec -n 1 ../../../gnu_py/bin/sisso++
-    - python ../check_model.py
-    - cd ../log_reg
-    - mpiexec -n 1 ../../../gnu_py/bin/sisso++
-    - python check_model.py
-    - cd ../max_corr
-    - mpiexec -n 1 ../../../gnu_py/bin/sisso++
-    - python ../check_model.py
+    - for direc in ../*/; do cd $direc; if [[ $direc != *"param"* ]]; then mpiexec -n 1 ../../../gnu_py/bin/sisso++; python check_model.py; fi; done
     - cd ../../../
 
 build-gnu-gcov:
diff --git a/src/inputs/InputParser.cpp b/src/inputs/InputParser.cpp
index b0bdcad3..399704f6 100644
--- a/src/inputs/InputParser.cpp
+++ b/src/inputs/InputParser.cpp
@@ -280,7 +280,22 @@ InputParser::InputParser(pt::ptree ip, std::string fn, std::shared_ptr<MPI_Inter
 
 InputParser::InputParser(std::string fn) :
     InputParser(get_prop_tree(fn, mpi_setup::comm), fn, mpi_setup::comm)
-{}
+{
+    if(_mpi_comm->rank() == 0)
+    {
+        std::vector<std::string> filepath = str_utils::split_string_trim(fn, "/");
+        std::string(fn);
+        if(filepath.size() > 1)
+        {
+            fn = str_utils::join("/", filepath.data(), filepath.size() - 1) + "/stripped_" + filepath.back();
+        }
+        else
+        {
+            fn = "stripped_" + fn;
+        }
+        boost::filesystem::remove(fn);
+    }
+}
 
 void InputParser::generate_phi_0(
     std::vector<std::string> headers,
@@ -862,7 +877,7 @@ void strip_comments(std::string& filename)
     filename = new_fn;
 }
 
-pt::ptree get_prop_tree(std::string fn, std::shared_ptr<MPI_Interface> mpi_comm)
+pt::ptree get_prop_tree(std::string fn, std::shared_ptr<MPI_Interface>& mpi_comm)
 {
     if(mpi_comm->rank() == 0)
     {
@@ -888,10 +903,5 @@ pt::ptree get_prop_tree(std::string fn, std::shared_ptr<MPI_Interface> mpi_comm)
 
     mpi_comm->barrier();
 
-    if(mpi_comm->rank() == 0)
-    {
-        boost::filesystem::remove(fn);
-    }
-
     return prop_tree;
 }
diff --git a/src/inputs/InputParser.hpp b/src/inputs/InputParser.hpp
index 7ddd2322..6cc3f1c0 100644
--- a/src/inputs/InputParser.hpp
+++ b/src/inputs/InputParser.hpp
@@ -1077,7 +1077,7 @@ std::vector<T> as_vector(pt::ptree const &pt)
  *
  * @return The property tree representation of the json file
  */
-pt::ptree get_prop_tree(std::string fn, std::shared_ptr<MPI_Interface> mpi_comm);
+pt::ptree get_prop_tree(std::string fn, std::shared_ptr<MPI_Interface>& mpi_comm);
 
 
 #endif
-- 
GitLab