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

10 views (last 30 days)
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.
Brandon Caasenbrood
Brandon Caasenbrood on 19 Apr 2023
Edited: Brandon Caasenbrood on 19 Apr 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 - https://gitlab.gbar.dtu.dk/s144426/s144426-TopOpt/-/blob/9e34bb5bb19b2e0f5aebbb4640f4d296627140d6/subsolv.m)
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.

Sign in to comment.

Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by