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

Eigen, NDEBUG, and matrix shapes #10

Open
vpuri3 opened this issue Feb 3, 2023 · 2 comments
Open

Eigen, NDEBUG, and matrix shapes #10

vpuri3 opened this issue Feb 3, 2023 · 2 comments

Comments

@vpuri3
Copy link

vpuri3 commented Feb 3, 2023

A student posted this on Piazza. Maintainers, please take a look :D

This might be done on purpose, but it did take me quite some time to figure out what is going on.
In the CmakeLists.txt that lives in ddg-exercises/projects/simplicial-complex-operators/CMakeLists.txt, line 41 (pasted below), the flag -DNDEBUG is passed. This disables the Eigen shape-checking for matrix multiplication. This allows wrongly shaped matrices to be multiplied silently. Once I took out this flag debugging became much easier :).

  # https://gitlab.kitware.com/cmake/cmake/-/issues/22484
  include(CheckCXXCompilerFlag)
  unset(COMPILER_SUPPORTS_MARCH_NATIVE CACHE)
  CHECK_CXX_COMPILER_FLAG(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)
  if(COMPILER_SUPPORTS_MARCH_NATIVE)
    SET(CMAKE_CXX_FLAGS_RELEASE        "-O3 -march=native -DNDEBUG")
  else()
    SET(CMAKE_CXX_FLAGS_RELEASE        "-O3 -mcpu=apple-m1 -DNDEBUG") # Apple M1
  endif()

@nzfeng
Copy link
Collaborator

nzfeng commented Feb 3, 2023

Hi, thanks for sharing!

Usually one sets debugging modes via compilation flags, rather than hardcoding it directly. In these exercises, by default, just compiling using cmake (i.e., without explicitly setting the flag to Release or Debug) will compile in "release" mode. In "release" mode, the variable CMAKE_CXX_FLAGS_RELEASE is naturally set to encode the -DNDEBUG flag. If one compiles in "debug" mode, which can be done with command line arguments via cmake -DCMAKE_BUILD_TYPE=Debug (or cmake -DCMAKE_BUILD_TYPE=Debug .. if you are in the build subdirectory of a project), then the value of CMAKE_CXX_FLAGS_DEBUG is used. You can see that the value of CMAKE_CXX_FLAGS_DEBUG being set earlier in the CMakeLists.txt file, with the corresponding flags to enable debugging.

Does compiling with cmake -DCMAKE_BUILD_TYPE=Debug enable Eigen shape-checking?

@nzfeng
Copy link
Collaborator

nzfeng commented Feb 3, 2023

By the way, thank you for sharing this. Now that I think about it, it makes more sense to make the default mode "debug" rather than "release" for these exercises. I'll probably change this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants