MathGroup Archive 2009

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

Search the Archive

Re: Re: ParrallelDo and set::noval

  • To: mathgroup at
  • Subject: [mg102742] Re: [mg102697] Re: ParrallelDo and set::noval
  • From: Patrick Scheibe <pscheibe at>
  • Date: Tue, 25 Aug 2009 01:45:07 -0400 (EDT)
  • References: <h63cgg$1b6$> <h6duf8$h1c$>


you only missed *how* the definitions are distributed. I give an example
and you should see the rest by yourself:

k := {1, 2, 3, 4}
k[[3]] = 2

ups, what happens here?


On Mon, 2009-08-24 at 20:30 +0200, Fred Simons wrote:
> 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: Re: Re: ParrallelDo and set::noval
  • Next by Date: Re: Re: Viewing packages in mathematica
  • Previous by thread: Re: Re: Re: ParrallelDo and set::noval
  • Next by thread: ListLogLinearPlot with two y-axis