Skip to content
Draft
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
25 changes: 19 additions & 6 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ message(STATUS "Build type = ${MOM5_TYPE}")
option(MOM5_USE_NETCDF3 "Use netCDF3 rather than netCDF4. Only relevant for MOM5_TYPEs that use internal FMS" OFF)
option(MOM5_DETERMINISTIC "Deterministic build" OFF)

if(MOM5_DETERMINISTIC AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(FATAL_ERROR "MOM5_DETERMINISTIC is only supported with CMAKE_BUILD_TYPE=Release (got '${CMAKE_BUILD_TYPE}').")
endif()

message(STATUS "Build options")
message(STATUS " - MOM5_USE_NETCDF3 ${MOM5_USE_NETCDF3}")
message(STATUS " - MOM5_DETERMINISTIC ${MOM5_DETERMINISTIC}" )
Expand All @@ -49,17 +53,26 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})
include(CheckFortranCompilerFlag)

# Fortran compiler flags
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -i4 -r8 -nowarn -check noarg_temp_created -assume nobuffered_io -convert big_endian -grecord-gcc-switches -fp-model precise -fp-model source -align all")
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -integer-size 32 -real-size 64 -nowarn -assume nobuffered_io -convert big_endian -fp-model precise -fp-model source -align all")
if (MOM5_DETERMINISTIC)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost certainly a separate issue, but if MOM5_DETERMINISTIC is set, then is the build-type also set to Release? Without a specified build-type, it will default to RelWithDebInfo and those flags do not have a corresponding MOM5_DETERMINISTIC branch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dougiesquire What do you think about this one ☝🏾?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RelWithDebInfo flags are appended to the Release flags so in theory this is okay. But without testing that I don't want to do, I'm not confident that the additional flags added by RelWithDebInfo don't break the determinism (e.g. add a timestamp to the exe). So to be safe, I'll prevent setting MOM5_DETERMINISTIC with anything other than Release.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also updated the spack package accordingly

set(CMAKE_Fortran_FLAGS_RELEASE "-g0 -O0 -xCORE-AVX2 -debug none -check none")
else()
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xCORE-AVX2 -debug all -check none")
endif()
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g3 -grecord-gcc-switches -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv -traceback")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -safe-cray-ptr -fpe0 -ftz -assume byterecl -integer-size 32 -real-size 64 -nowarn -assume nobuffered_io -convert big_endian -fp-model precise -fp-model source -align all")
if (MOM5_DETERMINISTIC)
set(CMAKE_Fortran_FLAGS_RELEASE "-g0 -O0 -xCORE-AVX2 -debug none -check none")
else()
set(CMAKE_Fortran_FLAGS_RELEASE "-g3 -O2 -xCORE-AVX2 -debug all -check none -traceback")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -xCORE-AVX2 -debug all -check none")
endif()
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g3 -grecord-gcc-switches -traceback")
set(CMAKE_Fortran_FLAGS_DEBUG "-g3 -O0 -debug all -check -check noarg_temp_created -check nopointer -warn -warn noerrors -ftrapuv -traceback")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer -fdefault-real-8 -ffree-line-length-none -fno-range-check -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation -Wconversion -Wline-truncation -Wintrinsics-std -Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsic-shadow -Wno-align-commons")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fcray-pointer -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fno-range-check -fconvert=big-endian -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation -Wconversion -Wline-truncation -Wintrinsics-std -Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter -Wintrinsic-shadow -Wno-align-commons")
check_fortran_compiler_flag("-fallow-invalid-boz" _boz_flag)
check_fortran_compiler_flag("-fallow-argument-mismatch" _argmis_flag)
if(_boz_flag)
Expand All @@ -69,7 +82,7 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch" )
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "-O2")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g")
set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELEASE} -g -frecord-gcc-switches -fbacktrace")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -W -fbounds-check")
else ()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
Expand Down
Loading