Skip to content
2 changes: 1 addition & 1 deletion configure.sh
Copy link
Collaborator

Choose a reason for hiding this comment

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

i wonder if we should just remove -DCMAKE_BUILD_TYPE=.... from ./configure.sh because 1. ./configure.sh also takes cmake args so gives flexibility for user to use ./configure.sh blahblah -DCMAKE_BUILD_TYPE=Debug if they want to. 2. in CMakeLists.txt build type is set to be Release in case the variable is not set.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for arg in "${ENV_ARGS[@]}"; do
fi
done

cmake ${SOURCE_DIR} -DCMAKE_INSTALL_PREFIX=$HERE -DCMAKE_BUILD_TYPE=Debug ${CMAKE_ARGS} ${CMAKE_ONLY_ARGS}
cmake ${SOURCE_DIR} -DCMAKE_INSTALL_PREFIX=$HERE -DCMAKE_BUILD_TYPE=Release ${CMAKE_ARGS} ${CMAKE_ONLY_ARGS}
# not required when re-compiling
# additional cmake arguments can be passed to configure.sh
# this also includes fesom specific options in CMakeLists, can be used as -DFESOM_COUPLED=ON
Expand Down
63 changes: 41 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,32 @@ if(${CMAKE_Fortran_COMPILER_ID} STREQUAL Intel OR ${CMAKE_Fortran_COMPILER_ID}
target_compile_options(${PROJECT_NAME} PRIVATE -xHost)
endif()

# # debugging related compiler flags
# target_compile_options(${PROJECT_NAME} PRIVATE -qopenmp -g -traceback -check all,noarg_temp_created,bounds,uninit ) #-ftrapuv ) #-init=zero)
# target_compile_options(${PROJECT_NAME} PRIVATE -g -traceback -check all,noarg_temp_created,bounds,uninit ) #-ftrapuv ) #-init=zero)
# debugging related compiler flags (activated for Debug build type)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(ENABLE_OPENMP)
target_compile_options(${PROJECT_NAME} PRIVATE -qopenmp -g -traceback -check all,noarg_temp_created,bounds,uninit) #-ftrapuv ) #-init=zero)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -g -traceback -check all,noarg_temp_created,bounds,uninit) #-ftrapuv ) #-init=zero)
endif()
endif()


elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU )
# target_compile_options(${PROJECT_NAME} PRIVATE -O3 -finit-local-zero -finline-functions -fimplicit-none -fdefault-real-8 -ffree-line-length-none)
if(${FESOM_PLATFORM_STRATEGY} STREQUAL ubuntu )
message(STATUS "Allowing type mismatches on Ubuntu for CI Testing" ) # NOTE(PG): Would be nicer to grab the CI=True from the env variable
target_compile_options(${PROJECT_NAME} PRIVATE -O2 -g -fbacktrace -ffloat-store -finit-local-zero -finline-functions -fimplicit-none -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fallow-argument-mismatch -cpp)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE -O0 -g -fbacktrace -ffloat-store -finit-local-zero -fimplicit-none -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fallow-argument-mismatch -cpp)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -O2 -g -fbacktrace -ffloat-store -finit-local-zero -finline-functions -fimplicit-none -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -fallow-argument-mismatch -cpp)
endif()
else()
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -ffloat-store -finit-local-zero -finline-functions -fimplicit-none -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -cpp)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE -O0 -ffloat-store -finit-local-zero -fimplicit-none -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -cpp)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -ffloat-store -finit-local-zero -finline-functions -fimplicit-none -fdefault-real-8 -fdefault-double-8 -ffree-line-length-none -cpp)
endif()

endif()
if(CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10 )
target_compile_options(${PROJECT_NAME} PRIVATE -fallow-argument-mismatch) # gfortran v10 is strict about erroneous API calls: "Rank mismatch between actual argument at (1) and actual argument at (2) (scalar and rank-1)"
Expand Down Expand Up @@ -362,29 +376,34 @@ elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU )
# | | -mno-fma4 -mavx2 -mfma | |
# | GCC/openMPI | -O3 -march=znver3 -mtune=znver3 -ftree-vectorize -flto | 280s | chatgpt recomendation
# | | -mcpu=znver3 | |
target_compile_options(${PROJECT_NAME} PRIVATE -march=znver3 -mtune=znver3 -ftree-vectorize -flto)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE -march=znver3 -mtune=znver3)
else()
target_compile_options(${PROJECT_NAME} PRIVATE -march=znver3 -mtune=znver3 -ftree-vectorize -flto)
endif()
else()
#[[if(NOT (${FESOM_PLATFORM_STRATEGY} STREQUAL ubuntu))
target_compile_options(${PROJECT_NAME} PRIVATE -native)
endif() ]]
endif()

# # debugging related compiler flags
#target_compile_options(${PROJECT_NAME} PRIVATE
#-fallow-argument-mismatch
#-fno-fast-math -fno-signed-zeros
#-freciprocal-math
#-mveclibabi=svml
#-flto
#-pg
#-fbacktrace
#-fcheck=all,bounds
#-finit-real=snan
#-finit-integer=-9999
#-fsanitize=undefined,address
#)
## if use -fsanitize=undefined,address you also need ... PRIVATE -lubsan)
#target_link_libraries(${PROJECT_NAME} PRIVATE -lubsan)
# debugging related compiler flags (activated for Debug build type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should use address sanitizer definitely for testing new code to check if we are allocating badly and creating leaks but I will skip -fsanitize for now as it need libasan to also be installed and present, this possibly need a cmake module to check this. so would skip this for now just, and ubsan seems to be a typo? should be -lasan or -static-libasan to compile options. More over any use of asan also need a env variable or someting to trace specific issue like ASAN_OPTIONS=detect_leaks=1 for detecting leaks. so this should be possibly done differently for it to be useful.

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE
-fallow-argument-mismatch
-fno-fast-math -fno-signed-zeros
-freciprocal-math
-mveclibabi=svml
-flto
-pg
-fbacktrace
-fcheck=all,bounds
-finit-real=snan
-finit-integer=-9999
-fsanitize=undefined,address
)
target_link_libraries(${PROJECT_NAME} PRIVATE -lubsan)
endif()


elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Cray )
Expand Down
Loading