Hello, in the code below, I have to do matrix multiplication thousands of time. The time it takes on my PC is about 70 secs to run this code. I want to reduce the time of execution. In the code below two variables, PRODOTTO3 and COEFF are sparse matrices and sparse vector respectively. I have tried making them sparse matrix but the time of execution increase to more than 200 secs. Does anybody have better idea to reduce the execution time?
From the time profiler I know that the 99.8% of the execution time is spent on this line "COEFF_S(i,j) = sum(COEFF.*(PRODOTTO3(:,j,i)))"
I really want to reduce the execution time.
THIS IS THE CODE WITHOUT SPARSE MATRIX
NU =25;
p=2 ;
npolinomi=factorial(NU+p)/(factorial(NU)*factorial(p));
PRODOTTO3 = (double((randn(round(npolinomi),round(npolinomi),round(npolinomi)))>0.7));
COEFF = zeros(round(npolinomi),1) ;
COEFF(1:3) = 1 ;
COEFF_S = zeros(size(COEFF,1),size(COEFF,1)) ;
tic ;
for l = 1:200
for i = 1 : size(COEFF,1)
for j=1:size(COEFF,1)
COEFF_S(i,j) = sum(COEFF.*(PRODOTTO3(:,j,i))) ;
end
end
end
for i= 1 : 250
for j = 1 : K
COEFF_S = COEFF_S*COEFF_S ;
end
end
end
toc
THIS IS CODE WITH SPARSE MATRIX
if true
NU =25;
p=2 ;
npolinomi=factorial(NU+p)/(factorial(NU)*factorial(p));
PRODOTTO3 = ndSparse(double((randn(round(npolinomi),round(npolinomi),round(npolinomi)))>0.7));
COEFF = zeros(round(npolinomi),1) ;
COEFF(1:3) = 1 ;
COEFF=sparse(COEFF) ;
COEFF_S = zeros(size(COEFF,1),size(COEFF,1)) ;
tic ;
for l = 1:200
for i = 1 : size(COEFF,1)
for j=1:size(COEFF,1)
*COEFF_S(i,j) = sum(COEFF.*(PRODOTTO3(:,j,i))) ;*
end
end
end
for i= 1 : 250
for j = 1 : K
COEFF_S = COEFF_S*COEFF_S ;
end
end
end
toc
end
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/353797-can-i-reduce-computation-time-for-the-matrix-computation-sparse-matrices#comment_479322
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/353797-can-i-reduce-computation-time-for-the-matrix-computation-sparse-matrices#comment_479322
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/353797-can-i-reduce-computation-time-for-the-matrix-computation-sparse-matrices#comment_479327
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/353797-can-i-reduce-computation-time-for-the-matrix-computation-sparse-matrices#comment_479327
Sign in to comment.