Thread Subject:
waitbar for parfor loops

Subject: waitbar for parfor loops

From: William Dampier

Date: 21 Mar, 2008 16:02:01

Message: 1 of 7

I was wondering if anyone has found a way to do progressbars
for the new parfor loops in R2007b and 2008a.

For normal for-loops the simple waitbar command works well.
waitbar(0)
for i=1:N
waitbar(i/N)
...do something
end

however it doesn't work with the parfor loops, since things
aren't done in order.

Has anybody made a function or found a work-around?

Thanks
Will

Subject: waitbar for parfor loops

From: Narfi

Date: 21 Mar, 2008 18:07:02

Message: 2 of 7

William,

Currently, there is unfortunately no way of receiving
notification in the MATLAB client when an iteration is
completed on a worker.

Best,

Narfi
"William Dampier" <walldo2@gmail.com> wrote in message
<fs0m5p$nkd$1@fred.mathworks.com>...
> I was wondering if anyone has found a way to do progressbars
> for the new parfor loops in R2007b and 2008a.
>
> For normal for-loops the simple waitbar command works well.
> waitbar(0)
> for i=1:N
> waitbar(i/N)
> ...do something
> end
>
> however it doesn't work with the parfor loops, since things
> aren't done in order.
>
> Has anybody made a function or found a work-around?
>
> Thanks
> Will

Subject: waitbar for parfor loops

From: William Dampier

Date: 21 Mar, 2008 19:12:01

Message: 3 of 7

You don't necessarily need something that communicates when
an iteration is done ... you just need something that can
tell a waitbar to update.

I've tried something along these lines so far, maybe it will
inspire someone with more knowledge of the callback systems.

N=100;
BEEN_DONE_VEC=false(N,1)
wait_handle=waitbar(0);
parfor (IND=1:N)
BEEN_DONE_VEC(IND)=true;
waitbar(wait_handle,mean(BEEN_DONE_VEC))
...do something
end

In this case it doesn't matter that the operations are not
done in order, since it just updates it with the fraction of
instances that are completed. The only problem I have is
figuring out how to pass an 'update' type call to waitbar.




"Narfi " <narfi.stefansson@mathworks.com> wrote in message
<fs0tg5$qdq$1@fred.mathworks.com>...
> William,
>
> Currently, there is unfortunately no way of receiving
> notification in the MATLAB client when an iteration is
> completed on a worker.
>
> Best,
>
> Narfi
> "William Dampier" <walldo2@gmail.com> wrote in message
> <fs0m5p$nkd$1@fred.mathworks.com>...
> > I was wondering if anyone has found a way to do progressbars
> > for the new parfor loops in R2007b and 2008a.
> >
> > For normal for-loops the simple waitbar command works well.
> > waitbar(0)
> > for i=1:N
> > waitbar(i/N)
> > ...do something
> > end
> >
> > however it doesn't work with the parfor loops, since things
> > aren't done in order.
> >
> > Has anybody made a function or found a work-around?
> >
> > Thanks
> > Will
>

Subject: waitbar for parfor loops

From: jochen Kamm

Date: 3 Nov, 2009 19:27:03

Message: 4 of 7

> N=100;
> BEEN_DONE_VEC=false(N,1)
> wait_handle=waitbar(0);
> parfor (IND=1:N)
> BEEN_DONE_VEC(IND)=true;
> waitbar(wait_handle,mean(BEEN_DONE_VEC))
> ...do something
> end

I had a similar idea. Matlab did not accept it though, since it will regard the mean(...) command (I used sum(...)) as something inconsistent as it varies with the order of the parfor loop execution - of which all results of course should be independent.

I thought of something more basic then:

fprintf(repmat('*',1,N));
parfor ind = 1 : N
    fprintf('\b')
    ...
end

if N is too large fractioning is be necessary. Its crude but it works.

fractioning in parts n, choose n appriopriatly:
M = numel(find(mod(1:N,n)==0));
fprintf(repmat('*',1,M));
parfor ind = 1 : N
    if mod(ind,n)==0; fprintf('\b'); end
    ...
end

Subject: waitbar for parfor loops

From: Gil Georges

Date: 20 Nov, 2009 12:49:05

Message: 5 of 7

the following works for me:

function testParFor()

Subject: waitbar for parfor loops

From: Daniel

Date: 29 Feb, 2012 05:25:10

Message: 6 of 7

"Will Dampier" wrote in message <fs0m5p$nkd$1@fred.mathworks.com>...
> I was wondering if anyone has found a way to do progressbars
> for the new parfor loops in R2007b and 2008a.
>
> For normal for-loops the simple waitbar command works well.
> waitbar(0)
> for i=1:N
> waitbar(i/N)
> ...do something
> end
>
> however it doesn't work with the parfor loops, since things
> aren't done in order.
>
> Has anybody made a function or found a work-around?
>
> Thanks
> Will

I have done some searching myself and the only work around I could find is wiriting to a file and reading that file. (messy and slow). You still cannot update the waitbar at each parfor iteration....BUT....you can do x number of iterations in a parfor loop and then update the waitbar (i.e. loop a parfor loop and update each time parfor finishes). For example do the following:

matlabpool;
matlabpoolsize = matlabpool('size');
% do a for loop that is big enough to do all necessary iterations
for n=1:matlabpoolsize:ceil(length(testLengths/matlabpoolsize))
    parfor z = n:min(n+(matlabpoolsize-1),length(testLengths))
        % iteration code here
        % note that z will be your iteration
    end
    % update waitbar each "matlabpoolsize"th iteration
    waitbar(n/ceil(length(testLengths/matlabpoolsize)),wb);
end
close(wb);
matlabpool('close');

Subject: waitbar for parfor loops

From: Edric M Ellis

Date: 29 Feb, 2012 08:32:38

Message: 7 of 7

"Daniel " <ddalgleish@gmail.com> writes:

>> I was wondering if anyone has found a way to do progressbars
>> for the new parfor loops in R2007b and 2008a.

> I have done some searching myself and the only work around I could
> find is wiriting to a file and reading that file.

I have a similar workaround, but using sockets so it's possibly a tiny
bit tidier. It's here:

http://www.mathworks.com/matlabcentral/fileexchange/24594-parfor-progress-monitor

Cheers,

Edric.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
computing Daniel 29 Feb, 2012 00:29:18
iterations Daniel 29 Feb, 2012 00:29:18
matlabpool Daniel 29 Feb, 2012 00:29:18
parfor Daniel 29 Feb, 2012 00:29:18
parallel Daniel 29 Feb, 2012 00:29:18
waitbar Daniel 29 Feb, 2012 00:29:18
waitbar Will Dampier 21 Mar, 2008 12:05:03
parfor Will Dampier 21 Mar, 2008 12:05:03
rssFeed for this Thread

Contact us