Large Matrix multiplication and out of memory error in matlab
Show older comments
i have sparse matrix V of size V =<162000x32400 double> or even bigger , I have to solve the following equations.
x_0=ones(size(V ,1) ,1);
y_0=V'*x_0;
result=V'*V + y_0*y_0'; %%%%%Problem here
The problem is in right hand side of last equation and is giving me out of memory error.
Accepted Answer
More Answers (4)
Walter Roberson
on 31 Oct 2011
0 votes
Is y_0=V'*x_0; the same as sum(V) ?
1 Comment
imran khan
on 31 Oct 2011
Jan
on 31 Oct 2011
0 votes
A [162000x32400] DOUBLE array needs 42GB memory. I'm not sure if computing V'*V + y_0*y_0' needs to allocate one, two or three further blocks of this size as temporary memory. In every case the blocks must be available in contiguos blocks. Therefore I estimate you need 128 to 256 GB free RAM.
How many RAM do you have installed?
(Is V sparse?) [EDITED:] How sparse is V?
3 Comments
Walter Roberson
on 31 Oct 2011
The problem statement does start by saying V is sparse.
imran khan
on 31 Oct 2011
imran khan
on 1 Nov 2011
Titus Edelhofer
on 31 Oct 2011
0 votes
Hi Imran,
I guess the problem is, that y_0*y0' most likely will be a full matrix, as long as your V matrix has no columns that sum up to zero. This will fail already as Jan pointed out. You might get along by looping over the columns of your matrix V ...
Titus
1 Comment
imran khan
on 1 Nov 2011
Titus Edelhofer
on 1 Nov 2011
Hi Imran,
something like the following should work:
n = size(V,2);
blksize = 100;
result = zeros(n);
for i=0:(blksize-1)
columns = i*n/blksize + (1:n/blksize);
result(:, columns) = V'*V(:,columns) + y_0*y_0(columns)';
end
I must admit I did not check if it is really correct, but should give an impression (and can be verified easily on small example). The blksize can be experimented for balancing memory and speed.
Titus
3 Comments
imran khan
on 3 Nov 2011
Titus Edelhofer
on 3 Nov 2011
Hi Imran,
I updated the code (n needs to be the number of columns). by the way, the code assumes, that the number of columns of V is a multiple of the blksize, otherwise one needs to be more careful ...
Titus
imran khan
on 4 Nov 2011
Categories
Find more on Environment and Settings 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!