MathGroup Archive 2010

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

Search the Archive

Re: Any answer for this ParallelDo error

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108884] Re: Any answer for this ParallelDo error
  • From: Zach Bjornson <bjornson at mit.edu>
  • Date: Tue, 6 Apr 2010 07:22:52 -0400 (EDT)

Hello Pratip,

You can use ParallelTable instead of ParallelDo. Even in non-parallel 
mode, Table is faster than Do (here it worked out to about 1.4x faster).

a = ParallelTable[If[PrimeQ[(i^3 + j^5)] == True, 1, 0], {i, 1, 20}, {j, 
1, 50}]

However, when I tested this with your tiny range of i and js, there was 
no speedup. Change to {i, 200} and {j, 500} gave a 2.42x speedup in 
parallel.

-Zach

On 4/5/2010 8:01 AM, pratip wrote:
> Hallo Group,
>
> Here is a harmless piece of code.
>
> Clear[a];
> t=AbsoluteTime[];
> a=ParallelTable[0,{i,1,20},{j,1,50}];
> DistributeDefinitions[a];
> mat=ParallelDo[a[[i,j]]=If[PrimeQ[(i^3+j^5)]==True,1,0],{i,1,20},{j,
> 1,50}];
> AbsoluteTime[]-t
>
> The error is something like
>
> Set::noval: Symbol a in part assignment does not have an immediate value.
> Set::noval: Symbol a in part assignment does not have an immediate value.
>
> I know there is a way of using SetSharedVariable but that version of
> the code is very slow.
>
> Clear[a];
> t=AbsoluteTime[];
> a=ParallelTable[0,{i,1,20},{j,1,50}];
> SetSharedVariable[a];
> mat=ParallelDo[a[[i,j]]=If[PrimeQ[(i^3+j^5)]==True,1,0],{i,1,20},{j,
> 1,50}];
> Print[a//ArrayPlot];
> AbsoluteTime[]-t
>
> Time taken: 6.1443514
>
> The single processor version is much faster
>
> Clear[a];
> t=AbsoluteTime[];
> a=Table[0,{i,1,20},{j,1,50}];
> mat=Do[a[[i,j]]=If[PrimeQ[(i^3+j^5)]==True,1,0],{i,1,20},{j,1,50}];
> Print[a//ArrayPlot];
> AbsoluteTime[]-t
>
> Time taken: 0.0360021
>
> My question is why I cant distribute the definition of a array to my
> processor kernels.
> Hope someone can give me an answer. I need to make this Do loop
> parallel.
>
> Yours,
>
> Pratip
>
>    


  • Prev by Date: Mathematica Programming
  • Next by Date: Arrangements
  • Previous by thread: Any answer for this ParallelDo error
  • Next by thread: Re: Any answer for this ParallelDo error