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 system improvements for CABLE offline #188

Closed
4 tasks done
SeanBryan51 opened this issue Dec 11, 2023 · 5 comments · Fixed by #200
Closed
4 tasks done

Build system improvements for CABLE offline #188

SeanBryan51 opened this issue Dec 11, 2023 · 5 comments · Fixed by #200
Assignees

Comments

@SeanBryan51
Copy link
Collaborator

SeanBryan51 commented Dec 11, 2023

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.

@SeanBryan51
Copy link
Collaborator Author

@harshula and I have scoped out solutions to address these issues. In short, we have concluded that moving to a CMake based build system is the best approach.

Addressing the requirements with CMake

CMake advantages:

  • Fortran module dependency resolution is completely automated with CMake. There are tools to generate Makefile dependency rules (see here, however these approaches often require maintenance - CMake does not require any maintenance.
  • CMake is a build system generator. It can create a faster build system to use like ninja to speed up compilation time.
  • CMake is less prone to build system inconsistencies due to it being more standardised and automated than tools such as GNU Make.
  • A CMake build system could provide a basis for building libraries which could be linked against in a coupled model context.

CMake disadvantages:

  • There may be a lack of CMake expertise in the community. This raises the need for a well documented guide for developers to assist those who are unfamiliar with CMake.

Consequences of moving to CMake

It is currently not possible to transition to CMake without breaking binary equivalence with the current build due to parts of the build system which are automated in CMake. To demonstrate binary equivalence when moving to CMake, the current build system will have to be massaged into the CMake way of doing things. The required changes include:

@JhanSrbinovsky
Copy link
Collaborator

Just a general comment here. The make tools will only apply to offline/. The future of which is less than certain, however likely to be around for at least 5 years even if we do adopt the JAC-Standalone route. But my main comment is that the intention of the existing Makefile(s), build scripts (apart from building an execuable) was to be transparent and easy to amend by developers. Potential developers/users are familiar with 1970s Makefiles, shell scripts etc. A large cohort of users will be on the NCI platform, where I suspect you have been developing this system so obviously the tools are available. However, an equally large cohort are not. In the past questions from new users about building etc have been unrelated to available tools as there is (I doubt) any UNIX/linux system that does not have bash, make etc. Is this going to be a problem? Docs on how to build will require updating to describe all of this.

@harshula
Copy link

Hi, While reviewing the existing build system, our observation was that the Makefile build system has been improperly amended by developers over time. Our understanding is that CMake automates a number of important steps, particularly module dependencies for Fortran projects. This may allow model developers to focus more on the Fortran code and reduce the changes to the build system.

@ccarouge
Copy link
Collaborator

@JhanSrbinovsky for tools availability, it is true that CMake isn't always available on all systems by default but it is very easy to install. I would think it is available on all supercomputers nowadays and it is available via Homebrew for Macs.

For ease of development, as Harshula said, if it is well done it might reduce the need for changing the build system following the development of CABLE hence making it simpler for development work.

@JhanSrbinovsky
Copy link
Collaborator

@ccarouge, fine with me. I gave up long ago on running CABLE locally anyway. In fact, we officially gave up on trying to support CABLE on anything less than at least a dedicated HPC system. The overwhelming majority of build issues were related to external tools/libs

@SeanBryan51 SeanBryan51 self-assigned this Jan 22, 2024
@SeanBryan51 SeanBryan51 linked a pull request Jan 22, 2024 that will close this issue
2 tasks
SeanBryan51 added a commit that referenced this issue Mar 1, 2024
In preparation for building CABLE with [spack](https://spack.io/),
@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](https://cmake.org/) based build system to
address these issues:

- #190
Although this problem can be solved in the Makefile by specifying the
relative paths to each source file, it requires updating all the
Makefile Fortran module dependency rules which is a pain. CMake
automatically handles Fortran module dependencies out of the box so
doing this with CMake is much easier.
- #191 
When invoking `cmake`, custom options, compilers and compiler flags can
be configurable by setting the appropriate variables via the [`-D`
flag](https://cmake.org/cmake/help/latest/manual/cmake.1.html#cmdoption-cmake-D),
for example: `cmake -DCMAKE_Fortran_COMPILER="mpif90"
-DCMAKE_Fortran_FLAGS="-O2 -fp-model precise" -S . -B build`. These can
be used for doing MPI only builds and enabling specific debug flags.
- #192 
As mentioned above, CMake automatically handles Fortran module
dependencies out of the box. Parallelised builds can be done by
specifying the `-j` flag to `cmake`.

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.

- [x] #197
- [x] #199

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

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

<!-- readthedocs-preview cable end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants