-
Notifications
You must be signed in to change notification settings - Fork 156
update cmake build for testing, build types and mixed precision #1694
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
Changes from all commits
c6c7eef
b985446
10d3f5d
2c7869a
10ac33b
436d708
64d120a
a3ae512
c088182
a377d46
db7f16e
e9e04c3
1772c6b
502d97b
810f343
94bea35
c68092e
ca15c94
1eeeddc
a209999
3bd3248
f12f78b
b957dd3
d83abe7
7e325c1
5d2a8d4
8050e20
cecc9e4
0badd96
99d181b
4b63446
12ccd0b
a12970d
06d81cc
8a69d09
b034f50
b904727
842ddc5
f7e21b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,25 +18,17 @@ jobs: | |
| container: | ||
| image: ghcr.io/noaa-gfdl/fms/fms-ci-rocky-gnu:13.2.0 | ||
| env: | ||
| CMAKE_FLAGS: "${{ matrix.build-type }} ${{ matrix.omp-flags }} ${{ matrix.libyaml-flag }} -D64BIT=on" | ||
| CMAKE_FLAGS: "${{ matrix.build-type }} ${{ matrix.omp-flags }} ${{ matrix.libyaml-flag }}" | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/[email protected] | ||
| - name: Generate makefiles with CMake | ||
| run: cmake $CMAKE_FLAGS -DNetCDF_ROOT=/opt/view -DLIBYAML_ROOT=/opt/view | ||
| - name: Build the library | ||
| run: make | ||
| - name: Link with basic executable | ||
| run: | | ||
| echo "program test" > test.F90 | ||
| echo " use fms_mod" >> test.F90 | ||
| echo " call fms_init" >> test.F90 | ||
| echo " call fms_end" >> test.F90 | ||
| echo "end program" >> test.F90 | ||
| mpifort -L/opt/view/lib -fopenmp `nf-config --flibs` -Iinclude_r4 -Iinclude_r8 test.F90 libfms_r4.a libfms_r8.a -o test.x | ||
| touch input.nml | ||
| - name: Run executable | ||
| run: ./test.x | ||
| mkdir build | ||
| cd build | ||
| cmake $CMAKE_FLAGS -DNetCDF_ROOT=/opt/view -DLIBYAML_ROOT=/opt/view .. | ||
| - name: Build the library | ||
| run: make -C build | ||
|
|
||
| build_arm: | ||
| runs-on: ubuntu-24.04-arm | ||
|
|
@@ -48,22 +40,14 @@ jobs: | |
| container: | ||
| image: ghcr.io/noaa-gfdl/fms/fms-ci-rocky-gnu:13.2.0-arm | ||
| env: | ||
| CMAKE_FLAGS: "${{ matrix.build-type }} ${{ matrix.omp-flags }} ${{ matrix.libyaml-flag }} -D64BIT=on" | ||
| CMAKE_FLAGS: "${{ matrix.build-type }} ${{ matrix.omp-flags }} ${{ matrix.libyaml-flag }}" | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/[email protected] | ||
| - name: Generate makefiles with CMake | ||
| run: cmake $CMAKE_FLAGS -DNetCDF_ROOT=/opt/view -DLIBYAML_ROOT=/opt/view | ||
| - name: Build the library | ||
| run: make | ||
| - name: Link with basic executable | ||
| run: | | ||
| echo "program test" > test.F90 | ||
| echo " use fms_mod" >> test.F90 | ||
| echo " call fms_init" >> test.F90 | ||
| echo " call fms_end" >> test.F90 | ||
| echo "end program" >> test.F90 | ||
| mpifort -L/opt/view/lib -fopenmp `nf-config --flibs` -Iinclude_r4 -Iinclude_r8 test.F90 libfms_r4.a libfms_r8.a -o test.x | ||
| touch input.nml | ||
| - name: Run executable | ||
| run: ./test.x | ||
| mkdir build | ||
| cd build | ||
| cmake $CMAKE_FLAGS -DNetCDF_ROOT=/opt/view -DLIBYAML_ROOT=/opt/view .. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this running the tests? |
||
| - name: Build the library | ||
| run: make -C build | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,55 @@ | ||
| \page cmake Building with CMake | ||
| # Instructions for building FMS with cmake | ||
|
|
||
| ## 1. Environment Variables | ||
| ## 1. Configuring the build | ||
|
|
||
| ### For GNU compilers on Linux with the bash shell: | ||
| ### Environment Variables | ||
|
|
||
| #### For GNU compilers on Linux with the bash shell: | ||
| ``` | ||
| export FC=mpifort | ||
| export CC=mpicc | ||
| ``` | ||
|
|
||
| ### For Intel Compilers on Linux with the bash shell: | ||
|
|
||
| #### For Intel Compilers on Linux with the bash shell: | ||
| ``` | ||
| export FC=mpiifort | ||
| export CC=mpiicc | ||
| ``` | ||
| MPI compiler wrappers may be named different on your system, so its best to ensure the compiler commands work prior to being set. | ||
|
|
||
| ### NetCDF is provided via the `nc-config` command: | ||
| #### NetCDF is provided via the `nc-config` command: | ||
| ``` | ||
| export NetCDF_ROOT=`nc-config --prefix` | ||
| ``` | ||
|
|
||
| ### If building with yaml parser (-DWITH_YAML) | ||
| #### If building with yaml parser (-DWITH_YAML) | ||
| ``` | ||
| export LIBYAML_ROOT=<your libyaml install directory> | ||
| ``` | ||
|
|
||
| ### Setting custom flags with the bash shell | ||
| To override the default compiler flags: | ||
| ### Running CMake | ||
| It's best to create a build directory inside of the FMS folder to avoid building on top of the source code. | ||
| Once that is done, CMake can be ran to generate the necessary build files: | ||
| ``` | ||
| export FCFLAGS="<fortran flags>" | ||
| export CFLAGS="<c flags>" | ||
| mkdir build && cd build | ||
| cmake [-DWITH_YAML=on] .. | ||
| ``` | ||
| In addition, the flag below must be included with the cmake command: | ||
|
|
||
| ### Setting a Build Type | ||
| CMake uses "build types" to set compiler flags. By default (.ie no -DCMAKE_BUILD_TYPE="Type" argument when cmake is run), it will use the "Release" build type which corresponds the the prod/opt flags used by the GFDL mkmf templates. | ||
|
|
||
| Similarly "Repro" and "Debug" also correspond to whatever options would be set by theircorresponding mkmf template files. | ||
|
|
||
| To reproduce the old behavior for the cmake build (2025.03 and prior), the "ReleaseUFS" and "DebugUFS" will use the same flags as before. | ||
|
|
||
| Please open an issue in the FMS repository if you have any issues or would like to request any changes to the current build type options. | ||
|
|
||
| ### Setting custom flags | ||
| To override the default compiler flags, you can set them via CMake arguments: | ||
| ``` | ||
| cmake <any other options> -DCMAKE_BUILD_TYPE=Debug .. | ||
| cmake -DCMAKE_BUILD_TYPE="NoFlags" -DCMAKE_C_FLAGS="<c flags>" -DCMAKE_Fortran_FLAGS="<fortran flags>" | ||
| ``` | ||
| By using the "NoFlags" build type, only necessary compilation flags will be added besides what is set via the cmake arguments. | ||
|
|
||
| ## 2. Build and install FMS with CMake | ||
| `<prefix>` is the full install directory for FMS provided by user | ||
|
|
@@ -45,20 +58,25 @@ cmake <any other options> -DCMAKE_BUILD_TYPE=Debug .. | |
| cd FMS | ||
| mkdir -p build && cd build | ||
| cmake -DCMAKE_INSTALL_PREFIX=<prefix> .. | ||
| make -j4 | ||
| make -j | ||
| make install | ||
| ``` | ||
|
|
||
| ### User configurable options: | ||
| By default, FMS is built without `OpenMP`, in `single precision (r4)` and delivered in static library files. | ||
| By default, FMS is built with `OpenMP` enabled and delivered in static library files. | ||
|
|
||
| FMS has mixed precision real support for most interfaces. By default, one library will be created, | ||
| `libfms`, that is compiled with r8 defaults but also contains overloaded r4 routines. | ||
|
|
||
| The 64BIT and 32BIT precision options will build distinct libraries when enabled with the given default | ||
| real size, libfms_r4 or libfms_r8. | ||
| real size, libfms_r4 or libfms_r8. These option are provided for backwards compatibility, but are no longer | ||
| supported by our development team, since mixed precision can now be used with a single library. | ||
| Unit tests currently only work when no precision option is specified. | ||
|
|
||
| The following build options are available: | ||
| ``` | ||
| -DOPENMP "Build FMS with OpenMP support" DEFAULT: OFF | ||
| -D32BIT "Build 32-bit (r4) FMS library" DEFAULT: ON | ||
| -DOPENMP "Build FMS with OpenMP support" DEFAULT: ON | ||
| -D32BIT "Build 32-bit (r4) FMS library" DEFAULT: OFF | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enabling -D64BIT=ON made my cmake configuration fail because the tests were trying to find FMS::fms and it was not built. I can patch this in my PR #1743 to just either not build the tests or fail |
||
| -D64BIT "Build 64-bit (r8) FMS library" DEFAULT: OFF | ||
| -DFPIC "Build with position independent code" DEFAULT: OFF | ||
| -DSHARED_LIBS "Build shared/dynamic libraries" DEFAULT: OFF | ||
|
|
@@ -74,10 +92,10 @@ The following build options are available: | |
|
|
||
| ## 3. Installation structure | ||
|
|
||
| When the above command finishes, the `<prefix>` will have an `include_r4` and a `lib` directory. The `lib ` directory will have these files: | ||
| When the above command finishes, the `<prefix>` will have an `include` and a `lib` directory. The `lib ` directory will have these files: | ||
|
|
||
| ``` | ||
| libfms_r4.a | ||
| libfms.a | ||
| cmake/fms/fms-targets.cmake | ||
| cmake/fms/fms-targets-release.cmake | ||
| cmake/fms/fms-config.cmake | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using spack containers, nice!