Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build MPI and serial executables in separate build trees #320

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/benchcab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,14 @@
"""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 @@
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 @@
)

self.subprocess_handler.run_cmd(
"cmake -S . -B build " + " ".join(cmake_args), env=env
"cmake -S . -B build/serial -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/serial", 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
"cmake --install build/serial --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
Loading