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

7 次查看(过去 30 天)
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 个评论
Bruno Luong
Bruno Luong 2023-4-18
@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 =
'9.14.0.2206163 (R2023a)'
Elapsed time is 0.153604 seconds. % REMINDER: Elapsed time is 0.188962 seconds. for R2021a
Brandon Caasenbrood
编辑:Brandon Caasenbrood 2023-4-19
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?
clc;
M = 3e4;
N = 1e3;
tic;
disp('test: spdiags');
a = rand(M,1);
for ii = 1:N
A = spdiags(a,0,M,M) - spdiags(a/10,0,M,M);
end
toc
tic;
disp('test: speye');
a = rand(M,1);
for ii = 1:N
A = a.*speye(M,M) - (a/10).*speye(M,M);
end
toc
% 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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by