-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
472 lines (443 loc) · 15.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# ==============================================================================
# This file is part of GMCORE since 2019.
#
# GMCORE is a dynamical core for atmospheric model.
#
# GMCORE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY. You may contact authors for helping or cooperation.
# ==============================================================================
cmake_minimum_required(VERSION 3.5)
project(gmcore LANGUAGES Fortran C)
option(R4 "Use single precision" OFF)
option(R16 "Use quadruple precision" OFF)
option(ENSURE_ORDER "Ensure computation order in parallel" OFF)
option(USE_GPTL "Use GPTL to profile performance" OFF)
option(USE_BULK_AERO "Use bulk aerosol model" ON)
option(USE_MODAL_AERO "Use modal aerosol model" OFF)
option(USE_CHEM "Use chemistry" OFF)
option(USE_CAM "Use CAM physics" OFF)
option(USE_CLM "Use CLM land model" OFF)
option(OUTPUT_H1_DTEND "Output each dynamics tendency in h1 file" OFF)
if (R4)
add_definitions(-DREAL_KIND=4)
set(CPPFLAGS ${CPPFLAGS} -DREAL_KIND=4)
message(STATUS "Use single precision.")
elseif (R16)
add_definitions(-DREAL_KIND=16)
set(CPPFLAGS ${CPPFLAGS} -DREAL_KIND=16)
message(STATUS "Use quadruple precision.")
else ()
add_definitions(-DREAL_KIND=8)
endif ()
if (ENSURE_ORDER)
add_definitions(-DENSURE_ORDER)
set(CPPFLAGS ${CPPFLAGS} -DENSURE_ORDER)
message(STATUS "Ensure computation order in parallel.")
endif ()
if (OUTPUT_H1_DTEND)
add_definitions(-DOUTPUT_H1_DTEND)
endif ()
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
add_definitions(-DFC_IS_GNU)
list(APPEND fortran_flags
-ffree-line-length-none
-fno-range-check
-ffpe-summary=none
)
if (CMAKE_Fortran_COMPILER_VERSION GREATER 10)
list(APPEND fortran_flags
-fallow-argument-mismatch
-fallow-invalid-boz
)
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND fortran_flags -O0 -fcheck=all -g -fbacktrace)
else ()
list(APPEND fortran_flags -Ofast)
endif ()
# FIXME: OpenMP causes sigmentation faults.
# list(APPEND fortran_flags -fopenmp)
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
add_definitions(-DFC_IS_INTEL)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
list(APPEND fortran_flags
-no-wrap-margin
-O0
-check bounds
-g
-traceback
-fp-model precise
)
else ()
list(APPEND fortran_flags
-no-wrap-margin
-O3
-align array64byte
# -qopenmp
# -fp-model precise
)
# FIXME: OpenMP causes sigmentation faults when using ifx compiler.
endif ()
endif ()
find_package(MPI)
if (DEFINED ENV{NETCDF} AND (NOT DEFINED ENV{NETCDF_ROOT}))
set(ENV{NETCDF_ROOT} $ENV{NETCDF})
endif ()
if (DEFINED ENV{NETCDF_ROOT})
include_directories("$ENV{NETCDF_ROOT}/include")
link_directories("$ENV{NETCDF_ROOT}/lib")
else ()
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_search_module(NETCDF REQUIRED netcdf)
if (NETCDF_FOUND)
include_directories(${NETCDF_INCLUDEDIR})
link_directories(${NETCDF_LIBDIR})
else ()
message(FATAL_ERROR "Pkg-config could not find netcdf library!")
endif ()
else ()
message(FATAL_ERROR "Unable to find pkg-config library!")
endif ()
endif ()
set(EXTERNAL_LIBS netcdff netcdf)
if (DEFINED ENV{GPTL} AND (NOT DEFINED ENV{GPTL_ROOT}))
set(ENV{GPTL_ROOT} $ENV{GPTL})
endif ()
if (USE_GPTL AND DEFINED ENV{GPTL_ROOT})
message(STATUS "Found GPTL in $ENV{GPTL_ROOT}.")
add_definitions(-DHAS_GPTL)
set(HAS_GPTL TRUE)
include_directories("$ENV{GPTL_ROOT}/include")
link_directories("$ENV{GPTL_ROOT}/lib")
list(APPEND EXTERNAL_LIBS gptlf gptl)
endif ()
if (DEFINED ENV{PAPI} AND (NOT DEFINED ENV{PAPI_ROOT}))
set(ENV{PAPI_ROOT} $ENV{PAPI})
endif ()
if (DEFINED ENV{PAPI_ROOT})
message(STATUS "Found PAPI in $ENV{PAPI_ROOT}.")
add_definitions(-DHAS_PAPI)
set(HAS_PAPI TRUE)
include_directories("$ENV{PAPI_ROOT}/include")
link_directories("$ENV{PAPI_ROOT}/lib")
list(APPEND EXTERNAL_LIBS papi)
endif ()
if (DEFINED ENV{PIO} AND (NOT DEFINED ENV{PIO_ROOT}))
set(ENV{PIO_ROOT} $ENV{PIO})
endif ()
if (USE_CAM AND DEFINED ENV{PIO_ROOT})
message(STATUS "Found PIO in $ENV{PIO_ROOT}.")
add_definitions(-DHAS_PIO)
set(HAS_PIO TRUE)
include_directories("$ENV{PIO_ROOT}/include")
link_directories("$ENV{PIO_ROOT}/lib")
list(APPEND EXTERNAL_LIBS piof pioc)
endif ()
if (DEFINED ENV{LAPACK} AND (NOT DEFINED ENV{LAPACK_ROOT}))
set(ENV{LAPACK_ROOT} $ENV{LAPACK})
endif ()
if (DEFINED ENV{LAPACK_ROOT})
message(STATUS "Found LAPACK in $ENV{LAPACK_ROOT}.")
add_definitions(-DHAS_LAPACK)
set(HAS_LAPACK TRUE)
include_directories("$ENV{LAPACK_ROOT}/include")
if (EXISTS "$ENV{LAPACK_ROOT}/lib")
link_directories("$ENV{LAPACK_ROOT}/lib")
endif ()
if (EXISTS "$ENV{LAPACK_ROOT}/lib64")
link_directories("$ENV{LAPACK_ROOT}/lib64")
endif ()
list(APPEND EXTERNAL_LIBS lapack blas)
endif ()
if (DEFINED ENV{ESMF} AND (NOT DEFINED ENV{ESMF_ROOT}))
set(ENV{ESMF_ROOT} $ENV{ESMF})
endif ()
if (HAS_LAPACK AND DEFINED ENV{ESMF_ROOT})
message(STATUS "Found ESMF in $ENV{ESMF_ROOT}.")
add_definitions(-DHAS_ESMF)
set(HAS_ESMF TRUE)
include_directories("$ENV{ESMF_ROOT}/include")
link_directories("$ENV{ESMF_ROOT}/lib")
list(APPEND EXTERNAL_LIBS esmf)
endif ()
if (DEFINED ENV{MCT} AND (NOT DEFINED ENV{MCT_ROOT}))
set(ENV{MCT_ROOT} $ENV{MCT})
endif ()
if (DEFINED ENV{MCT_ROOT})
message(STATUS "Found MCT in $ENV{MCT_ROOT}.")
add_definitions(-DHAS_MCT)
set(HAS_MCT TRUE)
include_directories("$ENV{MCT_ROOT}/include")
link_directories("$ENV{MCT_ROOT}/lib")
list(APPEND EXTERNAL_LIBS mct mpeu)
endif ()
if (DEFINED ENV{ECCODES} AND (NOT DEFINED ENV{ECCODES_ROOT}))
set(ENV{ECCODES_ROOT} $ENV{ECCODES})
endif ()
if (DEFINED ENV{ECCODES_ROOT})
message(STATUS "Found EcCodes in $ENV{ECCODES_ROOT}.")
add_definitions(-DHAS_ECCODES)
include_directories("$ENV{ECCODES_ROOT}/include")
if (EXISTS "$ENV{ECCODES_ROOT}/lib")
link_directories("$ENV{ECCODES_ROOT}/lib")
endif ()
if (EXISTS "$ENV{ECCODES_ROOT}/lib64")
link_directories("$ENV{ECCODES_ROOT}/lib64")
endif ()
list(APPEND EXTERNAL_LIBS eccodes_f90)
else ()
find_package(ECCODES QUIET)
if (ECCODES_FOUND)
list(APPEND EXTERNAL_LIBS eccodes_f90)
else ()
message(WARNING "Unable to find EcCodes!")
endif ()
endif ()
if (DEFINED ENV{MKLROOT})
add_definitions(-DHAS_MKL)
include_directories("$ENV{MKLROOT}/include")
link_directories("$ENV{MKLROOT}/lib")
elseif (DEFINED ENV{MKL_INC} AND DEFINED ENV{MKL_LIB})
add_definitions(-DHAS_MKL)
include_directories("$ENV{MKL_INC}")
link_directories("$ENV{MKL_LIB}")
endif ()
if (HAS_MKL)
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
list(APPEND EXTERNAL_LIBS lapack64)
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
if (CMAKE_Fortran_COMPILER_VERSION GREATER 2021.1)
list(APPEND fortran_flags -qmkl=sequential)
else ()
list(APPEND fortran_flags -mkl=sequential)
endif ()
endif ()
endif ()
string(REPLACE ";" " " CMAKE_Fortran_FLAGS "${fortran_flags}")
add_subdirectory(lib/container)
add_subdirectory(lib/datetime)
add_subdirectory(lib/string)
add_subdirectory(lib/fiona)
add_subdirectory(lib/flogger)
if (EXISTS ${PROJECT_SOURCE_DIR}/lib/rrtmgp/CMakeLists.txt)
message(STATUS "Build RRTMGP radiation codes.")
add_subdirectory(lib/rrtmgp)
list(APPEND EXTERNAL_LIBS rrtmgp)
set(HAS_RRTMGP TRUE)
endif ()
if (EXISTS ${PROJECT_SOURCE_DIR}/lib/noahmp/CMakeLists.txt)
message(STATUS "Build NoahMP land codes.")
add_subdirectory(lib/noahmp)
list(APPEND EXTERNAL_LIBS noahmp)
set(HAS_NOAHMP TRUE)
endif ()
add_library(gmcore)
target_sources(gmcore PRIVATE
lib/quadpack.f90
src/dynamics/adv/adv_batch_mod.F90
src/dynamics/adv/adv_mod.F90
src/dynamics/adv/ffsl_mod.F90
src/dynamics/adv/limiter_mod.F90
src/dynamics/adv/ppm_mod.F90
src/dynamics/adv/tvd_mod.F90
src/dynamics/adv/upwind_mod.F90
src/dynamics/adv/weno_mod.F90
src/dynamics/damp/damp_mod.F90
src/dynamics/damp/div_damp_mod.F90
src/dynamics/damp/vor_damp_mod.F90
src/dynamics/damp/laplace_damp_mod.F90
src/dynamics/damp/smag_damp_mod.F90
src/dynamics/dynamics_types_mod.F90
src/dynamics/filter_mod.F90
src/dynamics/filter_types_mod.F90
src/dynamics/gmcore_mod.F90
src/dynamics/interp_mod.F90
src/dynamics/operators_mod.F90
src/dynamics/nh_mod.F90
src/dynamics/pgf/pgf_lin97_mod.F90
src/dynamics/pgf/pgf_ptb_mod.F90
src/dynamics/pgf/pgf_mod.F90
src/dynamics/pgf/pgf_swm_mod.F90
src/dynamics/time_schemes_mod.F90
src/dynamics/tracer_mod.F90
src/dynamics/tracer_types_mod.F90
src/dynamics/vert_coord/hybrid_coord_ecmwf_mod.F90
src/dynamics/vert_coord/hybrid_coord_mod.F90
src/dynamics/vert_coord/hybrid_coord_ncep_mod.F90
src/dynamics/vert_coord/hybrid_coord_test_mod.F90
src/dynamics/vert_coord/mars_vert_coord_mod.F90
src/dynamics/vert_coord/sigma_coord_mod.F90
src/dynamics/vert_coord/smooth_coord_mod.F90
src/dynamics/vert_coord/vert_coord_mod.F90
src/dynamics/vert_coord/wrf_vert_coord_mod.F90
src/meshes/latlon/latlon_mesh_mod.F90
src/meshes/latlon/latlon_halo_mod.F90
src/meshes/latlon/latlon_field_types_mod.F90
src/meshes/latlon/latlon_operators_mod.F90
src/meshes/latlon/latlon_parallel_types_mod.F90
src/meshes/latlon/latlon_parallel_zonal_mod.F90
src/meshes/latlon/latlon_parallel_global_mod.F90
src/meshes/latlon/latlon_parallel_mod.F90
src/meshes/latlon/latlon_decomp_mod.F90
src/meshes/latlon/latlon_interp_mod.F90
src/physics/dp_coupling_mod.F90
src/physics/physics_mod.F90
src/physics/physics_mesh_mod.F90
src/physics/physics_types_mod.F90
src/physics/simple_physics/simple_physics_v6.f90
src/physics/simple_physics/simple_physics_types_mod.F90
src/physics/simple_physics/simple_physics_objects_mod.F90
src/physics/simple_physics/simple_physics_output_mod.F90
src/physics/simple_physics/simple_physics_driver_mod.F90
src/physics/test_forcing_mod.F90
src/physics/mars_nasa/mars_nasa_const_mod.F90
src/physics/mars_nasa/mars_nasa_namelist_mod.F90
src/physics/mars_nasa/mars_nasa_tracers_mod.F90
src/physics/mars_nasa/mars_nasa_physics_types_mod.F90
src/physics/mars_nasa/mars_nasa_objects_mod.F90
src/physics/mars_nasa/mars_orbit_mod.F90
src/physics/mars_nasa/mars_nasa_spectra_mod.F90
src/physics/mars_nasa/mars_nasa_optics_mod.F90
src/physics/mars_nasa/mars_nasa_solar_mod.F90
src/physics/mars_nasa/mars_nasa_rad_kcoef_mod.F90
src/physics/mars_nasa/mars_nasa_rad_mod.F90
src/physics/mars_nasa/mars_nasa_sfc_mod.F90
src/physics/mars_nasa/mars_nasa_pbl_mod.F90
src/physics/mars_nasa/mars_nasa_lsm_mod.F90
src/physics/mars_nasa/mars_nasa_mp_mod.F90
src/physics/mars_nasa/mars_nasa_physics_output_mod.F90
src/physics/mars_nasa/mars_nasa_physics_driver_mod.F90
src/prepare/latlon/latlon_bkg_mod.F90
src/prepare/latlon/latlon_topo_mod.F90
src/prepare/prepare_mod.F90
src/prepare/readers/era5_reader_mod.F90
src/prepare/readers/cam_reader_mod.F90
src/prepare/readers/fnl_reader_mod.F90
src/prepare/readers/openmars_reader_mod.F90
src/prepare/readers/topo_reader_mod.F90
src/prepare/ref_mod.F90
src/prepare/vert_interp_mod.F90
src/tests/aquaplanet_test_mod.F90
src/tests/adv/dcmip12_test_mod.F90
src/tests/adv/deform_test_mod.F90
src/tests/adv/moving_vortices_test_mod.F90
src/tests/adv/solid_rotation_test_mod.F90
src/tests/baroclinic_wave_test_mod.F90
src/tests/dcmip31_test_mod.F90
src/tests/held_suarez_test_mod.F90
src/tests/ksp15_test_mod.F90
src/tests/mars_cold_run_mod.F90
src/tests/mountain_wave_test_mod.F90
src/tests/rossby_haurwitz_wave_3d_test_mod.F90
src/tests/steady_state_pgf_test_mod.F90
src/tests/steady_state_test_mod.F90
src/tests/swm/cross_pole_flow_test_mod.F90
src/tests/swm/jet_zonal_flow_test_mod.F90
src/tests/swm/mountain_zonal_flow_test_mod.F90
src/tests/swm/rossby_haurwitz_wave_test_mod.F90
src/tests/swm/shallow_water_waves_test_mod.F90
src/tests/swm/splash_test_mod.F90
src/tests/swm/steady_geostrophic_flow_test_mod.F90
src/tests/swm/vortex_erosion_test_mod.F90
src/tests/tropical_cyclone_test_mod.F90
src/tests/colliding_modons_test_mod.F90
src/utils/accum_mod.F90
src/utils/regrid_mod.F90
src/utils/block_mod.F90
src/utils/const_mod.F90
src/utils/debug_mod.F90
src/utils/formula_mod.F90
src/utils/gas_mod.F90
src/utils/history_mod.F90
src/utils/initial_mod.F90
src/utils/math_mod.F90
src/utils/namelist_mod.F90
src/utils/perf_mod.F90
src/utils/process_mod.F90
src/utils/restart_mod.F90
src/utils/sphere_geometry_mod.F90
src/utils/time_mod.F90
src/utils/time_mod.F90
src/utils/tridiag_mkl_mod.F90
src/utils/tridiag_mod.F90
src/utils/tridiag_spk_mod.F90
)
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
if (CMAKE_Fortran_COMPILER_VERSION GREATER 8)
target_sources(gmcore PRIVATE
src/meshes/cubed_sphere/cubed_sphere_panel_mod.F90
src/meshes/cubed_sphere/cubed_sphere_mesh_mod.F90
src/meshes/cubed_sphere/cubed_sphere_array_mod.F90
)
endif ()
else ()
target_sources(gmcore PRIVATE
src/meshes/cubed_sphere/cubed_sphere_panel_mod.F90
src/meshes/cubed_sphere/cubed_sphere_mesh_mod.F90
src/meshes/cubed_sphere/cubed_sphere_array_mod.F90
)
endif ()
if (HAS_RRTMGP AND HAS_NOAHMP)
target_sources(gmcore PRIVATE
src/physics/wrf/wrf_namelist_mod.F90
src/physics/wrf/wrf_tracers_mod.F90
src/physics/wrf/wrf_physics_types_mod.F90
src/physics/wrf/wrf_objects_mod.F90
src/physics/wrf/lsm_noahmp_types_mod.F90
src/physics/wrf/lsm_noahmp_driver_mod.F90
src/physics/wrf/lsm_driver_mod.F90
src/physics/wrf/pbl_ysu_mod.F90
src/physics/wrf/pbl_driver_mod.F90
src/physics/wrf/rad_rrtmgp_types_mod.F90
src/physics/wrf/rad_rrtmgp_mod.F90
)
add_definitions(-DHAS_WRF)
endif ()
target_link_libraries(gmcore fortran_container fortran_datetime fiona flogger ${EXTERNAL_LIBS})
if (USE_CAM AND HAS_PIO AND HAS_LAPACK AND HAS_ESMF AND HAS_MCT)
message(STATUS "PIO, LAPACK, ESMF, and MCT are found. Building CAM physics and chemistry.")
include_directories(src/physics/cam/include)
add_definitions(-DSPMD)
add_definitions(-DUSE_CSM_SHARE)
add_definitions(-DPCNST=33)
add_definitions(-DN_RAD_CNST=15)
add_definitions(-DHAVE_IEEE_ARITHMETIC)
add_definitions(-DUSE_CONTIGUOUS=)
add_definitions(-DCLUBB_SGS)
add_definitions(-DCLUBB_CAM)
add_definitions(-DCLUBB_REAL_TYPE=8)
set(USE_CLUBB_SGS ON)
add_definitions(-DMODAL_AERO_3MODE)
add_definitions(-DHAS_CAM)
add_subdirectory(src/physics/cam)
add_subdirectory(src/chemistry)
else ()
message(WARNING "PIO, LAPACK, ESMF, and MCT are not found. Skipping CAM physics and chemistry.")
message(STATUS "HAS_PIO = ${HAS_PIO}")
message(STATUS "HAS_LAPACK = ${HAS_LAPACK}")
message(STATUS "HAS_ESMF = ${HAS_ESMF}")
message(STATUS "HAS_MCT = ${HAS_MCT}")
endif ()
add_executable(gmcore_prepare.exe src/drivers/gmcore_prepare.F90)
target_link_libraries(gmcore_prepare.exe gmcore)
add_executable(gmcore_swm_driver.exe src/drivers/gmcore_swm_driver.F90)
target_link_libraries(gmcore_swm_driver.exe gmcore)
add_executable(gmcore_driver.exe src/drivers/gmcore_driver.F90)
target_link_libraries(gmcore_driver.exe gmcore)
add_executable(gmcore_adv_driver.exe src/drivers/gmcore_adv_driver.F90)
target_link_libraries(gmcore_adv_driver.exe gmcore)
if (HAS_ESMF AND USE_CLM)
add_subdirectory(src/components/lnd/clm)
add_executable(gmcore_esmf_driver.exe
src/coupler/esmf/comp_wrapper_mod.F90
src/coupler/esmf/atm_comp_mod.F90
src/coupler/esmf/lnd_comp_mod.F90
src/coupler/esmf/ocn_comp_mod.F90
src/coupler/esmf/ice_comp_mod.F90
src/coupler/esmf/cpl_comp_mod.F90
src/drivers/gmcore_esmf_driver.F90
)
target_link_libraries(gmcore_esmf_driver.exe gmcore clm)
endif ()