Thread Subject: waitbar for parfor loops

Subject: waitbar for parfor loops

From: William Dampier

Date: 21 Mar, 2008 16:02:01

Message: 1 of 5

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 5

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 5

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 5

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

the following works for me:

function testParFor()

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
parfor Will Dampier 21 Mar, 2008 12:05:03
waitbar Will Dampier 21 Mar, 2008 12:05:03
rssFeed for this Thread

Contact us at files@mathworks.com