Re: Re: ParrallelDo and set::noval
- To: mathgroup at smc.vnet.net
- Subject: [mg102704] Re: [mg102697] Re: ParrallelDo and set::noval
- From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
- Date: Thu, 20 Aug 2009 04:55:30 -0400 (EDT)
- References: <h63cgg$1b6$1@smc.vnet.net> <h6duf8$h1c$1@smc.vnet.net>
Hi,
why do you create the table in the first place? Just let ParallelTable
collect your data:
grid = Range[4, 50, 0.5];
DistributeDefinitions[grid];
testArray1 = ParallelTable[
{i, If[4 <= grid[[i]] <= 50, 1, 0]}, {i, 1, Length[grid]}]
but if you insist to know what was wrong with your code, please have a
look at SetSharedVariable[...]
grid = Range[4, 50, 0.5];
testArray = Array[Null, {Length[grid]}];
DistributeDefinitions[grid];
SetSharedVariable[testArray];
ParallelDo[iroot = 0;
rr = grid[[i]];
Which[4 <= rr <= 50, iroot = 1];
testArray[[i]] = {i, iroot};, {i, 1, Length[grid]}]
testArray===testArray1
Out[12]= True
Cheers
Patrick
On Wed, 2009-08-19 at 07:02 -0400, guerom00 wrote:
> As requested, a minimal example which illustrate the problem.
>
> The following sequential code works fine :
>
> grid = Range[4, 50, 0.5];
> testArray = Array[Null, {Length[grid]}];
>
> Do[
> iroot = 0;
> rr = grid[[i]];
> Which[
> 4 <= rr <= 50, iroot = 1
> ];
> testArray[[i]] = {i, iroot};
> , {i, 1, Length[grid]}]
>
>
> The equivalent parallel code :
>
> grid = Range[4, 50, 0.5];
> testArray = Array[Null, {Length[grid]}];
>
> DistributeDefinitions[grid,testArray];
>
> ParallelDo[
> iroot = 0;
> rr = grid[[i]];
> Which[
> 4 <= rr <= 50, iroot = 1
> ];
> testArray[[i]] = {i, iroot};
> , {i, 1, Length[grid]}]
>
> returns "Set::noval: Symbol testArray in part assignment does not have
> an immediate value." Somehow the DistributeDefinitions[] is not
> sufficient to indicate to each kernel that I have initialized the list
> testArray.
>
> Thanks in advance for any help :)
>