Memory usage of decomposition

30 ビュー (過去 30 日間)
Mariano
Mariano 2025 年 2 月 15 日 19:25
コメント済み: Christine Tobler 2025 年 2 月 17 日 14:26
Hello,
Consider linear systems Ax=b_i with A sparse and positive definite and several right hand sides b_i. In the experiments I have done, it is faster to use
dA = decomposition(A,'chol','upper');
x_i = dA\b_i; % repeat as needed
than the classical
R = chol(A);
x_i=R\(R'\b_i); % repeat as needed
But dA occupies much more memory than R
n = 1e5;d = 1e-5;rc = 1e-5;
A=sprand(n,n,d,rc);
A = A+A'+10*speye(n,n);
R = chol(A);
dA = decomposition(A,'chol','upper');
memR = whos("R"); memR = memR.bytes;
memdA = whos("dA"); memdA = memdA.bytes;
fprintf(' R occupies %.1e bytes.\ndA occupies %.1e bytes\n',memR,memdA)
R occupies 5.6e+06 bytes. dA occupies 1.5e+07 bytes
Any idea of why? Any solution?
Thanks,
Mariano
  6 件のコメント
Mariano
Mariano 2025 年 2 月 17 日 6:35
Thanks for the tip!
Christine Tobler
Christine Tobler 2025 年 2 月 17 日 14:26
The number of bytes returned by whos isn't always reliable, since it will count arrays that share memory multiple times (see below). I would trust the system's memory indicator more than the whos command. For example:
>> A = randn(1000);
>> B = A;
>> s.A = A; s.B = A;
>> whos
Name Size Bytes Class Attributes
A 1000x1000 8000000 double
B 1000x1000 8000000 double
s 1x1 16000274 struct
The whos command would have you think we're using 32 MB of RAM - but in fact, all of these are shared copies and we only allocated significant memory once, for A.
For the internal object using more memory than its properties require, this is because it's storing an object from an external library, which can't be represented in MATLAB directly. The byte-count told to us by that third-party library is shown by whos.
Note that this same object is also used inside of mldivide, and gets destroyed at the end of the mldivide command. So whether to use mldivide or decomposition is a question of if you can afford to keep this memory allocated for a longer time, not if you can afford to allocate it in the first place.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by