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 |
|
//import jsr166y.*; |
8 |
|
import java.util.concurrent.*; |
9 |
– |
import java.util.concurrent.TimeUnit; |
10 |
– |
|
9 |
|
|
10 |
|
/** |
11 |
|
* LU matrix decomposition demo |
26 |
|
|
27 |
|
int procs = 0; |
28 |
|
int n = 2048; |
29 |
< |
int runs = 5; |
29 |
> |
int runs = 32; |
30 |
|
try { |
31 |
|
if (args.length > 0) |
32 |
|
procs = Integer.parseInt(args[0]); |
43 |
|
System.out.println(usage); |
44 |
|
return; |
45 |
|
} |
46 |
< |
ForkJoinPool pool = procs == 0? new ForkJoinPool() : |
46 |
> |
ForkJoinPool pool = (procs == 0) ? ForkJoinPool.commonPool() : |
47 |
|
new ForkJoinPool(procs); |
48 |
|
System.out.println("procs: " + pool.getParallelism() + |
49 |
|
" n: " + n + " runs: " + runs); |
64 |
|
pool.invoke(new LowerUpper(n, M)); |
65 |
|
long time = System.nanoTime() - start; |
66 |
|
double secs = ((double)time) / NPS; |
67 |
< |
System.out.printf("\tTime: %7.3f\n", secs); |
67 |
> |
System.out.printf("Time: %7.3f ", secs); |
68 |
> |
if ((run & 3) == 3) System.out.println(); |
69 |
|
|
70 |
|
if (CHECK) check(m, copy, n); |
71 |
|
} |
73 |
|
pool.shutdown(); |
74 |
|
} |
75 |
|
|
77 |
– |
|
76 |
|
static void randomInit(double[][] M, int n) { |
77 |
|
java.util.Random rng = new java.util.Random(); |
78 |
|
for (int i = 0; i < n; ++i) |
103 |
|
System.out.println("Max difference = " + maxDiff); |
104 |
|
} |
105 |
|
|
108 |
– |
|
106 |
|
// Blocks record underlying matrix, and offsets into current block |
107 |
|
static final class Block { |
108 |
|
final double[][] m; |
215 |
|
Block L10 = new Block(L.m, L.loRow+h, L.loCol); |
216 |
|
Block L11 = new Block(L.m, L.loRow+h, L.loCol+h); |
217 |
|
|
221 |
– |
|
218 |
|
Seq3 s1 = |
219 |
|
seq(new Lower(h, L00, M00), |
220 |
|
new Schur(h, L10, M00, M10), |
230 |
|
} |
231 |
|
} |
232 |
|
|
237 |
– |
|
233 |
|
static final class Upper extends RecursiveAction { |
234 |
|
final int size; |
235 |
|
final Block U; |
253 |
|
} |
254 |
|
} |
255 |
|
|
261 |
– |
|
256 |
|
public void compute() { |
257 |
|
if (size == BLOCK_SIZE) { |
258 |
|
upper(); |
285 |
|
} |
286 |
|
} |
287 |
|
|
294 |
– |
|
288 |
|
static final class LowerUpper extends RecursiveAction { |
289 |
|
final int size; |
290 |
|
final Block M; |
372 |
|
thr.invoke(); |
373 |
|
} |
374 |
|
} |
382 |
– |
|
383 |
– |
|
384 |
– |
|
375 |
|
} |
386 |
– |
|