Skip to content

Commit

Permalink
Use OPENMP instead of OpenMP_Fortran_FOUND, cleanup compiler flags (u…
Browse files Browse the repository at this point in the history
…fs-community#286)

* Simplify ccpp/data/CMakeLists.txt and ccpp/driver/CMakeLists.txt
* Use OPENMP instead of OpenMP_Fortran_FOUND
  • Loading branch information
DusanJovic-NOAA authored Apr 22, 2021
1 parent 70b442e commit bfb8da5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 114 deletions.
76 changes: 44 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ 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()

add_subdirectory(cpl)
add_subdirectory(io)

###############################################################################
### fv3dycore
###############################################################################
Expand Down Expand Up @@ -94,29 +91,31 @@ else()
set(DYN32 OFF CACHE BOOL "Disable support for 32bit fast physics in CCPP")
endif()

list(APPEND _fv3dycore_defs_private CCPP)

if(OpenMP_Fortran_FOUND)
if(OPENMP)
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 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>
$<INSTALL_INTERFACE:mod>)

target_compile_definitions(fv3dycore PRIVATE "${_fv3dycore_defs_private}")

# So much for being consistent:
# atmos_cubed_sphere/tools/fv_diagnostics.F90: #include <fv_diagnostics.h>
# atmos_cubed_sphere/tools/fv_eta.F90: #include <tools/fv_eta.h>
target_include_directories(fv3dycore PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/atmos_cubed_sphere
${CMAKE_CURRENT_SOURCE_DIR}/atmos_cubed_sphere/tools
${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod)
target_include_directories(fv3dycore INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>
$<INSTALL_INTERFACE:mod>)
${CMAKE_CURRENT_SOURCE_DIR}/atmos_cubed_sphere/tools
${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod)

target_link_libraries(fv3dycore PUBLIC fms
ccppphys
ccppdata
esmf)
if(OpenMP_Fortran_FOUND)
if(OPENMP)
target_link_libraries(fv3dycore PUBLIC OpenMP::OpenMP_Fortran)
endif()

Expand All @@ -137,47 +136,60 @@ target_include_directories(fv3dycore PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/fr
target_link_libraries(ccppphys PUBLIC sp::sp_d
w3nco::w3nco_d)

###############################################################################
### stochastic_physics
###############################################################################
# When specifying an out-of-tree source a binary directory must be explicitly specified.
#add_subdirectory(../stochastic_physics stochastic_physics)
add_subdirectory(stochastic_physics)

###############################################################################
### fv3atm
###############################################################################
if(INLINE_POST)
set(POST_SRC io/inline_post.F90 io/post_nems_routines.F90 io/post_gfs.F90 io/post_regional.F90)
else()
set(POST_SRC io/inline_post_stub.F90)
list(APPEND _fv3atm_defs_private NO_INLINE_POST)
endif()

if(NOT PARALLEL_NETCDF)
list(APPEND _fv3atm_defs_private NO_PARALLEL_NETCDF)
endif()

add_library(fv3atm
atmos_model.F90
fv3_cap.F90
module_fv3_config.F90
module_fcst_grid_comp.F90
time_utils.F90)
stochastic_physics/stochastic_physics_wrapper.F90
cpl/module_cplfields.F90
cpl/module_cap_cpl.F90
io/ffsync.F90
io/FV3GFS_io.F90
io/module_write_nemsio.F90
io/module_write_netcdf.F90
io/module_write_netcdf_parallel.F90
io/module_fv3_io_def.F90
io/module_write_internal_state.F90
io/module_wrt_grid_comp.F90
${POST_SRC}
)

list(APPEND _fv3atm_defs_private GFS_PHYS
INTERNAL_FILE_NML
use_WRTCOMP
ESMF_VERSION_MAJOR=${ESMF_VERSION_MAJOR})

target_compile_definitions(fv3atm PRIVATE "${_fv3atm_defs_private}")

set_target_properties(fv3atm PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
target_include_directories(fv3atm INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>
$<INSTALL_INTERFACE:mod>)

list(APPEND _fv3atm_defs_private CCPP)
target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/physics
${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod)
${CMAKE_CURRENT_BINARY_DIR}/ccpp/driver/mod
${CMAKE_CURRENT_BINARY_DIR}/../stochastic_physics)
set(CCPP_LIBRARIES ccppdriver ccppdata ccppphys ccpp)
add_dependencies(fv3atm ccppdriver ccppdata ccppphys ccpp)
target_link_libraries(fv3atm PUBLIC ccppdriver ccppdata ccppphys ccpp)

target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/stochastic_physics)
target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../stochastic_physics)
target_compile_definitions(fv3atm PRIVATE "${_fv3atm_defs_private}")
add_dependencies(fv3atm ${CCPP_LIBRARIES})

target_link_libraries(fv3atm PUBLIC fv3dycore
cpl
io
${CCPP_LIBRARIES}
stochastic_physics
stochastic_physics_wrapper)
fms)

target_link_libraries(fv3atm PUBLIC nemsio::nemsio
w3emc::w3emc_d
Expand All @@ -190,15 +202,15 @@ if(INLINE_POST)
target_link_libraries(fv3atm PUBLIC upp::upp)
endif()

if(OpenMP_Fortran_FOUND)
if(OPENMP)
target_link_libraries(fv3atm PUBLIC OpenMP::OpenMP_Fortran)
endif()

###############################################################################
### Install
###############################################################################
install(
TARGETS fv3atm fv3dycore io ${CCPP_LIBRARIES} cpl stochastic_physics_wrapper
TARGETS fv3atm fv3dycore ${CCPP_LIBRARIES}
EXPORT fv3atm-config
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
Expand Down
8 changes: 2 additions & 6 deletions ccpp/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ endif()

message ("Force 64 bits in ccpp/data")
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
if(REPRO)
string (REPLACE "-i4 -real-size 32" "-i4 -real-size 64" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
else()
string (REPLACE "-i4 -real-size 32" "-i4 -real-size 64 -no-prec-div -no-prec-sqrt" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
endif()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -real-size 64")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8")
endif()
Expand All @@ -35,7 +31,7 @@ add_library(
target_link_libraries(ccppdata PUBLIC ccpp)
target_link_libraries(ccppdata PUBLIC ccppphys)

if(OpenMP_Fortran_FOUND)
if(OPENMP)
target_link_libraries(ccppdata PUBLIC OpenMP::OpenMP_Fortran)
endif()

Expand Down
8 changes: 2 additions & 6 deletions ccpp/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ endif()

message ("Force 64 bits in ccpp/driver")
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
if(REPRO)
string (REPLACE "-i4 -real-size 32" "-i4 -real-size 64" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
else()
string (REPLACE "-i4 -real-size 32" "-i4 -real-size 64 -no-prec-div -no-prec-sqrt" CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
endif()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -real-size 64")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8")
endif()
Expand Down Expand Up @@ -42,7 +38,7 @@ target_link_libraries(ccppdriver PUBLIC ccpp)
target_link_libraries(ccppdriver PUBLIC ccppphys)
target_link_libraries(ccppdriver PUBLIC ccppdata)

if(OpenMP_Fortran_FOUND)
if(OPENMP)
target_link_libraries(ccppdriver PUBLIC OpenMP::OpenMP_Fortran)
endif()

Expand Down
11 changes: 0 additions & 11 deletions cpl/CMakeLists.txt

This file was deleted.

46 changes: 0 additions & 46 deletions io/CMakeLists.txt

This file was deleted.

13 changes: 0 additions & 13 deletions stochastic_physics/CMakeLists.txt

This file was deleted.

0 comments on commit bfb8da5

Please sign in to comment.