1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
// Adapted from a cilk benchmark |
47 |
|
return; |
48 |
|
} |
49 |
|
|
50 |
< |
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
50 |
> |
ForkJoinPool g = (procs == 0) ? new ForkJoinPool() : |
51 |
|
new ForkJoinPool(procs); |
52 |
< |
|
52 |
> |
|
53 |
|
System.out.print("parallelism = " + g.getParallelism()); |
54 |
|
System.out.print(" granularity = " + leafmaxcol); |
55 |
|
System.out.print(" rows = " + nx); |
56 |
|
System.out.print(" columns = " + ny); |
57 |
|
System.out.println(" steps = " + nt); |
58 |
< |
|
58 |
> |
|
59 |
|
oldm = new double[nx][ny]; |
60 |
|
newm = new double[nx][ny]; |
61 |
|
|
91 |
|
|
92 |
|
static final double dx = (xo - xu) / (nx - 1); |
93 |
|
static final double dy = (yo - yu) / (ny - 1); |
94 |
< |
static final double dt = (to - tu) / nt; |
94 |
> |
static final double dt = (to - tu) / nt; |
95 |
|
static final double dtdxsq = dt / (dx * dx); |
96 |
|
static final double dtdysq = dt / (dy * dy); |
97 |
|
|
98 |
|
|
99 |
|
// the function being applied across the cells |
100 |
< |
static final double f(double x, double y) { |
101 |
< |
return Math.sin(x) * Math.sin(y); |
100 |
> |
static final double f(double x, double y) { |
101 |
> |
return Math.sin(x) * Math.sin(y); |
102 |
|
} |
103 |
|
|
104 |
|
// random starting values |
105 |
|
|
106 |
< |
static final double randa(double x, double t) { |
107 |
< |
return 0.0; |
106 |
> |
static final double randa(double x, double t) { |
107 |
> |
return 0.0; |
108 |
|
} |
109 |
< |
static final double randb(double x, double t) { |
110 |
< |
return Math.exp(-2*t) * Math.sin(x); |
109 |
> |
static final double randb(double x, double t) { |
110 |
> |
return Math.exp(-2*t) * Math.sin(x); |
111 |
|
} |
112 |
< |
static final double randc(double y, double t) { |
113 |
< |
return 0.0; |
112 |
> |
static final double randc(double y, double t) { |
113 |
> |
return 0.0; |
114 |
|
} |
115 |
< |
static final double randd(double y, double t) { |
116 |
< |
return Math.exp(-2*t) * Math.sin(y); |
115 |
> |
static final double randd(double y, double t) { |
116 |
> |
return Math.exp(-2*t) * Math.sin(y); |
117 |
|
} |
118 |
< |
static final double solu(double x, double y, double t) { |
119 |
< |
return Math.exp(-2*t) * Math.sin(x) * Math.sin(y); |
118 |
> |
static final double solu(double x, double y, double t) { |
119 |
> |
return Math.exp(-2*t) * Math.sin(x) * Math.sin(y); |
120 |
|
} |
121 |
|
|
122 |
|
|
132 |
|
ub = upperBound; |
133 |
|
time = timestep; |
134 |
|
} |
135 |
< |
|
135 |
> |
|
136 |
|
public void compute() { |
137 |
|
if (ub - lb > leafmaxcol) { |
138 |
|
int mid = (lb + ub) >>> 1; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
< |
/** Update all cells **/ |
153 |
> |
/** Updates all cells. */ |
154 |
|
final void compstripe(double[][] newMat, double[][] oldMat) { |
155 |
|
|
156 |
|
// manually mangled to reduce array indexing |
184 |
|
nv[b] = cell |
185 |
|
+ dtdysq * (prev - twoc + next) |
186 |
|
+ dtdxsq * (east[b] - twoc + west[b]); |
187 |
– |
|
187 |
|
} |
188 |
|
} |
189 |
|
|
190 |
< |
edges(newMat, llb, lub, tu + time * dt); |
190 |
> |
edges(newMat, llb, lub, tu + time * dt); |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
// the original version from cilk |
195 |
|
final void origcompstripe(double[][] newMat, double[][] oldMat) { |
196 |
< |
|
196 |
> |
|
197 |
|
final int llb = (lb == 0) ? 1 : lb; |
198 |
|
final int lub = (ub == nx) ? nx - 1 : ub; |
199 |
|
|
204 |
|
newMat[a][b] = cell |
205 |
|
+ dtdxsq * (oldMat[a+1][b] - twoc + oldMat[a-1][b]) |
206 |
|
+ dtdysq * (oldMat[a][b+1] - twoc + oldMat[a][b-1]); |
208 |
– |
|
207 |
|
} |
208 |
|
} |
209 |
|
|
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
< |
/** Initialize all cells **/ |
214 |
> |
/** Initializes all cells. */ |
215 |
|
final void init() { |
216 |
|
final int llb = (lb == 0) ? 1 : lb; |
217 |
|
final int lub = (ub == nx) ? nx - 1 : ub; |
218 |
|
|
219 |
< |
for (int a = llb; a < lub; a++) { /* inner nodes */ |
219 |
> |
for (int a = llb; a < lub; a++) { /* inner nodes */ |
220 |
|
double[] ov = oldm[a]; |
221 |
|
double x = xu + a * dx; |
222 |
|
double y = yu; |
227 |
|
} |
228 |
|
|
229 |
|
edges(oldm, llb, lub, 0); |
232 |
– |
|
230 |
|
} |
231 |
|
|
232 |
< |
/** Fill in edges with boundary values **/ |
232 |
> |
/** Fills in edges with boundary values. */ |
233 |
|
final void edges(double [][] m, int llb, int lub, double t) { |
234 |
|
|
235 |
|
for (int a = llb; a < lub; a++) { |
249 |
|
} |
250 |
|
|
251 |
|
if (ub == nx) { |
252 |
< |
double[] v = m[nx - 1]; |
252 |
> |
double[] v = m[nx - 1]; |
253 |
|
double y = yu; |
254 |
|
for (int b = 0; b < ny; b++) { |
255 |
|
y += dy; |