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

5 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 12 Juin 2024
Modifié(e) : MathWorks Support Team le 17 Juin 2024
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 commentaire
Philip Borghesani
Philip Borghesani le 23 Oct 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Linear Algebra dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by