How to troubleshoot an 'Out of memory' error with pca() when matlab still has plenty of RAM free?

4 views (last 30 days)
Could you help troubleshoot an 'Out of memory' error when running pca() on a 6000 x 9500 matrix of doubles?
To reproduce the error, run:
pca(rand(6000, 9500));
This produces the error:
Error using svd
Out of memory. Type "help memory" for your options.
Error in pca>localSVD (line 484)
[U,sigma,coeff] = svd(x, 'econ');
More specifically, pca will work on 6000x5000 but not an 6000x6000 matrix.
There should not be an 'Out of memory' error here because:
  1. matlab still has plenty of RAM available: this system has 32 GB of RAM and the matlab process nevers consumes more than 15% of that, even during pca (according to the 'top' command in ubuntu).
  2. R does PCA on that matrix without problem ;-)
Operating systems limits don't seem to be the solution:
A. running 'ulimit' on the command line suggests no memory limits:
$ ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) 0
-m: resident set size (kbytes) unlimited
-u: processes 126664
-n: file descriptors 1024
-l: locked-in-memory size (kbytes) 16384
-v: address space (kbytes) 12582912
-x: file locks unlimited
-i: pending signals 126664
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
B. Matlab is running in a 64-bit environment: ubuntu 18 LTS 64 bit with Matlab R2019b. The 'computer' matab command returns 'GLNXA64' so I believe I am using the 64-bit version of matlab. The 'ver' command also reports an x86_64 architecture and a 64-bit java hotspot server.
This question has been asked before. But it seems relevant to ask it again because all previous questions refered to the old implementaiton of pca (princomp()), are for systems with significantly less RAM (8 GB), for 32 bit environments, or were caused by issues in the data matrix (such as NaNs filling one column).
  8 Comments
Jean Hausser
Jean Hausser on 15 Mar 2020
dpb: I thought of that too, but how could it possibly be? Take a look at how mem usage changes as I prepare for pca:
Action memory usage
start matlab 4%
load data 8%
precompute 9% then back to 8%
drop bad data 7.5%
So even the first 9% of memory are unusable due to memory fragmentation, Matlab still has 91% of RAM available to play with.
Or does matlab maybe store objects at random places in the RAM instead of stacking it up at the first available address? This could increase fragmentation. But even so, my intuition would be that there is tons of contiguous RAM to play with.
What do you think? How can we check if memory fragmentation is the culprit?

Sign in to comment.

Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!