A few questions on memory management of sparse matrices...
2 views (last 30 days)
Show older comments
Hi,
I have a bit of trouble with the space used by sparse matrices.
I use two ways of creating the same matrix, say P:
(1) allocating some space and filling the matrix like P(4,2) = 89; the space allocated at the beginning is exactly the space used.
(2) or creating 3 arrays of rows and columns indices and matrix values, and making P in just one command line.
What I observed: - when I create twice the same matrix with both methods, the space used in bigger for the first one (until half much more space).
- the second method was faster when I created one big matrix. but the first is faster when I create a relatively large cell array filled with many smaller sparse matrices. Actually, when using the first method, I receive this matlab warning (that advises me to use the second method) when I want to create the big sparse matrix but not when I create the cell arrays of matrices.
- with the second method, I obtain 3 arrays of 8MB but my matrix is 500MB!
I can't explain all these things. Could you?
Thank!
3 Comments
James Tursa
on 19 Jul 2013
I agree with Jan ... we need to see the code. A simple expression like P(4,2) = 89 may cause the entire existing sparse matrix memory to be copied to new memory. So understanding exactly how you are doing the sparse matrix build is critical to the memory usage and timing issues.
Jan
on 19 Jul 2013
Edited: Jan
on 19 Jul 2013
@James: I had a discussion about why Matlab required more than 8GB free RAM to create q [1x1e9] UINT32 vector, although 4GB should be enough. The description as a text did not reveal the cause, but the seeing the code did:
uint32(1:1e9) % 8GB used for the temporary double array! Better:
uint32(1):uint32(1e9) % 4GB
Answers (0)
See Also
Categories
Find more on Sparse Matrices 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!