possible speed up of the ischange function by parfor

8 views (last 30 days)
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
parfor (k = 1:ncolsA,numWorkers)
TF(:,k) = ischangeArrayColumn(B(:,k),args{:}); % line 170
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 =
>> maxNumCompThreads
ans =
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?

Answers (0)


Find more on Conway's Game of Life in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!