chentingpc
chentingpc

Reputation: 1283

What is the maximum size of matrix in Eigen?

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?

Upvotes: 3

Views: 6870

Answers (2)

SigTerm
SigTerm

Reputation: 26409

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.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564403

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.

Upvotes: 7

Related Questions