File Exchange

image thumbnail


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


Updated 29 Jan 2016

View Version History

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
close(hbar); % close the progress bar

Cite As

Daniel Terry (2021). parfor_progressbar (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (28)

Ali Komai

If you have many workers and many iterations the disk I/O operations degrade performance to such an extent making the use impossible.


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 ->


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 '''


Great function and easy to implement!

Ali Aghaeifar

Would be nice to add percentage value to the progress bar



Kristoffer Walker

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


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


Great function, thanks!

Julian Freedland

Eric Chadwick

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


Why I get the following error?

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


Works pretty much as expected.

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


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


sorry, it should be

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



Daniel Terry

Tested and working on MATLAB 2016b.

Liang Wang

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

Stefano Imoscopi


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.

Geert Verhoeven

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)

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.


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. ...

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

Community Treasure Hunt

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

Start Hunting!