Why does MATLAB take a longer time to compute the SVD of matrices whos size is a power of 2?

14 visualizzazioni (ultimi 30 giorni)
There is a significant difference in the Singular Value Decomposition computation time when the matrix size is a power of two.
For example, if I compute the SVD of randomly generated square matrices of sizes 511, 512 and 513, note the difference in the computaion times.
A=randn(512);
tic;[u s v]=svd(A);toc
This displays:
Elapsed time is 24.476422 seconds.
However, the following:
A=randn(511);
tic;[u s v]=svd(A);toc
displays:
Elapsed time is 5.049256 seconds.
and
A=randn(513);
tic;[u s v]=svd(A);toc
displays:
Elapsed time is 4.974085 seconds.
I would like to increase the speed and capabilities of SVD computation in MATLAB.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 25 Gen 2017
This is expected behavior. This behavior is due to what is called the "cache resonance effect". When the size of a matrix is a power of 2, the cache replacement algorithm is not as effective.
For more information on increasing the speed and capabilities of matrix computation refer to the following URL:
  1 Commento
Philip Borghesani
Philip Borghesani il 23 Ott 2017
Although this effect is expected the times and size of the effect are a bit overstated for modern systems, on my machine (Xeon E5-1650 v3) and R2017b I see:
A=randn(511);B=randn(512);C=randn(513);
>> timeit(@()svd(A),3)
ans =
0.0470
>> timeit(@()svd(B),3)
ans =
0.0507
>> timeit(@()svd(C),3)
ans =
0.0466

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by