From 2fa7a447cbd5bbf4112bc48e0880f0cf1eb923a2 Mon Sep 17 00:00:00 2001 From: Rahul Mahajan Date: Wed, 7 Oct 2020 10:53:46 -0400 Subject: [PATCH] Preparation for S2S cmake (#183) * replace #ifdef OPENMP with #ifdef _OPENMP * OpenMP link libraries * fix typos and missing stuff * clean up compile defs * move CCPP code generator call to FV3, where it belongs * install targets are updated * minor cleanups --- CMakeLists.txt | 246 +++++++++++------- atmos_model.F90 | 50 ++-- ccpp/config/ccpp_prebuild_config.py | 240 ++++++++--------- ccpp/driver/CCPP_driver.F90 | 6 +- gfsphysics/CMakeLists.txt | 55 ++-- gfsphysics/GFS_layer/GFS_driver.F90 | 4 +- gfsphysics/physics/GFS_debug.F90 | 15 +- io/CMakeLists.txt | 31 ++- ipd/CMakeLists.txt | 36 +-- stochastic_physics/CMakeLists.txt | 25 +- .../stochastic_physics_wrapper.F90 | 56 ++-- 11 files changed, 419 insertions(+), 345 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eaae5928c..320a1580b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,31 @@ if(CCPP) - add_definitions(-DCCPP) + + if(DEFINED CCPP_SUITES) + set(_ccpp_suites_arg "--suites=${CCPP_SUITES}") + endif() + message("Calling CCPP code generator (ccpp_prebuild.py) ... ${_ccpp_suites_arg}") + execute_process(COMMAND ${Python_EXECUTABLE} + "ccpp/framework/scripts/ccpp_prebuild.py" + "--config=ccpp/config/ccpp_prebuild_config.py" + "--builddir=${CMAKE_CURRENT_BINARY_DIR}" ${_ccpp_suites_arg} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/ccpp_prebuild.out + ERROR_FILE ${CMAKE_CURRENT_BINARY_DIR}/ccpp_prebuild.err + RESULT_VARIABLE RC) + # Check return code from ccpp_prebuild.py + if(NOT RC EQUAL 0) + message(FATAL_ERROR "An error occured while running ccpp_prebuild.py, check ${CMAKE_CURRENT_BINARY_DIR}/ccpp_prebuild.{out,err}") + endif() + # this should not be necessary; including CCPP_*.cmake here and passing + # SCHEMES, CAPS and TYPEDEFS via environment variables to CCPP build. + # CCPP should be able to directly include those three .cmake files. + include(${CMAKE_CURRENT_BINARY_DIR}/ccpp/physics/CCPP_SCHEMES.cmake) + include(${CMAKE_CURRENT_BINARY_DIR}/ccpp/physics/CCPP_CAPS.cmake) + include(${CMAKE_CURRENT_BINARY_DIR}/ccpp/physics/CCPP_TYPEDEFS.cmake) + set(ENV{CCPP_SCHEMES} "${SCHEMES}") + set(ENV{CCPP_CAPS} "${CAPS}") + set(ENV{CCPP_TYPEDEFS} "${TYPEDEFS}") + endif() add_subdirectory(cpl) @@ -10,84 +36,108 @@ add_subdirectory(io) ############################################################################### ### fv3dycore ############################################################################### +list(APPEND _fv3dycore_srcs + atmos_cubed_sphere/model/a2b_edge.F90 + atmos_cubed_sphere/model/multi_gases.F90 + atmos_cubed_sphere/model/boundary.F90 + atmos_cubed_sphere/model/dyn_core.F90 + atmos_cubed_sphere/model/fv_arrays.F90 + atmos_cubed_sphere/model/fv_control.F90 + atmos_cubed_sphere/model/fv_dynamics.F90 + atmos_cubed_sphere/model/fv_fill.F90 + atmos_cubed_sphere/model/fv_grid_utils.F90 + atmos_cubed_sphere/model/fv_mapz.F90 + atmos_cubed_sphere/model/fv_nesting.F90 + atmos_cubed_sphere/model/fv_regional_bc.F90 + atmos_cubed_sphere/model/fv_sg.F90 + atmos_cubed_sphere/model/fv_tracer2d.F90 + atmos_cubed_sphere/model/fv_update_phys.F90 + atmos_cubed_sphere/model/sw_core.F90 + atmos_cubed_sphere/model/tp_core.F90 + atmos_cubed_sphere/model/nh_core.F90 + atmos_cubed_sphere/model/nh_utils.F90 + atmos_cubed_sphere/tools/external_ic.F90 + atmos_cubed_sphere/tools/external_sst.F90 + atmos_cubed_sphere/tools/fv_diagnostics.F90 + atmos_cubed_sphere/tools/fv_eta.F90 + atmos_cubed_sphere/tools/fv_grid_tools.F90 + atmos_cubed_sphere/tools/fv_io.F90 + atmos_cubed_sphere/tools/fv_mp_mod.F90 + atmos_cubed_sphere/tools/fv_nudge.F90 + atmos_cubed_sphere/tools/fv_treat_da_inc.F90 + atmos_cubed_sphere/tools/fv_iau_mod.F90 + atmos_cubed_sphere/tools/fv_restart.F90 + atmos_cubed_sphere/tools/fv_surf_map.F90 + atmos_cubed_sphere/tools/fv_timing.F90 + atmos_cubed_sphere//tools/init_hydro.F90 + atmos_cubed_sphere/tools/sim_nc_mod.F90 + atmos_cubed_sphere/tools/sorted_index.F90 + atmos_cubed_sphere/tools/test_cases.F90 + atmos_cubed_sphere/driver/fvGFS/DYCORE_typedefs.F90 + atmos_cubed_sphere/driver/fvGFS/fv_nggps_diag.F90 + atmos_cubed_sphere/driver/fvGFS/atmosphere.F90) + if(NOT CCPP) - set(FAST_PHYSICS_SRCS_F90 atmos_cubed_sphere/model/fv_cmp.F90) + list(APPEND _fv3dycore_srcs atmos_cubed_sphere/model/fv_cmp.F90) +endif() + +add_library(fv3dycore ${_fv3dycore_srcs}) + +list(APPEND _fv3dycore_defs_private SPMD + use_WRTCOMP + GFS_PHYS + USE_GFSL63 + MOIST_CAPPA + USE_COND) + +if(MULTI_GASES) + list(APPEND _fv3dycore_defs_private MULTI_GASES) +endif() + +if(32BIT) + list(APPEND _fv3dycore_defs_private OVERLOAD_R4 + OVERLOAD_R8) +endif() + +if(CCPP) + list(APPEND _fv3dycore_defs_private CCPP) endif() -add_library( - fv3dycore - - atmos_cubed_sphere/model/a2b_edge.F90 - atmos_cubed_sphere/model/multi_gases.F90 - atmos_cubed_sphere/model/boundary.F90 - atmos_cubed_sphere/model/dyn_core.F90 - atmos_cubed_sphere/model/fv_arrays.F90 - ${FAST_PHYSICS_SRCS_F90} - atmos_cubed_sphere/model/fv_control.F90 - atmos_cubed_sphere/model/fv_dynamics.F90 - atmos_cubed_sphere/model/fv_fill.F90 - atmos_cubed_sphere/model/fv_grid_utils.F90 - atmos_cubed_sphere/model/fv_mapz.F90 - atmos_cubed_sphere/model/fv_nesting.F90 - atmos_cubed_sphere/model/fv_regional_bc.F90 - atmos_cubed_sphere/model/fv_sg.F90 - atmos_cubed_sphere/model/fv_tracer2d.F90 - atmos_cubed_sphere/model/fv_update_phys.F90 - atmos_cubed_sphere/model/sw_core.F90 - atmos_cubed_sphere/model/tp_core.F90 - atmos_cubed_sphere/model/nh_core.F90 - atmos_cubed_sphere/model/nh_utils.F90 - atmos_cubed_sphere/tools/external_ic.F90 - atmos_cubed_sphere/tools/external_sst.F90 - atmos_cubed_sphere/tools/fv_diagnostics.F90 - atmos_cubed_sphere/tools/fv_eta.F90 - atmos_cubed_sphere/tools/fv_grid_tools.F90 - atmos_cubed_sphere/tools/fv_io.F90 - atmos_cubed_sphere/tools/fv_mp_mod.F90 - atmos_cubed_sphere/tools/fv_nudge.F90 - atmos_cubed_sphere/tools/fv_treat_da_inc.F90 - atmos_cubed_sphere/tools/fv_iau_mod.F90 - atmos_cubed_sphere/tools/fv_restart.F90 - atmos_cubed_sphere/tools/fv_surf_map.F90 - atmos_cubed_sphere/tools/fv_timing.F90 - atmos_cubed_sphere//tools/init_hydro.F90 - atmos_cubed_sphere/tools/sim_nc_mod.F90 - atmos_cubed_sphere/tools/sorted_index.F90 - atmos_cubed_sphere/tools/test_cases.F90 - atmos_cubed_sphere/driver/fvGFS/DYCORE_typedefs.F90 - atmos_cubed_sphere/driver/fvGFS/fv_nggps_diag.F90 - atmos_cubed_sphere/driver/fvGFS/atmosphere.F90 -) +if(OpenMP_Fortran_FOUND) + list(APPEND _fv3dycore_defs_private OPENMP) +endif() set_property(SOURCE atmos_cubed_sphere/model/nh_utils.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FAST}") set_property(SOURCE atmos_cubed_sphere/model/fv_mapz.F90 APPEND_STRING PROPERTY COMPILE_FLAGS "${FAST}") set_target_properties(fv3dycore PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod) -target_include_directories(fv3dycore PUBLIC $) - -target_link_libraries(fv3dycore PRIVATE fms) -target_link_libraries(fv3dycore PRIVATE gfsphysics) -target_link_libraries(fv3dycore PRIVATE ipd) -target_link_libraries(fv3dycore PRIVATE esmf) -target_include_directories(fv3dycore PRIVATE atmos_cubed_sphere ${ESMF_MOD}) +target_compile_definitions(fv3dycore PRIVATE "${_fv3dycore_defs_private}") +target_include_directories(fv3dycore PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/atmos_cubed_sphere) +target_include_directories(fv3dycore INTERFACE $ + $) + +target_link_libraries(fv3dycore PUBLIC fms + gfsphysics + ipd + esmf) +if(OpenMP_Fortran_FOUND) + target_link_libraries(fv3dycore PUBLIC OpenMP::OpenMP_Fortran) +endif() ############################################################################### ### ccpp ############################################################################### if(CCPP) - add_subdirectory(ccpp) - add_subdirectory(ccpp/driver) - - add_dependencies(gfsphysics ccpp ccppphys) - add_dependencies(ccppdriver ccpp ccppphys) - add_dependencies(ccppphys ccpp) - - target_include_directories(fv3dycore PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/framework/src) - target_include_directories(fv3dycore PRIVATE ${CMAKE_BINARY_DIR}/FV3/ccpp/driver) - - target_link_libraries(ccppphys PRIVATE sp::sp_d) - target_link_libraries(ccppphys PRIVATE w3nco::w3nco_d) + add_subdirectory(ccpp) + add_subdirectory(ccpp/driver) + add_dependencies(gfsphysics ccpp ccppphys) + add_dependencies(ccppdriver ccpp ccppphys) + add_dependencies(ccppphys ccpp) + target_include_directories(fv3dycore PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/framework/src + ${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver) + target_link_libraries(ccppphys PRIVATE sp::sp_d + w3nco::w3nco_d) endif() ############################################################################### @@ -100,44 +150,51 @@ add_subdirectory(stochastic_physics) ############################################################################### ### fv3atm ############################################################################### -add_library( - fv3atm +add_library(fv3atm + atmos_model.F90 + fv3_cap.F90 + module_fv3_config.F90 + module_fcst_grid_comp.F90 + time_utils.F90) - atmos_model.F90 - fv3_cap.F90 - module_fv3_config.F90 - module_fcst_grid_comp.F90 - time_utils.F90 -) +list(APPEND _fv3atm_defs_private GFS_PHYS + INTERNAL_FILE_NML + ESMF_VERSION_MAJOR=${ESMF_VERSION_MAJOR}) set_target_properties(fv3atm PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod) -target_include_directories(fv3atm PUBLIC $) +target_include_directories(fv3atm INTERFACE $ + $) if(CCPP) - target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod) - set(CCPP_LIBRARIES ccppdriver ccppphys ccpp) - add_dependencies(fv3atm ccppdriver ccppphys ccpp) - target_link_libraries(fv3atm PUBLIC ccppdriver ccppphys ccpp) + list(APPEND _fv3atm_defs_private CCPP) + target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod) + set(CCPP_LIBRARIES ccppdriver ccppphys ccpp) + add_dependencies(fv3atm ccppdriver ccppphys ccpp) + target_link_libraries(fv3atm PUBLIC ccppdriver ccppphys ccpp) endif() target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/stochastic_physics) -target_compile_definitions(fv3atm PRIVATE -DESMF_VERSION_MAJOR=${ESMF_VERSION_MAJOR}) - -target_link_libraries(fv3atm PUBLIC fms) -target_link_libraries(fv3atm PUBLIC cpl) -target_link_libraries(fv3atm PUBLIC gfsphysics) -target_link_libraries(fv3atm PUBLIC ipd) -target_link_libraries(fv3atm PUBLIC io) -target_link_libraries(fv3atm PUBLIC fv3dycore) -target_link_libraries(fv3atm PUBLIC stochastic_physics) -target_link_libraries(fv3atm PUBLIC stochastic_physics_wrapper) - -target_link_libraries(fv3atm PUBLIC - nemsio::nemsio w3emc::w3emc_d w3nco::w3nco_d sp::sp_d bacio::bacio_4) +target_compile_definitions(fv3atm PRIVATE "${_fv3atm_defs_private}") + +target_link_libraries(fv3atm PUBLIC fv3dycore + cpl + io + stochastic_physics + stochastic_physics_wrapper) + +target_link_libraries(fv3atm PUBLIC nemsio::nemsio + w3emc::w3emc_d + w3nco::w3nco_d + sp::sp_d + bacio::bacio_4 + esmf) + if(INLINE_POST) target_link_libraries(fv3atm PUBLIC nceppost::nceppost) endif() -target_link_libraries(fv3atm PUBLIC esmf) +if(OpenMP_Fortran_FOUND) + target_link_libraries(fv3atm PUBLIC OpenMP::OpenMP_Fortran) +endif() ############################################################################### ### Install @@ -147,9 +204,8 @@ install( EXPORT fv3atm-config LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod DESTINATION ${CMAKE_INSTALL_PREFIX}) install(EXPORT fv3atm-config - DESTINATION lib/cmake -) - + DESTINATION lib/cmake) diff --git a/atmos_model.F90 b/atmos_model.F90 index 81589c3864..860079949c 100644 --- a/atmos_model.F90 +++ b/atmos_model.F90 @@ -131,7 +131,7 @@ module atmos_model_mod ! type atmos_data_type - integer :: axes(4) ! axis indices (returned by diag_manager) for the atmospheric grid + integer :: axes(4) ! axis indices (returned by diag_manager) for the atmospheric grid ! (they correspond to the x, y, pfull, phalf axes) integer, pointer :: pelist(:) =>null() ! pelist where atmosphere is running. integer :: layout(2) ! computer task laytout @@ -152,7 +152,7 @@ module atmos_model_mod type(time_type) :: Time ! current time type(time_type) :: Time_step ! atmospheric time step. type(time_type) :: Time_init ! reference time. - type(grid_box_type) :: grid ! hold grid information needed for 2nd order conservative flux exchange + type(grid_box_type) :: grid ! hold grid information needed for 2nd order conservative flux exchange type(IPD_diag_type), pointer, dimension(:) :: Diag end type atmos_data_type ! to calculate gradient on cubic sphere grid. @@ -235,7 +235,7 @@ module atmos_model_mod ! atmospheric tendencies for dynamics, radiation, vertical diffusion of ! momentum, tracers, and heat/moisture. For heat/moisture only the ! downward sweep of the tridiagonal elimination is performed, hence -! the name "_down". +! the name "_down". ! !