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

Add CMake based build system for CABLE offline #200

Merged
merged 4 commits into from
Mar 1, 2024

Conversation

SeanBryan51
Copy link
Collaborator

@SeanBryan51 SeanBryan51 commented Jan 22, 2024

In preparation for building CABLE with spack, @harshula, @ccarouge and I have found areas where the current build system for CABLE offline can be improved (see #188 for more details). This change adds a CMake based build system to address these issues:

The following pull requests should be merged before this pull request so that we can demonstrate binary equivalence between the executables compiled by both Makefile and CMake builds. This ensures no unwanted changes are introduced by the transition.

Edit: the above PR's have been merged - the serial and MPI binaries built by CMake (in release mode) are equivalent to the binaries built by the Makefile based build system in the main branch.

Fixes #188, #190, #191, #192


📚 Documentation preview 📚: https://cable--200.org.readthedocs.build/en/200/

@SeanBryan51 SeanBryan51 linked an issue Jan 22, 2024 that may be closed by this pull request
4 tasks
documentation/docs/user_guide/installation.md Show resolved Hide resolved
Copy link
Collaborator Author

@SeanBryan51 SeanBryan51 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO after this pull request:

  • We should list the source files in alphabetical order (the current order is so that we preserve binary equivalence with the Makefile build).
  • Use find_package(MPI REQUIRED) instead of specifying mpif90 when invoking cmake for MPI case.
  • Add simultaneous compilation of MPI and serial executables by creating a separate target for each executable.
  • Remove MPI option from build script as the same can be achieved by specifying --target cable-mpi when invoking CMake.

CMakeLists.txt Outdated Show resolved Hide resolved
@SeanBryan51
Copy link
Collaborator Author

Note, some links in the documentation are currently broken as they point to source files that were added in this pull request. To see the source files, replace main with 188-cmake-based-build-system in the url.

@SeanBryan51
Copy link
Collaborator Author

@ccarouge is it worth supporting both Makefile and CMake based build systems? Or should we deprecate the Makefile build system in this pull request?

build.bash Outdated Show resolved Hide resolved
build.bash Outdated Show resolved Hide resolved
@ccarouge
Copy link
Collaborator

@ccarouge is it worth supporting both Makefile and CMake based build systems? Or should we deprecate the Makefile build system in this pull request?

For the record: we only want to support one build system. So this PR should deprecate the Makefile build system.

@SeanBryan51 SeanBryan51 force-pushed the 188-cmake-based-build-system branch 3 times, most recently from 22896d4 to b7aec13 Compare February 28, 2024 01:29
Copy link
Collaborator

@ccarouge ccarouge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor stuff. I don't think I need to review again but I'd like the -j option for cmake to be an option for build.bash.

build.bash Show resolved Hide resolved
build.bash Outdated Show resolved Hide resolved
build.bash Show resolved Hide resolved
Copy link

@harshula harshula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Potentially a few things we can look at later.

This was referenced Mar 1, 2024
@SeanBryan51 SeanBryan51 merged commit 045dfe2 into main Mar 1, 2024
2 of 3 checks passed
@SeanBryan51 SeanBryan51 deleted the 188-cmake-based-build-system branch March 1, 2024 04:55
SeanBryan51 added a commit that referenced this pull request Mar 15, 2024
This pull request should follow after the CMake implementation (see
#200). This change adds the following build system changes:

- List source files in alphabetical order in CMakeLists.txt. The order
of source files was previously chosen so that we could demonstrate
binary equivalence in executables between the CMake build and the
Makefile build.
- Use [`find_package(MPI
REQUIRED)`](https://cmake.org/cmake/help/latest/module/FindMPI.html)
instead of specifying `mpif90` when invoking `cmake` for MPI case. This
is done so that
1. We can create separate targets for the serial and MPI executable and
only link against the MPI libraries when needed without relying on the
MPI compiler wrapper. This lets us compile all executables (serial and
parallel) with a single invocation of CMake.
2. We can use object libraries to compile the object files common to
both serial and MPI builds. This saves compiling these object files for
each executable (serial and MPI), reducing compilation time.
- Portability fixes and improvements to build.bash.
- Add `--compiler` flag to build.bash and GNU compiler support.
- Add Matthias's configuration for example.

Regression tests using
[benchcab](https://github.com/CABLE-LSM/benchcab)* (bitwise comparison
of model output via nccmp) show that model output is bitwise identical
between the current branch and the main branch for serial and MPI model
runs.

*executables were built manually as benchcab does not yet support the
recent build system changes (see related issue:
CABLE-LSM/benchcab#258).

Fixes #215

<!-- readthedocs-preview cable start -->
----
📚 Documentation preview 📚:
https://cable--216.org.readthedocs.build/en/216/

<!-- readthedocs-preview cable end -->
SeanBryan51 added a commit to CABLE-LSM/benchcab that referenced this pull request Apr 4, 2024
The CABLE build system was transitioned from Makefile to CMake: see
CABLE-LSM/CABLE#216,
CABLE-LSM/CABLE#200.

This change adds support for building CABLE via CMake in benchcab so
that CABLE versions which branch from the HEAD of main can be tested.

Closes #258
SeanBryan51 added a commit to CABLE-LSM/benchcab that referenced this pull request Apr 4, 2024
The CABLE build system was transitioned from Makefile to CMake: see
CABLE-LSM/CABLE#216,
CABLE-LSM/CABLE#200.

This change adds support for building CABLE via CMake in benchcab so
that CABLE versions which branch from the HEAD of main can be tested.

Closes #258
SeanBryan51 added a commit to CABLE-LSM/benchcab that referenced this pull request Apr 5, 2024
The CABLE build system was transitioned from Makefile to CMake: see
CABLE-LSM/CABLE#216,
CABLE-LSM/CABLE#200.

This change adds support for building CABLE via CMake in benchcab so
that CABLE versions which branch from the HEAD of main can be tested.

Closes #258
SeanBryan51 added a commit to CABLE-LSM/benchcab that referenced this pull request Apr 5, 2024
The CABLE build system was transitioned from Makefile to CMake: see
CABLE-LSM/CABLE#216,
CABLE-LSM/CABLE#200.

This change adds support for building CABLE via CMake in benchcab so
that CABLE versions which branch from the HEAD of main can be tested.

Closes #258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants