File Exchange

image thumbnail

Waitbar for Parfor

version 1.0.0 (2.53 KB) by Yun Pu
Waitbar or wait message for parfor or for loop.


Updated 31 Mar 2019

View License

This script generates a waitbar or a wait message including (1) the percentage finished; (2) the time used; and (3) the estimated remaining time for parfor or other types of loop. The script uses "parallel.pool.DataQueue" to collect information from workers.

Example.m provides an example. Basically, we need to construct the object right before the loop, send a message to the object within the loop, and destroy the object after the loop.

N = 100000;
WaitMessage = parfor_wait(N, 'Waitbar', true);
parfor i = 1: N

Cite As

Yun Pu (2021). Waitbar for Parfor (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Xingwang Yong

Excellent work! Thank you very much.

Alex Ogren

Awesome! The only reason I gave 4 instead of 5 is because I find that the estimated remaining time is not very accurate when used in my application.

Xin Liu

Hello, Yun Pu, this is a good function, but it would show warnings when I clike the 'cancel' button of the waitbar during the parfor loop.
For more details, MATLAB shows:
"警告: 第二个参数必须为消息字符向量或现有进度条的句柄。 "
Do you know how to fix it?
Thanks sincerely!

Good job Yun Pu, I modified it a bit to show the time in HH hours MM min SS sec format:

In your code, put:
WaitMessage = parfor_wait(It,'Waitbar',true,'ReportInterval',1);
parfor i=1:N

In the function, replace the following lines:
Line 53: Obj.WaitbarHandle = waitbar(0,[num2str(0), '% Please wait'], 'Resize', true','Units', 'centimeters','Position', [4,3,9.68,2.8]);
Line 90: waitbar(Obj.NumMessage/Obj.TotalMessage, Obj.WaitbarHandle,{['Completed: ',num2str(Obj.NumMessage/Obj.TotalMessage*100,'%.2f'), '% '],['in ',num2str(floor(UsedTime_now/3600), '%.2f'), ' hours ', num2str(floor(rem(UsedTime_now,3600)/60), '%.2f'), ' min and ', num2str(60*((rem(UsedTime_now,3600)/60)-floor(rem(UsedTime_now,3600)/60)), '%.2f'), ' sec'],['Estimated time needed: ', num2str(floor(EstimatedTimeNeeded/3600), '%.2f'), ' hours ', num2str(floor(rem(EstimatedTimeNeeded,3600)/60), '%.2f'), ' min and ', num2str(60*((rem(EstimatedTimeNeeded,3600)/60)-floor(rem(EstimatedTimeNeeded,3600)/60)), '%.2f'), ' sec']});

MATLAB Release Compatibility
Created with R2019a
Compatible with R2017a to R2019a
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!