possible speed up of the ischange function by parfor

2 次查看(过去 30 天)
I completely understand, that any modifications of standard MATLAB functions are very dangerous, but I found the possibility how to significantly speedup the "ischange" function in a case when input data are in matrix form and change point analysis is performed along columns (dim =1) or rows (dim =2) by simple parallelization (if Parallel computing toolbox is available).
Modification of ischange.m -> ischange_parallel.m by simple replacing for -> parfor:
% ischange_parallel.m (R2020b)
% Apply the ischange algorithm to each column
if nargout > 1
S1 = B;
S2 = B;
parfor (k = 1:ncolsA,numWorkers)
[TF(:,k),S1(:,k),S2(:,k)] = ischangeArrayColumn(B(:,k),args{:}); % line 166
end
else
parfor (k = 1:ncolsA,numWorkers)
TF(:,k) = ischangeArrayColumn(B(:,k),args{:}); % line 170
end
end
where numWorkers specify required number of workers. For numWorkers = 0 is the behaviour of ischange function fully unchanged.
This modification brings significant speed up (depending on number of available Workers).
>> A = rand(1e5,100);
>> tic;[TF,S1,S2] = ischange(A,'linear',1,'Threshold',.1);toc
Elapsed time is 36.320765 seconds.
>> tic;[TF_,S1_,S2_] = ischange_parallel(A,'linear',1,'Threshold',.1);toc
Elapsed time is 5.818893 seconds.
>> isequal([TF,S1,S2],[TF_,S1_,S2_])
ans =
logical
1
>> maxNumCompThreads
ans =
8
I think there are a lot of other MATLAB functions that could benefit significantly from parallelization, but as long as the Parallel Computing toolkit remains as an extra parallel extension, there is no chance of speeding up these functions. BTW, maybe it's time to consider incorporating of the Parallel toolbox functionality into MATLAB?
Any comments or recommendations?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by