MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ProgressIndicator and ParallelTable problem :(

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117933] Re: ProgressIndicator and ParallelTable problem :(
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Tue, 5 Apr 2011 06:41:36 -0400 (EDT)
  • References: <inc6no$11g$1@smc.vnet.net>

Hi,

> I am trying to use the ProgressIndicator with a parallel evaluation.
> If I just do the calculation inside a normal Table then the following
> piece of code works OK, ie the ProgressIndicator actually progresses.
> 
> In[1]:= ProgressIndicator[Dynamic[x],{1,8}]
> 
> In[2]:= Table[Pause[0.05];f[x],{x,1,8}]//AbsoluteTiming
> Out[2]= {0.4000228,{f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]}}

Honestly, I was surprised to see that this works at all, since Table is
a scoping construct, but it turns out that it behaves like Block for the
scoping and I found, again to my surprise, that this also triggers updates:

Dynamic[x]

Block[{x}, x = 1; Pause[1]; x =.]

Is this the intended behavior? It is a subtle point, but I think it
could explain some problems in complicated user interfaces that I
couldn't really understand but eventually got rid of by changing from
Block to Module in a few places (quite a desperate method of trial and
error). I can't remember that I have seen that mentioned in the docs, is
it mentioned somewhere or is it assumed that a reasonable experienced
user would expect this? After I have seen it and thought about it I
don't find it that surprising anymore, but I think it would be worth a
"possible issues" note in an appropriate place.

> However, if I use the ParallelTable instead, then the calculation is
> done much faster as expected but the ProgressIndicator does not work.
> 
> In[3]:= ParallelTable[Pause[0.05];f[x],{x,1,8}]//AbsoluteTiming
> Out[3]= {0.0650038,{f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8]}}
> 
> Any ideas why this happens?

I don't exactly know how ParallelTable internally is implemented, but it
doesn't come as a big surprise that it is not working, since the
asignment of x has to be done in the parallel kernels, and since x on
each kernel has a differnt value at one point in time, there is no
clearly defined global value for x per se. It would of course be
possible to somehow maintain a global value on the master, but that
would mean additional overhead due to the synchronizing that would be
necessary for that. Obviously that is not how it was implemented, and
most probably for good reasons.

> To make my question more clear, what I would like to be able to do is
> to have the ProgressIndicator update every time one of the parallel
> Kernels finishes its calculation, with 100% achieved when all
> calculations are done. Is there any way this can be achieved?

One way to achieve what you want without an explicitly synchronized
global variable (which might do harm to the performance) is with the
more complicated but also more powerful functions ParallelSubmit and
WaitNext:

ProgressIndicator[Dynamic[n], {1, 8}]
(
res = Table[Null, {8}];
jobs = Table[ParallelSubmit[{x}, Pause[0.05]; f[x]], {x, 1, 8}];
Do[{res[[n]], b, jobs} = WaitNext[jobs], {n, 1, 8}];
  res) // AbsoluteTiming

I wouldn't be surprised if ParallelTable behind the scene does something
very similar but with slightly less overhead as one can guess from the
timings...

hth,

albert


  • Prev by Date: Re: WebMathematica and SVG graphics
  • Next by Date: Re: Mathematica 8.01 and the CDF plug-in
  • Previous by thread: ProgressIndicator and ParallelTable problem :(
  • Next by thread: Re: ProgressIndicator and ParallelTable problem :(