필터 지우기
필터 지우기

Collapsing preallocated memory of sparse matrix

조회 수: 3 (최근 30일)
Hyeokjin Jho
Hyeokjin Jho 2019년 1월 22일
댓글: Bjorn Gustavsson 2019년 1월 23일
I used sparse matrix for some calculation, and I roughly know how many nnz will be stored. So I preallocated a slightly larger memory when I initialize that sparse matrix.
reserveRate = 1.2 % 120%
A = spalloc(n,m,estimated_nnz * reserveRate);
After finishing the calculation, since the memory has some unfilled margin, I would like to remove those space. Is there any way to do so?

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2019년 1월 22일
Is there a particular reason you dont collect the non-zero values and their matrix indices into 3 arrays and then after all those are completed first then generating the sparse array? That is the general advice to not over-allocate.
HTH
  댓글 수: 2
Hyeokjin Jho
Hyeokjin Jho 2019년 1월 23일
It's a quite big data. The array takes memory over 50%, so duplicating it will lead to shortage of memory.
Bjorn Gustavsson
Bjorn Gustavsson 2019년 1월 23일
But if your arrays with the non-zero values and the corresponding row and column indices take up over 50% of your memory wouldn't you rapidly run into problems as soon as you start doing operations on the sparse array?
Sad follow-up suggestion: read the indices first, then you candetermine the exact size needed so you can allocate the minimal A, and then do another read to fill it? If it is so that you just get the values and indices in some calculation maybe another way would be to store them in arrays, save to file(s) - then you might be able to wiggle your way around by determining the size of A and then populate it. I know these are "not pretty" suggestions...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by