Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: waitbar for parfor loops
Date: Tue, 3 Nov 2009 19:27:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <hcq066$53c$1@fred.mathworks.com>
References: <fs0m5p$nkd$1@fred.mathworks.com> <fs0tg5$qdq$1@fred.mathworks.com> <fs11a1$9nh$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257276423 5228 172.30.248.37 (3 Nov 2009 19:27:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Nov 2009 19:27:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2075219
Xref: news.mathworks.com comp.soft-sys.matlab:582143


> 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