Search code examples
c++eigen

Eigen: set EIGEN_STACK_ALLOCATION_LIMIT doesn't work


I wish to change stack size that limited by Eigen

I add

#define EIGEN_STACK_ALLOCATION_LIMIT 0

to my cpp file.

However, no matter what value I set to EIGEN_STACK_ALLOCATION_LIMIT, compilation output always contains

C:/mingw-w64/x86_64-7.1.0-win32-seh-rt_v5-rev0/mingw64/x86_64-w64-mingw32/include/Eigen/src/Core/util/Macros.h:799:0: note: this is the location of the previous definition #define EIGEN_STACK_ALLOCATION_LIMIT 131072

131072 is exactly 128KB, nothing changes! Why? Am I wrong here? How to correctly set EIGEN_STACK_ALLOCATION_LIMIT for Eigen? In addition, how to adjust g++ stack size limit?

ps: I know I should not use large fixed size matrix. But using Dynamic got mysterous abort of compilation, so I am trying different ways.


Solution

  • You need to define EIGEN_STACK_ALLOCATION_LIMIT before including any Eigen headers. The easiest way to do that is by a compiler parameter:

    g++ -DEIGEN_STACK_ALLOCATION_LIMIT=0  {... other arguments ...}
    

    Regarding the stack-size limit: There are several related questions on stack-overflow. If none of them fit, ask a new question for that.