Skip to content

Commit

Permalink
Merge branch 'sarats/gnu/boz-literals' (PR #5727)
Browse files Browse the repository at this point in the history
GNU Fortran: Wrap boz constant inside intrinsic to fix compilation
issue

This fixes having to set `-fallow-invalid-boz` flag for gfortran to
build: wrap a couple of constants with a type-casting intrinsic.
Also, clean up and remove flag duplicates in mach-specific cmakes.

[BFB]
  • Loading branch information
amametjanov committed Jul 9, 2023
2 parents 3ec4ba2 + bffd1d1 commit 54ecb82
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 26 deletions.
8 changes: 0 additions & 8 deletions cime_config/machines/Depends.gnu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ if (NOT DEBUG)
endif()
endif()

list(APPEND ALLOW_INVALID_BOZ_LIST
eam/src/control/cam_history.F90
elm/src/biogeochem/MEGANFactorsMod.F90
)
list(APPEND NO_INLINE_ARG_PACKING_LIST
eam/src/dynamics/se/inidat.F90
)

if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
foreach(ITEM IN LISTS ALLOW_INVALID_BOZ_LIST)
e3sm_add_flags("${ITEM}" "-fallow-invalid-boz") # avoids build error for integer, parameter :: gen_hash_key_offset = z'000053db'
endforeach()

if (NOT DEBUG)
# new in gnu10, inline arg packing was causing INF values with SMS_P4x1.ne4pg2_ne4pg2.F-MMFXX
foreach(ITEM IN LISTS NO_INLINE_ARG_PACKING_LIST)
Expand Down
8 changes: 0 additions & 8 deletions cime_config/machines/Depends.gnugpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@ if (NOT DEBUG)
endif()
endif()

list(APPEND ALLOW_INVALID_BOZ_LIST
eam/src/control/cam_history.F90
elm/src/biogeochem/MEGANFactorsMod.F90
)
list(APPEND NO_INLINE_ARG_PACKING_LIST
eam/src/dynamics/se/inidat.F90
)

if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
foreach(ITEM IN LISTS ALLOW_INVALID_BOZ_LIST)
e3sm_add_flags("${ITEM}" "-fallow-invalid-boz") # avoids build error for integer, parameter :: gen_hash_key_offset = z'000053db'
endforeach()

if (NOT DEBUG)
# new in gnu10, inline arg packing was causing INF values with SMS_P4x1.ne4pg2_ne4pg2.F-MMFXX
foreach(ITEM IN LISTS NO_INLINE_ARG_PACKING_LIST)
Expand Down
1 change: 0 additions & 1 deletion cime_config/machines/cmake_macros/gnu_anlgce-ub18.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ string(APPEND CXX_LIBS " -lstdc++")
if (NOT DEBUG)
string(APPEND FFLAGS " -O2")
endif()
string(APPEND FFLAGS " -fallow-argument-mismatch -fallow-invalid-boz")
execute_process(COMMAND $ENV{NETCDF_PATH}/bin/nf-config --flibs OUTPUT_VARIABLE SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE0 OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND $ENV{NETCDF_PATH}/bin/nc-config --libs OUTPUT_VARIABLE SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE1 OUTPUT_STRIP_TRAILING_WHITESPACE)
string(APPEND SLIBS " ${SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE0} ${SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE1} -lblas -llapack")
Expand Down
1 change: 0 additions & 1 deletion cime_config/machines/cmake_macros/gnu_anlgce.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ string(APPEND CXX_LIBS " -lstdc++")
if (NOT DEBUG)
string(APPEND FFLAGS " -O2")
endif()
string(APPEND FFLAGS " -fallow-argument-mismatch -fallow-invalid-boz")
execute_process(COMMAND $ENV{NETCDF_PATH}/bin/nf-config --flibs OUTPUT_VARIABLE SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE0 OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND $ENV{NETCDF_PATH}/bin/nc-config --libs OUTPUT_VARIABLE SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE1 OUTPUT_STRIP_TRAILING_WHITESPACE)
string(APPEND SLIBS " ${SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE0} ${SHELL_CMD_OUTPUT_BUILD_INTERNAL_IGNORE1} -lblas -llapack")
Expand Down
3 changes: 0 additions & 3 deletions cime_config/machines/cmake_macros/gnu_docker-scream.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,3 @@ set(SCC "/opt/conda/bin/x86_64-conda-linux-gnu-gcc")
set(SCXX "/opt/conda/bin/x86_64-conda-linux-gnu-g++")
set(SFC "/opt/conda/bin/x86_64-conda-linux-gnu-gfortran")
set(SUPPORTS_CXX "TRUE")
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
string(APPEND FFLAGS " -fallow-argument-mismatch -fallow-invalid-boz ")
endif()
4 changes: 2 additions & 2 deletions cime_config/machines/cmake_macros/gnu_eddi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ if (COMP_NAME STREQUAL gptl)
endif()
set(NETCDF_PATH "$ENV{NETCDF_HOME}")
if (NOT DEBUG)
string(APPEND FFLAGS " -fno-unsafe-math-optimizations -fallow-argument-mismatch -fallow-invalid-boz")
string(APPEND FFLAGS " -fno-unsafe-math-optimizations ")
endif()
if (DEBUG)
string(APPEND FFLAGS " -g -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -fallow-argument-mismatch -fallow-invalid-boz -Wall")
string(APPEND FFLAGS " -g -fbacktrace -fbounds-check -ffpe-trap=invalid,zero,overflow -Wall")
endif()
string(APPEND SLIBS " -L$ENV{NETCDF_HOME}/lib/ -lnetcdff -lnetcdf -lcurl -llapack -lblas")
if (MPILIB STREQUAL mpi-serial)
Expand Down
2 changes: 1 addition & 1 deletion cime_config/machines/cmake_macros/gnu_spock.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(SUPPORTS_CXX "TRUE")
string(APPEND FFLAGS " -fallow-argument-mismatch -Wno-implicit-interface -fallow-invalid-boz ")
string(APPEND FFLAGS " -Wno-implicit-interface ")
string(APPEND CXX_LIBS " -lstdc++")
if (NOT DEBUG)
string(APPEND FFLAGS " -O2")
Expand Down
2 changes: 1 addition & 1 deletion components/eam/src/control/cam_history.F90
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ module cam_history
! logic in the routine that optimizes character strings of length 8.
!

integer, parameter :: gen_hash_key_offset = z'000053db'
integer, parameter :: gen_hash_key_offset = int(z'000053db')

integer, parameter :: tbl_max_idx = 15 ! 2**N - 1
integer, dimension(0:tbl_max_idx) :: tbl_gen_hash_key = &
Expand Down
2 changes: 1 addition & 1 deletion components/elm/src/biogeochem/MEGANFactorsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ integer function gen_hashkey(string)
integer :: i

integer, parameter :: tbl_max_idx = 15 ! 2**N - 1
integer, parameter :: gen_hash_key_offset = z'000053db'
integer, parameter :: gen_hash_key_offset = int(z'000053db')
integer, dimension(0:tbl_max_idx) :: tbl_gen_hash_key = (/61,59,53,47,43,41,37,31,29,23,17,13,11,7,3,1/)

hash = gen_hash_key_offset
Expand Down

0 comments on commit 54ecb82

Please sign in to comment.