diff --git a/src/benchcab/model.py b/src/benchcab/model.py index 6e6246b..868d9dc 100644 --- a/src/benchcab/model.py +++ b/src/benchcab/model.py @@ -86,7 +86,7 @@ def get_coverage_dir(self) -> Path: """Get absolute path for code coverage analysis.""" return (internal.CODECOV_DIR / f"R{self.model_id}").absolute() - def _get_build_flags(self, mpi: bool, coverage: bool, compiler_id: str) -> dict: + def _get_build_flags(self, coverage: bool, compiler_id: str) -> dict: """Get flags for CMake build.""" # Supported compilers for code coverage codecov_compilers = ["ifort", "ifx"] @@ -94,7 +94,6 @@ def _get_build_flags(self, mpi: bool, coverage: bool, compiler_id: str) -> dict: build_flags = {} build_flags["build_type"] = "Debug" if coverage else "Release" - build_flags["mpi"] = "ON" if mpi else "OFF" build_flags["flags_init"] = "" @@ -164,14 +163,13 @@ def build(self, modules: list[str], mpi: bool, coverage: bool): self.logger.debug( f"Getting environment variable for compiler $FC = {env_fc}" ) - build_flags = self._get_build_flags(mpi, coverage, env_fc) + build_flags = self._get_build_flags(coverage, env_fc) env_fc = None with chdir(path_to_repo): env = os.environ.copy() cmake_args = [ - f"-DCABLE_MPI={build_flags['mpi']}", f"-DCMAKE_BUILD_TYPE={build_flags['build_type']}", f"-DCMAKE_Fortran_FLAGS_INIT={build_flags['flags_init']}", "-DCMAKE_VERBOSE_MAKEFILE=ON", @@ -207,12 +205,20 @@ def build(self, modules: list[str], mpi: bool, coverage: bool): ) self.subprocess_handler.run_cmd( - "cmake -S . -B build " + " ".join(cmake_args), env=env + "cmake -S . -B build -DCABLE_MPI=OFF " + " ".join(cmake_args), env=env ) - self.subprocess_handler.run_cmd("cmake --build build ", env=env) + self.subprocess_handler.run_cmd("cmake --build build", env=env) self.subprocess_handler.run_cmd( "cmake --install build --prefix .", env=env ) + if mpi: + self.subprocess_handler.run_cmd( + "cmake -S . -B build_mpi -DCABLE_MPI=ON " + " ".join(cmake_args), env=env + ) + self.subprocess_handler.run_cmd("cmake --build build_mpi", env=env) + self.subprocess_handler.run_cmd( + "cmake --install build_mpi --prefix .", env=env + ) def remove_module_lines(file_path: Path) -> None: diff --git a/tests/test_model.py b/tests/test_model.py index cdf6a3e..5724f48 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -121,7 +121,6 @@ def cmake_flags(self, codecov, mpi, compiler_id): return { "build_type": codecov_build_type[codecov], - "mpi": mpi_args[mpi], "flags_init": codecov_init_args[codecov], } @@ -136,11 +135,11 @@ def test_get_build_flags(self, model, mpi, codecov, compiler_id, cmake_flags): User has {compiler_id} in their environment""" ), ): - model._get_build_flags(mpi, codecov, compiler_id) + model._get_build_flags(codecov, compiler_id) return # Success case: get expected build flags to pass to CMake. - assert model._get_build_flags(mpi, codecov, compiler_id) == cmake_flags + assert model._get_build_flags(codecov, compiler_id) == cmake_flags # TODO(Sean) remove for issue https://github.com/CABLE-LSM/benchcab/issues/211