Re: Any answer for this ParallelDo error

*To*: mathgroup at smc.vnet.net*Subject*: [mg108896] Re: Any answer for this ParallelDo error*From*: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>*Date*: Tue, 6 Apr 2010 07:25:14 -0400 (EDT)

Hi, you know what a shared variable is? You know that there's a lot to do for the ParallelDo to manage exclusive write-accesses to your "a" for every single subkernel? What you want is to "build the parts of the solution list and to merge them to the final solution at the end". {t1, mat1} = AbsoluteTiming[ ParallelTable[ If[PrimeQ[(i^3 + j^5)] == True, 1, 0], {i, 1, 20}, {j, 1, 50}]]; Your code is not what you really want at different places: - why you are initializing an array with 0 and storing your elements in it? You just have to build your matrix. - what do you think is in your variable "mat"? - using ParallelTable to initialize/allocate an array is really making the stuff slow. There's nothing to do for the subkernels and the overhead of parallelization is far too big. Btw, to really take advantages of parallelization your calculations inside the loop should really be more complex. This makes the the subkernels really have to compute something and they are not kept busy moving memory-contents back and forth. Hope this helps a bit. Cheers Patrick On Mon, 2010-04-05 at 08:01 -0400, 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 >