Update a sparse matrix efficiently

조회 수: 26(최근 30일)
mafoEV
mafoEV 2020년 3월 5일
댓글: Bruno Luong 2020년 8월 25일
Dear MATLAB community,
I have a large sparse matrix (~ 100,000 by 100,000, with about 100,000 non-zero elements), which I need to update regularly (at each solver step).
So far, I've done it by creating its elements first (rows, columns and values) as column vectors, then assembling them using the sparse function:
A = sparse(iA, jA, vA, m, n, nnzA);
However this line is now taking 13% of my total solve time (called 355 times, taking about 0.29s each time).
The matrix structure does not change from one iteration to the next, only about half of the values need updating. Is there a more efficient way to do it? I haven't been able to find any solution so far looking at the forums.
I'm using Matlab 2019b Update 3 (9.7.0.1261785).
Many thanks.
  댓글 수: 1
Bruno Luong
Bruno Luong 2020년 8월 25일
Are you updated only non-zero elements? only zero elements? Not known?
In three cases, the required time are differents.

댓글을 달려면 로그인하십시오.

답변(1개)

sjhstone
sjhstone 2020년 8월 25일
You can refer to the following blog post. It seems that you have reached the optimal efficiency.
If the sparsity pattern does not change, and there are nonzero entries on the last column and the last row, I think it might be redundant to pass arguments nnzA. Because MATLAB seems to use MEX routine, we do need to do numerical experiments to see whether not passing them into sparse can accelerate your code.

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by