MathGroup Archive 2009

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

Search the Archive

Re: Re: ParrallelDo and set::noval

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102744] Re: [mg102697] Re: ParrallelDo and set::noval
  • From: Fred Simons <f.h.simons at tue.nl>
  • Date: Tue, 25 Aug 2009 01:45:29 -0400 (EDT)
  • References: <h63cgg$1b6$1@smc.vnet.net> <h6duf8$h1c$1@smc.vnet.net> <200908191102.HAA26430@smc.vnet.net>

Many have already reported that the correct way for solving the problem 
is using SetSharedVariable instead of DistributeDefinitions.

But part of the original posting was also the observation that 
DistributeDefinitions was not enough to make the definition available to 
all subkernels. Though in this form that remark is not correct, there is 
something strange here that I cannot explain.

As an introduction, start with a fresh kernel and execute the following.

zzz=12;
ParallelEvaluate[zzz=RandomInteger[{0,5}]];
Information[zzz];
ParallelEvaluate[Information[zzz]];

The kernel works in the default context Global` and each subkernel has 
its own context Global`, independent of the normal Global context. Since 
I use a dual core computer, my output shows three variables zzz, one in 
the standard context Global` and two in the two subkernel contexts 
Global`. The three values are different, so the three variables are 
different, despite that they have the same name and seem to be in the 
same context.

Now another variant of the original problem, that produces the 
remarkable Set::noval message.

m=Range[5];
DistributeDefinitions[m];
ParallelDo[Print[{i, m, m[[i]]}];m[[i]]=0;Print[m], {i,1,5}]

In the output we see which subkernel tried to do what. The message that 
the symbol m in part assignment does not have an immediate value is very 
strange, since each subkernel was able to compute both m and m[[i]]. It 
seems to be the assignment to m[[i]] that generates the message, for 
here are two pieces of code that do work (and of course produce 
different values for m in each of the three contexts Global`); they 
assign to m instead of to m[[i]].

m=Range[5];
DistributeDefinitions[m];
ParallelDo[Print[{i, m, m[[i]]}];m=ReplacePart[m, i->0];Print[m], {i,1,5}]
m
ParallelEvaluate[m]

m=Range[5];
DistributeDefinitions[m];
ParallelDo[Print[{m,i}];m=Flatten[{Take[m, i-1],0, Drop[m, 
i]}];Print[m], {i,1,5}]
m
ParallelEvaluate[m]

Does someone have an explanation why, in this very theoretical 
situation, assignment to m is possible and assignment to a part of m not?

Fred Simons
Eindhoven University of Technology


  • Prev by Date: TeamDrive and Mathematica Stylesheets
  • Next by Date: Re: Re: ParrallelDo and set::noval
  • Previous by thread: Re: ParrallelDo and set::noval
  • Next by thread: Re: Re: ParrallelDo and set::noval