3

In my case (64bit ubuntu with 16GB memory, using Eigen3), I write MatrixXd m(M,M); where M = 100,000, while running, the program crashed, and reported:

what(): std::bad_alloc
Aborted (core dumped)

Using a dynamic 2 dim array, the program works fine. Is there a hard limit on the size of (dense) matrix in Eigen?

chentingpc
  • 1,283
  • 3
  • 18
  • 24

2 Answers2

7

You're trying to allocate 100000*100000 elements of 8 bytes each, or 80,000,000,000 bytes (74.5GB), which is failing as you only have 16GB of memory. This causes the memory allocation to fail, as it can't find a single continuous block of memory that large.

There is no fixed limit in Eigen, but the array does need to be allocatable on your system.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • thanks, in 2d array cases, I forgot that C++ would not alloc real space until the program access it, so I supposed that the memory is still big enough for the matrix. – chentingpc Jul 02 '13 at 16:42
1

YOu forgot about size of matrix element.

MatrixXd uses double

100000 * 100000 = 10000000000 elements.

sizeof(double) is probably 8 on your system.

Which means, that in order to create this matrix, you'll need:

width*height*sizeof(double) => 100000*100000*8/(1024*1024*1024) => 74.5 gigabytes of memory.

SigTerm
  • 26,089
  • 6
  • 66
  • 115
  • thanks, in 2d array cases, I forgot that C++ would not alloc real space until the program access it, so I supposed that the memory is still big enough for the matrix. – chentingpc Jul 02 '13 at 16:41