Skip to content

Commit

Permalink
Build MPI and serial executables in separate build trees
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanBryan51 committed Nov 13, 2024
1 parent 9c9a954 commit 15077ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/benchcab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@ 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"]

build_flags = {}

build_flags["build_type"] = "Debug" if coverage else "Release"
build_flags["mpi"] = "ON" if mpi else "OFF"

build_flags["flags_init"] = ""

Expand Down Expand Up @@ -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)

Check warning on line 166 in src/benchcab/model.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/model.py#L166

Added line #L166 was not covered by tests
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",
Expand Down Expand Up @@ -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)

Check warning on line 210 in src/benchcab/model.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/model.py#L210

Added line #L210 was not covered by tests
self.subprocess_handler.run_cmd(
"cmake --install build --prefix .", env=env
)
if mpi:
self.subprocess_handler.run_cmd(

Check warning on line 215 in src/benchcab/model.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/model.py#L214-L215

Added lines #L214 - L215 were not covered by tests
"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(

Check warning on line 219 in src/benchcab/model.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/model.py#L218-L219

Added lines #L218 - L219 were not covered by tests
"cmake --install build_mpi --prefix .", env=env
)


def remove_module_lines(file_path: Path) -> None:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}

Expand All @@ -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
Expand Down

0 comments on commit 15077ff

Please sign in to comment.