Skip to content
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

Allow single and double precision libraries in a single build. #70

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ ecwam_find_python_mods()

### Set third party libraries

if( HAVE_SINGLE_PRECISION )
set( prec sp )
else()
set( prec dp )
endif()
ecbuild_add_option( FEATURE DOUBLE_PRECISION
DEFAULT ON
DESCRIPTION "Support for Double Precision" )

ecbuild_add_option( FEATURE SINGLE_PRECISION
DEFAULT ON
DESCRIPTION "Support for Single Precision" )
set( HAVE_dp ${HAVE_DOUBLE_PRECISION} )
set( HAVE_sp ${HAVE_SINGLE_PRECISION} )


unset( OpenMP_Fortran_LIBRARIES )
if( HAVE_OMP )
Expand Down
101 changes: 56 additions & 45 deletions src/ecwam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ list( APPEND ecwam_srcs
sdice.F90
sdice1.F90
sdice2.F90
sdice3.F90
icebreak_modify_attenuation.F90
sdice3.F90
icebreak_modify_attenuation.F90
ibrmemout.F90
se10mean.F90
sebtmean.F90
Expand Down Expand Up @@ -441,41 +441,48 @@ if( HAVE_ACC )
set( LIBRARY_TYPE STATIC )
endif()

ecbuild_add_library(
TARGET ${ecwam}
TYPE ${LIBRARY_TYPE}
SOURCES ${ecwam_srcs}
PUBLIC_LIBS fiat parkind_${prec} ${ecwam}_intfb
${MPI_Fortran_LIBRARIES}
${${PNAME}_OCEANMODEL_LIBRARIES}
field_api_${prec}
PRIVATE_LIBS eccodes_f90
${MULTIO_LIBRARIES}
${OpenMP_Fortran_LIBRARIES}
$<${HAVE_ECFLOW}:ecflow_lightf>
$<${HAVE_ACC}:OpenACC::OpenACC_Fortran>
PUBLIC_INCLUDES $<INSTALL_INTERFACE:include>
PRIVATE_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE_DEFINITIONS ${ECWAM_PRIVATE_DEFINITIONS} $<${HAVE_CUDA}:WAM_HAVE_CUDA>
PUBLIC_DEFINITIONS ${ECWAM_DEFINITIONS}
)
foreach( prec sp dp )
if( HAVE_${prec} )

ecwam_target_fortran_module_directory(
TARGET ${ecwam}
MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/module/${ecwam}
INSTALL_DIRECTORY module/${ecwam}
)
ecbuild_add_library(
TARGET ${ecwam}_${prec}
TYPE ${LIBRARY_TYPE}
SOURCES ${ecwam_srcs}
PUBLIC_LIBS fiat parkind_${prec} ${ecwam}_intfb
${MPI_Fortran_LIBRARIES}
${${PNAME}_OCEANMODEL_LIBRARIES}
field_api_${prec}
PRIVATE_LIBS eccodes_f90
${MULTIO_LIBRARIES}
${OpenMP_Fortran_LIBRARIES}
$<${HAVE_ECFLOW}:ecflow_lightf>
$<${HAVE_ACC}:OpenACC::OpenACC_Fortran>
PUBLIC_INCLUDES $<INSTALL_INTERFACE:include>
PRIVATE_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE_DEFINITIONS ${ECWAM_PRIVATE_DEFINITIONS} $<${HAVE_CUDA}:WAM_HAVE_CUDA>
PUBLIC_DEFINITIONS ${ECWAM_DEFINITIONS}
)

if( HAVE_ACC AND CMAKE_Fortran_COMPILER_ID MATCHES "PGI|NVHPC")
target_link_options( ${ecwam} INTERFACE SHELL:${OpenACC_Fortran_FLAGS} )
target_compile_options( ${ecwam} PRIVATE "-gpu=maxregcount:168,fastmath" )
endif()
ecwam_target_fortran_module_directory(
TARGET ${ecwam}_${prec}
MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/module/${ecwam}_${prec}
INSTALL_DIRECTORY module/${ecwam}_${prec}
)

if( HAVE_CUDA )
target_link_options( ${ecwam} PUBLIC "-cuda;-gpu=pinned" )
endif()
if( HAVE_ACC AND CMAKE_Fortran_COMPILER_ID MATCHES "PGI|NVHPC")
target_link_options( ${ecwam}_${prec} INTERFACE SHELL:${OpenACC_Fortran_FLAGS} )
target_compile_options( ${ecwam}_${prec} PRIVATE "-gpu=maxregcount:168,fastmath" )
endif()

ecwam_target_compile_definitions_FILENAME( ${ecwam} )
if( HAVE_CUDA )
target_link_options( ${ecwam}_${prec} PUBLIC "-cuda;-gpu=pinned" )
endif()

ecwam_target_compile_definitions_FILENAME( ${ecwam}_${prec} )

endif()

endforeach()

### The file mubuf.F90, which is only used for "preproc" is sensitive to optimisations
# possibly leading to different wam_grid_<1,2,3> files.
Expand Down Expand Up @@ -537,17 +544,21 @@ if( HAVE_LOKI )
)
endif()

# Apply Loki source file transformation to lib target
loki_transform_target( TARGET ${ecwam}
MODE ${LOKI_MODE}
FRONTEND ${LOKI_FRONTEND}
CONFIG ${LOKI_CONFIG_FILE}
PLAN ${CMAKE_CURRENT_BINARY_DIR}/loki_plan_ecwam.cmake
CPP
DEFINITIONS WAM_GPU
INCLUDES ${ecwam_intfb_includes}
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/
)
foreach( prec sp dp )
if( HAVE_${prec} )
# Apply Loki source file transformation to lib target
loki_transform_target( TARGET ${ecwam}_${prec}
MODE ${LOKI_MODE}
FRONTEND ${LOKI_FRONTEND}
CONFIG ${LOKI_CONFIG_FILE}
PLAN ${CMAKE_CURRENT_BINARY_DIR}/loki_plan_ecwam.cmake
CPP
DEFINITIONS WAM_GPU
INCLUDES ${ecwam_intfb_includes}
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/
)
endif()
endforeach()

endif()
10 changes: 6 additions & 4 deletions src/programs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ if( CMAKE_Fortran_COMPILER_ID MATCHES Intel )
set_source_files_properties( create_wam_bathymetry_ETOPO1.F90 PROPERTIES COMPILE_FLAGS "-check nobounds" )
endif()

foreach( program
foreach( prec sp dp )
foreach( program
chief
bouint
preproc
Expand All @@ -20,13 +21,14 @@ foreach( program
create_wam_bathymetry_ETOPO1 )

ecbuild_add_executable(
TARGET ${PROJECT_NAME}-${program}
TARGET ${PROJECT_NAME}-${program}-${prec}
SOURCES ${program}.F90
LIBS ${PROJECT_NAME} ${OpenMP_Fortran_LIBRARIES}
LIBS ${PROJECT_NAME}_${prec} ${OpenMP_Fortran_LIBRARIES}
LINKER_LANGUAGE Fortran
)
ecwam_target_compile_definitions_FILENAME(${PROJECT_NAME}-${program})
ecwam_target_compile_definitions_FILENAME( ${PROJECT_NAME}-${program}-${prec} )

endforeach()
endforeach()

string( TOUPPER ${PROJECT_NAME} PNAME )
Expand Down
Loading