Borrar filtros
Borrar filtros

Why is spdiags() much slower now than in previous versions

12 visualizaciones (últimos 30 días)
Mads el 6 de Mayo de 2021
Editada: Brandon Caasenbrood el 19 de Abr. de 2023
I have used spdiags() over many years.
Lately MathWorks have updated the script and the response is much slower.
I have compared spdiags() from R2019a with R2021a on a mac.
The older spdiags() runs in my present test 15 to 40 times faster than the latest spdiags().
I wonder what benefit I get from waiting that much longer, for something that involves plugging numbers into a sparse matrix.
  7 comentarios
Bruno Luong
Bruno Luong el 18 de Abr. de 2023
@Brandon Caasenbrood "I can confirm the same. spdiags has poor performance compared to previous matlab version (e.g. 2021a outperforms 2023a signficantly)"
I just test the same code I posted above with R2023a, and it is faster than R2021a.
>> testspdiags
ans =
' (R2023a)'
Elapsed time is 0.153604 seconds. % REMINDER: Elapsed time is 0.188962 seconds. for R2021a
Brandon Caasenbrood
Brandon Caasenbrood el 19 de Abr. de 2023
Editada: Brandon Caasenbrood el 19 de Abr. de 2023
I might have shouted wolf too early. But I'm getting subpar performance with spdaig in comparison to speye when make diagonal matrices. I've recently moved from 2021a to 2023a, and only now noticed the performance dip; which made me believe the "6 May 2021" issue above was related. Consider the following code (a segment from the MMA solver by Krister Svanberg -
GG and GG_ are identical, but speye outperforms spdiags here. Nevertheless, running the below code, gives indeed similar performance. What am I missing here?
M = 3e4;
N = 1e3;
disp('test: spdiags');
a = rand(M,1);
for ii = 1:N
A = spdiags(a,0,M,M) - spdiags(a/10,0,M,M);
disp('test: speye');
a = rand(M,1);
for ii = 1:N
A = a.*speye(M,M) - (a/10).*speye(M,M);
% test: spdiags
% Elapsed time is 0.814878 seconds.
% test: speye
% Elapsed time is 0.847202 seconds.
The profiler says the bottleneck is in spdiags>makeSparseGeneral.Slightly odd, since I, J, and V are preallocated above, and I also never seen a profiler highlighting the iteration counter before.

Iniciar sesión para comentar.

Respuestas (0)


Más información sobre Sparse Matrices en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by