progressDemo

版本 1.0.0 (1.4 KB) 作者: Shlomo Geva
A demo of a very simple progress monitor for parfor
6.0 次下载
更新时间 2021/2/14

查看许可证

The following function demonstrates a very simple progress monitor for parfor.
All you need is to follow the example.

function progressDemo(~)
% Function demonstrating a simple progress monitor for parfor.

if isempty(gcp('nocreate'))
parpool('local',8); % start 8 threads (if not already running)
end

D = parallel.pool.DataQueue;
afterEach(D, @UpdateProgress);
updateFreq=100; % loop update frequency
p=1; % loop counter; note: need p defined outside of parfor scope

fprintf('\nProgress: 0%%');
N=12345; % number of iterations, done in parallel
parfor n=1:N
% DO SOMETHING
send(D,n); % update progress
end
fprintf('\b\b\b\b\b\b%5.2f%%',100);
fprintf('\nDone!!\n')

function UpdateProgress(~) % note: nested function
% using \b because \r and Matlab do not get along on all platforms...
p = p + 1;
if ~rem(p,updateFreq) % only show progress every updateFreq iterations
fprintf('\b\b\b\b\b\b%5.2f%%',p/N*100);
end
end
end

引用格式

Shlomo Geva (2024). progressDemo (https://www.mathworks.com/matlabcentral/fileexchange/87367-progressdemo), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2020b
与 R2017a 及更高版本兼容
平台兼容性
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0