How does MATLAB allocate memory while solving large (10m-ish) linear systems?

3 views (last 30 days)
I am trying to solve a 'sparse' linear system of equations (Ax=b) with number of variables in the range of 1-10 million. Its a basic finite element simulation for solid mechanics problems, with a sparse and symmetric matrix (A), and sparse right side (b). The matrix is such that 0.01% of the total entries are non zero. I am using the '\' operator.
MATLAB was able to solve a 2.3m variable problem on my personal laptop (R2021b, Windows, 16GB RAM, i7-7700 2.8 GHz) in about 6 hours.
I have access to a (Linux) cluster that has a good number of processors and I can request any amount of memory (using PBS). However, when I try to run the same code, with 5m variables (a finer mesh), 300 GB of memory allocated, the job was quit right at the linear solution step, with memory error.
I need to know what I am doing wrong, and how can I fix this problem. 300 GB is outrageous, 16 GB is nothing. Is there a memory setting that MATLAB uses that is different for Linux and windows? I think MATLAB uses my hard drive to temporarily store data during the solution process, and it might not be the case with Linux. If that is the case, how do I switch that setting on inside my code.
I also welcome suggestions on different solvers or approaches I could use to solve problems such as these. Let me know if you guys need other information from me, and sorry if this has already been answered, just direct me there.
Thank you for your time!

Accepted Answer

Matt J
Matt J on 17 Oct 2022
Edited: Matt J on 17 Oct 2022
With 5m variables and a density of 0.01%, your matrix is going to consume about 56GB even before mldivide starts to do any work.
(5e6)^2*0.01/100*8*3/2^30
ans = 55.8794
You should check with the memory command how much memory is available to Matlab on your system (it wouldn't be the total 300Gb available to the system as a whole). However, it doesn't seem unreasonable that mldivide() could consume another 100 GB at least, and I can imagine that exceeding the amount of memory that Matlab has.
For a problem this size, you should probably be using an iterative solver, like pcg, rather than mldivide().
  16 Comments
Bruno Luong
Bruno Luong on 26 Oct 2022
As I just wrote above you use iterative solver by passing the function handle, for input x vector that provide
Ax := A*x
by this calculation:
Ax = (x'*U)'+U*x-diag(U).*x
where U is triu of A. So you need to store U = triu of A, and not A.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!