MATLAB Answers

possible speed up of the ischange function by parfor

2 views (last 30 days)
Michal Kvasnicka
Michal Kvasnicka on 15 Oct 2020
Edited: Michal Kvasnicka on 15 Oct 2020
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 Comments

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