File Exchange

image thumbnail

parfor_progressbar

version 2.13.0.0 (4.97 KB) by Daniel Terry
Graphically monitors the completion of iterations in a parfor loop

13 Downloads

Updated 29 Jan 2016

View License

Creates a graphical progress indicator to monitor the completion of iterations in a long-running loop. The usage is similar to MATLAB's built in waitbar function, but it works with parfor loops in addition to ordinary for loops. A temporary file is written to by worker threads to record the completion of each parfor iteration and a timer periodically updates the progress bar. Through optional arguments that are passed to waitbar internally, the user can set a cancel button or any other option that waitbar supports. For now, only local execution is supported, but the function can be modified to replace tempdir with a location accessible by all workers.
Example usage:

N=50; %total number of parfor iterations
hbar = parfor_progressbar(N,'Please wait...'); %create the progress bar
parfor i=1:N,
pause(rand); % computation
hbar.iterate(1); % update progress by one iteration
end
close(hbar); % close the progress bar

Cite As

Daniel Terry (2019). parfor_progressbar (https://www.mathworks.com/matlabcentral/fileexchange/53773-parfor_progressbar), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (26)

Frerk Saxen

Multiple read and write to text file has some serios limitation: 1. very time consuming, 2. simulaneous read/write might cause some troubles, 3. only working on local pool.
I implemented my own parfor progress monitor based on udp sockets (No read/write problems, much, much faster and working not only on local pools).
It shows the remaining time and progress of each worker -> https://de.mathworks.com/matlabcentral/fileexchange/71436-parfor-progress-monitor-progress-bar-v4

Koen

Great function and easy to implement, But with large iterations i.e. 1000 I would highly recommend to increase the progress bar by 10 every tenth of a cycle to speed up the process. Time the parfor took without the progress bar: 60 seconds, with every iteration 205 seconds, every tenth: 66 seconds.
Just add this:
'''
if ~mod(i, 10)
hbar.iterate(10); % update progress by one iteration
end '''

Koen

Great function and easy to implement!

Would be nice to add percentage value to the progress bar

Alex

AA

Great function. Just what I needed. It is not restricted to parfor loops. I just used it with spmd blocks. Thanks.

Kris

Dave Lee

When I compare two cases of running with and without hbar.iterate(1), I see this progress bar makes parfor loop run more slowly

John

Great function, thanks!

Great function! It is a very nice feature in any code using parfor loops. I was just wondering if you ever considered Mo.En's suggestion of adding a percentage or a remaining time estimation?

Ali Komai

M V

Why I get the following error?

Error while evaluating TimerFcn for timer 'parfor_progressbar'
No public property 'ipcfile' for class 'parfor_progressbar'

Mo.En

Works pretty much as expected.

I have two suggestions:
1. Add percentage value, to the progress bar.
2. Add a general "Remaining Time" estimation

Zhengyi

if a cancel button is added, the waitbar can not be deleted:

hbar = parfor_progressbar(10,'Please wait...','CreateCancelBtn','@() disp(''cancelling'')');
close(hbar); % does not delete hbar
delete(hbar); % does not delete hbar either

Zhengyi

sorry, it should be

hbar = parfor_progressbar(10,'Please wait...','CreateCancelBtn','@() disp(''cancelling'')');

Shaan

Shachar

Daniel Terry

Tested and working on MATLAB 2016b.

Liang Wang

Great tool, useful for 2014 and 2015, but not working for 2016a anymore.

Useful!

Daniel Terry

Thank you for your kind review Geert.

I have some ideas of how to do this. The tricky part is that GUI objects are not updated within the parfor loop. It may be possible to add a callback for the waitbar window in the GUI thread that deletes the parfor_progress.txt status file to tell the parfor threads to stop.

I will keep you posted if I come up with something that works.

Nicely made and very useful. Thanks!
Just one question: I would like that upon closing the waitbar, the parfor loop stops (for instance, if the user sees that it will take ages for the algorithm to finish, he/she can choose to stop the processing).
So far, I did not manage to do this. My code

if isempty(hbar.wbh)
delete(gcp('nocreate'));
return
end

does not seem to work because the object handle wbh is not empty upon closing the waitbar. Any idea how I could manage this?

Thanks in advance. Cheers, Geert

Jon Dudley

Great submission, thanks.

Daniel Terry

This error was fixed in the recent version. Please try it again.

Shachar

when running it, the waitbar do not progress. and there is an worning:

Warning: This functionality is no longer supported under the -nodisplay and -noFigureWindows startup options. ...

Updates

2.13.0.0

Now supports both MATLAB 2014 and 2015. Using a class instead of graphics handle to fix warnings in worker threads and make it compatible with 2014. If you had a problem with the previous version, please try it again.

2.11.0.0

Added a picture and changed the title to emphasize that this is an extension of the built-in waitbar function.

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux