Skip to content

Commit 728644b

Browse files
authored
Add CMake Build (#77)
This adds a CMake build for cice5, this is only tested with the "auscom" (access-om2) driver. I will fix the "access" driver when merging in the access-esm1.6 branch. These options are exposed to the user now, with defaults from access 1 degree configurations, to enable easier optimisation: set(CICE_NXGLOB "360" CACHE STRING "Size of grid in X-direction") set(CICE_NYGLOB "300" CACHE STRING "Size of grid in Y-direction") set(CICE_BLCKX "15" CACHE STRING "Size of computational blocks in X-direction") set(CICE_BLCKY "300" CACHE STRING "Size of computational blocks in Y-direction") set(CICE_MXBLCKS "1" CACHE STRING "Maximum number of blocks per task")
1 parent cb27fd5 commit 728644b

10 files changed

Lines changed: 856 additions & 8 deletions

File tree

.github/build-ci/data/standard.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"gcc_compiler": "gcc@13.2.0",
33
"intel_compiler": "intel@2021.10.0",
44
"oneapi_compiler": "oneapi@2025.2.0",
5+
"om2_1deg": "build_system=cmake model=access-om2 nxglob=360 nyglob=300 blckx=15 blcky=300 mxblcks=1",
56
"target": "x86_64"
67
}

.github/build-ci/manifests/gcc-cice5.spack.yaml.j2 renamed to .github/build-ci/manifests/gcc-cice5-makefile.spack.yaml.j2

File renamed without changes.

.github/build-ci/manifests/intel-cice5.spack.yaml.j2 renamed to .github/build-ci/manifests/intel-cice5-makefile.spack.yaml.j2

File renamed without changes.

.github/build-ci/manifests/oneapi-cice5.spack.yaml.j2 renamed to .github/build-ci/manifests/oneapi-cice5-makefile.spack.yaml.j2

File renamed without changes.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ jobs:
3838
# spack-config-ref: main
3939
# spack-ref: releases/v0.22
4040
secrets:
41-
spack-install-command-pat: ${{ secrets.SPACK_INSTALL_COMMAND_PAT }}
41+
spack-install-command-pat: ${{ secrets.SPACK_INSTALL_COMMAND_PAT }}

CMakeLists.txt

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
# Copyright ACCESS-NRI and contributors. See the top-level LICENSE file for details.
2+
3+
cmake_minimum_required(VERSION 3.18)
4+
5+
#[==============================================================================[
6+
# Basic project definition #
7+
#]==============================================================================]
8+
9+
project(CICE
10+
DESCRIPTION "CICE5 Sea Ice Model"
11+
HOMEPAGE_URL https://github.com/ACCESS-NRI/cice5
12+
LANGUAGES Fortran)
13+
14+
#[==============================================================================[
15+
# Options #
16+
#]==============================================================================]
17+
18+
message(STATUS "Build options")
19+
20+
# provide some default options from access "1degree" configurations
21+
# its intended the user will set these
22+
23+
set(CICE_IO "PIO" CACHE STRING "CICE netcdf io method")
24+
25+
if(NOT CICE_IO MATCHES "^(NetCDF|PIO)$")
26+
message(FATAL_ERROR " CICE_IO ${CICE_IO} not valid, choose NetCDF|PIO")
27+
else()
28+
message(STATUS " - CICE_IO ${CICE_IO}")
29+
endif()
30+
31+
set(CICE_DRIVER "auscom" CACHE STRING "CICE driver code to use")
32+
message(STATUS " - CICE_DRIVER ${CICE_DRIVER}")
33+
34+
set(CICE_NXGLOB "360" CACHE STRING "Size of grid in X-direction")
35+
set(CICE_NYGLOB "300" CACHE STRING "Size of grid in Y-direction")
36+
37+
# defaults from https://github.com/ACCESS-NRI/access-spack-packages/blob/d8b48b18a1400cf2a6850af0bf038af55804d92f/packages/cice5/spack-build.sh#L89-L91
38+
# BLCKX = 360/24 = 15 , BLCKY = 300/1 = 300
39+
set(CICE_BLCKX "15" CACHE STRING "Size of computational blocks in X-direction")
40+
set(CICE_BLCKY "300" CACHE STRING "Size of computational blocks in Y-direction")
41+
set(CICE_MXBLCKS "1" CACHE STRING "Maximum number of blocks per task")
42+
43+
# these are also configuration settings, but we leave them as internal only at this point
44+
# could be made options if users need them
45+
46+
if (CICE_DRIVER MATCHES "access")
47+
set( NSNWLYR 1 )
48+
set( NICECAT 5 )
49+
set( NICELYR 1 )
50+
else()
51+
set( NSNWLYR 1 ) # number of vertical layers in the snow
52+
set( NICECAT 5 ) # number of ice thickness categories
53+
set( NICELYR 4 ) # number of vertical layers in the ice
54+
endif()
55+
56+
### Tracers # match ice_in tracer_nml to conserve memory
57+
set( TRBGCS 0 ) # number of skeletal layer bgc tracers
58+
set( TRAGE 1 ) # set to 1 for ice age tracer
59+
set( TRFY 1 ) # set to 1 for first-year ice area tracer
60+
set( TRLVL 1 ) # set to 1 for level and deformed ice tracers
61+
set( TRPND 1 ) # set to 1 for melt pond tracers
62+
set( NTRAERO 0 ) # number of aerosol tracers
63+
# (up to max_aero in ice_domain_size.F90)
64+
# CESM uses 3 aerosol tracers
65+
set( TRBRI 1 ) # set to 1 for brine height tracer
66+
set( NBGCLYR 0 ) # number of zbgc layers
67+
68+
### File unit numbers
69+
set( NUMIN 11 ) # minimum file unit number
70+
set( NUMAX 99 ) # maximum file unit number
71+
72+
#[==============================================================================[
73+
# Project configuration #
74+
#]==============================================================================]
75+
76+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
77+
include(CMakePackageConfigHelpers)
78+
79+
# https://github.com/ACCESS-NRI/access-spack-packages/blob/d8b48b18a1400cf2a6850af0bf038af55804d92f/packages/cice5/package.py#L197C1-L198C65
80+
# note: previous deterministic and optimisation report options not included
81+
set (NCI_INTEL_FLAGS "-r8 -i4 -w -fpe0 -ftz -convert big_endian -assume byterecl -check noarg_temp_created")
82+
set (NCI_REPRO_FLAGS "-fp-model precise -fp-model source -align all")
83+
set (NCI_OPTIM_FLAGS "-g3 -O2 -axCORE-AVX2 -debug all -check none -traceback -assume buffered_io")
84+
set (NCI_DEBUG_FLAGS "-g3 -O0 -debug all -check all -no-vec -traceback -assume nobuffered_io")
85+
86+
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
87+
set(CMAKE_Fortran_FLAGS_RELEASE "-Wall -fdefault-real-8 -fdefault-double-8 -ffpe-trap=invalid,zero,overflow -fallow-argument-mismatch")
88+
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
89+
set(CMAKE_Fortran_FLAGS_RELEASE "${NCI_INTEL_FLAGS} ${NCI_REPRO_FLAGS} ${NCI_OPTIM_FLAGS}")
90+
set(CMAKE_Fortran_FLAGS_DEBUG "${NCI_INTEL_FLAGS} ${NCI_REPRO_FLAGS} ${NCI_DEBUG_FLAGS}")
91+
else()
92+
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
93+
endif()
94+
95+
add_compile_definitions(
96+
NXGLOB=${CICE_NXGLOB}
97+
NYGLOB=${CICE_NYGLOB}
98+
BLCKX=${CICE_BLCKX}
99+
BLCKY=${CICE_BLCKY}
100+
MXBLCKS=${CICE_MXBLCKS}
101+
NUMIN=${NUMIN}
102+
NUMAX=${NUMAX}
103+
TRAGE=${TRAGE}
104+
TRFY=${TRFY}
105+
TRLVL=${TRLVL}
106+
TRPND=${TRPND}
107+
NTRAERO=${NTRAERO}
108+
TRBRI=${TRBRI}
109+
NBGCLYR=${NBGCLYR}
110+
TRBGCS=${TRBGCS}
111+
NICECAT=${NICECAT}
112+
NICELYR=${NICELYR}
113+
NSNWLYR=${NSNWLYR}
114+
)
115+
116+
add_compile_definitions( gather_scatter_barrier ncdf OASIS3_MCT )
117+
118+
if (CICE_IO MATCHES PIO)
119+
add_compile_definitions(PIO)
120+
endif()
121+
122+
if(CICE_DRIVER MATCHES "auscom")
123+
add_compile_definitions(AusCOM coupled)
124+
elseif(CICE_DRIVER MATCHES "access")
125+
add_compile_defitions(ACCESS AusCOM coupled)
126+
endif()
127+
128+
#[==============================================================================[
129+
# External packages #
130+
#]==============================================================================]
131+
132+
find_package(PkgConfig REQUIRED)
133+
pkg_check_modules(OASIS3PSMILE REQUIRED IMPORTED_TARGET "oasis3-psmile.MPI1")
134+
pkg_check_modules(OASIS3MCT REQUIRED IMPORTED_TARGET "oasis3-mct")
135+
pkg_check_modules(OASIS3MPEU REQUIRED IMPORTED_TARGET "oasis3-mpeu")
136+
pkg_check_modules(OASIS3SCRIP REQUIRED IMPORTED_TARGET "oasis3-scrip")
137+
138+
find_package(MPI REQUIRED COMPONENTS Fortran)
139+
if(CICE_DRIVER MATCHES "auscom")
140+
find_package(LIBACCESSOM2)
141+
endif()
142+
143+
if(CICE_IO MATCHES "PIO" AND NOT TARGET PIO::PIO_Fortran)
144+
# Code has not been tested with versions older than 2.5.3, but probably still works fine
145+
find_package(PIO 2.5.3 REQUIRED COMPONENTS Fortran)
146+
endif()
147+
if(CICE_IO MATCHES "^(NetCDF|PIO)$" AND NOT TARGET NetCDF::NetCDF_Fortran)
148+
# Code has not been tested with versions older than 4.7.3, but probably still works fine
149+
find_package(NetCDF 4.7.3 REQUIRED Fortran)
150+
endif()
151+
152+
#[==============================================================================[
153+
# Main definitions #
154+
#]==============================================================================]
155+
156+
set(CICE_SOURCE "${CMAKE_SOURCE_DIR}/source")
157+
set(CICE_MPI "${CMAKE_SOURCE_DIR}/mpi")
158+
set(CICE_DRIVER_SOURCE "${CMAKE_SOURCE_DIR}/drivers/${CICE_DRIVER}")
159+
160+
add_executable(cice ${CICE_DRIVER_SOURCE}/CICE.F90)
161+
162+
target_link_libraries(cice
163+
PUBLIC libaccessom2::accessom2
164+
PRIVATE
165+
MPI::MPI_Fortran
166+
PkgConfig::OASIS3PSMILE PkgConfig::OASIS3MCT PkgConfig::OASIS3MPEU PkgConfig::OASIS3SCRIP
167+
# OASIS3MCT is a depedency of OASIS3PSMILE, so order matters here
168+
)
169+
170+
if(CICE_IO MATCHES "^(NetCDF|PIO)$")
171+
target_link_libraries(cice PRIVATE NetCDF::NetCDF_Fortran NetCDF::NetCDF_C)
172+
if(CICE_IO MATCHES "PIO")
173+
target_link_libraries(cice PRIVATE PIO::PIO_Fortran)
174+
endif()
175+
endif()
176+
177+
target_sources(cice PRIVATE
178+
${CICE_SOURCE}/ice_aerosol.F90
179+
${CICE_SOURCE}/ice_dyn_evp.F90
180+
${CICE_SOURCE}/ice_meltpond_lvl.F90
181+
${CICE_SOURCE}/ice_step_mod.F90
182+
${CICE_SOURCE}/ice_age.F90
183+
${CICE_SOURCE}/ice_dyn_shared.F90
184+
${CICE_SOURCE}/ice_history_mechred.F90
185+
${CICE_SOURCE}/ice_meltpond_topo.F90
186+
${CICE_SOURCE}/ice_therm_0layer.F90
187+
${CICE_SOURCE}/ice_algae.F90
188+
${CICE_SOURCE}/ice_fileunits.F90
189+
${CICE_SOURCE}/ice_history_pond.F90
190+
${CICE_SOURCE}/ice_ocean.F90
191+
${CICE_SOURCE}/ice_therm_bl99.F90
192+
${CICE_SOURCE}/ice_atmo.F90
193+
${CICE_SOURCE}/ice_history_shared.F90
194+
${CICE_SOURCE}/ice_orbital.F90
195+
${CICE_SOURCE}/ice_therm_itd.F90
196+
${CICE_SOURCE}/ice_blocks.F90
197+
${CICE_SOURCE}/ice_read_write.F90
198+
${CICE_SOURCE}/ice_therm_mushy.F90
199+
${CICE_SOURCE}/ice_brine.F90
200+
${CICE_SOURCE}/ice_firstyear.F90
201+
${CICE_SOURCE}/ice_init.F90
202+
${CICE_SOURCE}/ice_restart_driver.F90
203+
${CICE_SOURCE}/ice_therm_shared.F90
204+
${CICE_SOURCE}/ice_calendar.F90
205+
${CICE_SOURCE}/ice_flux.F90
206+
${CICE_SOURCE}/ice_itd.F90
207+
${CICE_SOURCE}/ice_restart_shared.F90
208+
${CICE_SOURCE}/ice_therm_vertical.F90
209+
${CICE_SOURCE}/ice_diagnostics.F90
210+
${CICE_SOURCE}/ice_forcing.F90
211+
${CICE_SOURCE}/ice_kinds_mod.F90
212+
${CICE_SOURCE}/ice_restart_shared.F90
213+
${CICE_SOURCE}/ice_transport_driver.F90
214+
${CICE_SOURCE}/ice_distribution.F90
215+
${CICE_SOURCE}/ice_grid.F90
216+
${CICE_SOURCE}/ice_restoring.F90
217+
${CICE_SOURCE}/ice_transport_remap.F90
218+
${CICE_SOURCE}/ice_domain.F90
219+
${CICE_SOURCE}/ice_history_bgc.F90
220+
${CICE_SOURCE}/ice_lvl.F90
221+
${CICE_SOURCE}/ice_shortwave.F90
222+
${CICE_SOURCE}/ice_zbgc.F90
223+
${CICE_SOURCE}/ice_domain_size.F90
224+
${CICE_SOURCE}/ice_history_drag.F90
225+
${CICE_SOURCE}/ice_mechred.F90
226+
${CICE_SOURCE}/ice_spacecurve.F90
227+
${CICE_SOURCE}/ice_zbgc_shared.F90
228+
${CICE_SOURCE}/ice_dyn_eap.F90
229+
${CICE_SOURCE}/ice_history.F90
230+
${CICE_SOURCE}/ice_meltpond_cesm.F90
231+
${CICE_SOURCE}/ice_state.F90
232+
${CMAKE_SOURCE_DIR}/csm_share/shr_orb_mod.F90
233+
)
234+
235+
target_sources(cice PRIVATE
236+
${CICE_MPI}/ice_boundary.F90
237+
${CICE_MPI}/ice_communicate.F90
238+
${CICE_MPI}/ice_gather_scatter.F90
239+
${CICE_MPI}/ice_global_reductions.F90
240+
${CICE_MPI}/ice_broadcast.F90
241+
${CICE_MPI}/ice_exit.F90
242+
${CICE_MPI}/ice_timers.F90
243+
)
244+
245+
if(CICE_DRIVER MATCHES "access")
246+
target_sources(cice PRIVATE
247+
${CICE_DRIVER_SOURCE}/CICE_RunMod.F90
248+
${CICE_DRIVER_SOURCE}/cpl_forcing_handler.F90
249+
${CICE_DRIVER_SOURCE}/cpl_parameters.F90
250+
${CICE_DRIVER_SOURCE}/CICE_FinalMod.F90
251+
${CICE_DRIVER_SOURCE}/cpl_interface.F90
252+
${CICE_DRIVER_SOURCE}/ice_constants.F90
253+
${CICE_DRIVER_SOURCE}/CICE_InitMod.F90
254+
${CICE_DRIVER_SOURCE}/cpl_arrays_setup.F90
255+
${CICE_DRIVER_SOURCE}/cpl_netcdf_setup.F90
256+
)
257+
elseif(CICE_DRIVER MATCHES "auscom")
258+
target_sources(cice PRIVATE
259+
${CICE_DRIVER_SOURCE}/cpl_forcing_handler.F90
260+
${CICE_DRIVER_SOURCE}/sat_vapor_pres_k_mod.F90
261+
${CICE_DRIVER_SOURCE}/CICE_FinalMod.F90
262+
${CICE_DRIVER_SOURCE}/cpl_interface.F90
263+
${CICE_DRIVER_SOURCE}/monin_obukhov_kernel.F90
264+
${CICE_DRIVER_SOURCE}/sat_vapor_pres_mod.F90
265+
${CICE_DRIVER_SOURCE}/CICE_InitMod.F90
266+
${CICE_DRIVER_SOURCE}/cpl_netcdf_setup.F90
267+
${CICE_DRIVER_SOURCE}/monin_obukhov_mod.F90
268+
${CICE_DRIVER_SOURCE}/surface_flux_mod.F90
269+
${CICE_DRIVER_SOURCE}/CICE_RunMod.F90
270+
${CICE_DRIVER_SOURCE}/cpl_parameters.F90
271+
${CICE_DRIVER_SOURCE}/ocean_rough_mod.F90
272+
${CICE_DRIVER_SOURCE}/cpl_arrays_setup.F90
273+
${CICE_DRIVER_SOURCE}/ice_constants.F90
274+
)
275+
else()
276+
message(FATAL_ERROR "CICE_DRIVER: ${CICE_DRIVER} is currently not supported by the CMake build system")
277+
endif()
278+
279+
# Select IO source files based on CICE_IO
280+
if(CICE_IO MATCHES "NetCDF")
281+
target_sources(cice PRIVATE
282+
${CMAKE_SOURCE_DIR}/io_netcdf/ice_history_write.F90
283+
${CMAKE_SOURCE_DIR}/io_netcdf/ice_restart.F90
284+
)
285+
elseif(CICE_IO MATCHES "PIO")
286+
target_sources(cice PRIVATE
287+
${CMAKE_SOURCE_DIR}/io_pio/ice_history_write.F90
288+
${CMAKE_SOURCE_DIR}/io_pio/ice_pio.F90
289+
${CMAKE_SOURCE_DIR}/io_pio/ice_restart.F90
290+
)
291+
endif()
292+
293+
#[==============================================================================[
294+
# Install #
295+
#]==============================================================================]
296+
297+
set_target_properties(cice PROPERTIES
298+
LINKER_LANGUAGE Fortran
299+
OUTPUT_NAME "cice_${CICE_DRIVER}_${CICE_NXGLOB}x${CICE_NYGLOB}_${CICE_BLCKX}x${CICE_BLCKY}.exe"
300+
)
301+
302+
install(TARGETS cice
303+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
304+
COMPONENT IO_${CICE_IO}
305+
)

0 commit comments

Comments
 (0)