A simple ParallelDo problem

• To: mathgroup at smc.vnet.net
• Subject: [mg108795] A simple ParallelDo problem
• From: pratip <pratip.chakraborty at gmail.com>
• Date: Thu, 1 Apr 2010 05:58:38 -0500 (EST)

```Dear Group Members,
Here is a typical problem of mathematica parallel computation tools.
First form a airfoil in 2D
(*Geometry*)
Clear[x];
n0;
c=0.09;
p=0.24;
t=0.05;
camber:=c If[x<p,(2p x-x^2)/p^2,((1-2p)+2p x-x^2)/(1-p)^2];
theta=ArcTan[D[camber,x]];
p=Table[
x=0.5(1-Cos[Pi s]);
x1=1.00893x;
thk=5t (0.2969Sqrt[x1]-0.126x1-0.3516x1^2+0.2843x1^3-0.1015x1^4);
{x,camber}+Sign[s]thk {-Sin[theta],Cos[theta]},
{s,-1,1,2/(n-1)}];
ListPlot[10p,AspectRatio->Automatic]

Now we set some values
(* Some variable are set*)
pt=10p;
alpha=Pi/19;
pc=Table[(pt[[i]]+pt[[i+1]])/2,{i,1,n-1}];
s=Table[v=pt[[i+1]]-pt[[i]];Sqrt[v.v],{i,1,n-1}];
theta=Table[v=pt[[i+1]]-pt[[i]];
ArcTan[v[[1]],v[[2]]],
{i,1,n-1}];
sin=Sin[theta];
cos=Cos[theta];
Cn1=Cn2=Ct1=Ct2=Table[0,{n-1},{n-1}];

Distribute to the parallel kernels
(*Definitions distribution*)
DistributeDefinitions[p, alpha, pc, s, theta, sin, cos, Cn1, Cn2, Ct1,
Ct2, n, c, pt, t]

Now comes the problem

(*Parallel Computation*)
tim=AbsoluteTime[];
ParallelDo[
If[i==j,
{Cn1[[i,j]]=-1;
Cn2[[i,j]]=1;
Ct1[[i,j]]=Ct2[[i,j]]=Pi/2},
{v=pc[[i]]-pt[[j]];
a=-v.{cos[[j]],sin[[j]]};
b=v.v;
t=theta[[i]]-theta[[j]];
c=Sin[t];
d=Cos[t];
e=v.{sin[[j]],-cos[[j]]};
f=Log[1+s[[j]](s[[j]]+2a)/b];
g=ArcTan[b+a s[[j]],e s[[j]]];
t=theta[[i]]-2theta[[j]];
p1=v.{Sin[t],Cos[t]};
q=v.{Cos[t],-Sin[t]};
Cn2[[i,j]]=d+(0.5q f-(a c+d e)g)/s[[j]];
Cn1[[i,j]]=0.5d f+c g-Cn2[[i,j]];
Ct2[[i,j]]=c+0.5p1 f/s[[j]]+(a d-c e)g/s[[j]];
Ct1[[i,j]]=0.5c f-d g-Ct2[[i,j]]}]
,{i,1,n-1},{j,1,n-1}];
AbsoluteTime[]-tim

The error is returned as

Set::noval: Symbol Cn1 in part assignment does not have an immediate
value.
Set::noval: Symbol Cn2 in part assignment does not have an immediate
value.

However if you replace the ParallelDo with simple Do results come in
7.0554036 sec.
I need to make the problem parallel. I have 8 cores to so for a simple
problem like this
I must get a timing like less than 1 sec.
Hope someone will help.
Another question is if I have a package (<<Mypackage`) and I want to
distribute all the function definitions of this package fully
available to the parallel kernels how to do that? Parallel computation
does not seem to be so simple as it turns out to be when you just
consider the documentation examples. How to make all the information
(variables, functions,data) available to the Master kernel also
available to the launched parallel kernels at once. Memeory is not a
problem.

best regards,
Pratip

```

• Prev by Date: Re: How to do numerical computations?
• Next by Date: Re: a little nasty problem?
• Previous by thread: Re: a little nasty problem?
• Next by thread: Re: A simple ParallelDo problem