SeisSol icon indicating copy to clipboard operation
SeisSol copied to clipboard

Debug build optimizes variables out

Open sebwolf-de opened this issue 4 years ago • 8 comments

Describe the bug If I build SeisSol as Debug some variables get optimized out.

Expected behavior No variables get optimized out in Debug builds.

To Reproduce Steps to reproduce the behavior:

  1. Current Master
  2. Intel Compiler
  3. On SuperMUC-NG

sebwolf-de avatar Feb 17 '21 16:02 sebwolf-de

Does it happen in the Fortran or C++ code?

ravil-mobile avatar Feb 17 '21 16:02 ravil-mobile

C++ When I manually add -O0 it works.

sebwolf-de avatar Feb 17 '21 16:02 sebwolf-de

maybe we can try something like below in the main CMakeLists.txt?

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  target_compile_options(SeisSol-lib PUBLIC "-g")
endif()

ravil-mobile avatar Feb 17 '21 16:02 ravil-mobile

or something like

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()

here https://github.com/SeisSol/SeisSol/blob/b98133c397244e8f0bcb0e38e6a2d163b039409e/CMakeLists.txt#L296-L306

ravil-mobile avatar Feb 17 '21 16:02 ravil-mobile

There's also CMAKE_CXX_FLAGS_DEBUG. Apparently Cmake doesn't set -O0 (but I thought it was default anyway on most compilers?)

Apparently, gcc recommends -0g (see here)

krenzland avatar Feb 18 '21 10:02 krenzland

but I thought it was default anyway on most compilers?

You are right. Maybe it is not a case for Intel compiler.

@sebwolf-de, have you tried the changes that I suggested? If it works we can probably add them to the master branch

ravil-mobile avatar Feb 18 '21 11:02 ravil-mobile

According to the man pages, -O0 is default for gcc and -02 is default for intel. You can find the latter under the documentation for the argument -ftrapuv:

which changes the default optimization level from O2 to -O0 (Linux and macOS*) or /Od (Windows). You can override this effect by explicitly specifying an O option setting.

So we should add to CMAKE_CXX_FLAGS_DEBUG: -O0 for intel, -Og for gcc (maybe?). Not sure what to set for clang, it supports -Og but this defaults to -O1. So we should probably choose -O0 as well? https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-o0

krenzland avatar Feb 18 '21 11:02 krenzland

@ravil-mobile thanks for your suggestions, but the -g was already set before, it was rather a matter of the -O flags

sebwolf-de avatar Feb 22 '21 10:02 sebwolf-de