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 java.util.*; |
14 |
|
static final long NPS = (1000L * 1000 * 1000); |
15 |
|
static int THRESHOLD; |
16 |
|
|
17 |
< |
public static void main (String[] args) throws Exception { |
17 |
> |
public static void main(String[] args) throws Exception { |
18 |
|
int procs = 0; |
19 |
|
int n = 1 << 25; |
20 |
|
int reps = 10; |
24 |
|
if (args.length > 1) |
25 |
|
n = Integer.parseInt(args[1]); |
26 |
|
if (args.length > 2) |
27 |
< |
reps = Integer.parseInt(args[1]); |
27 |
> |
reps = Integer.parseInt(args[2]); |
28 |
|
} |
29 |
|
catch (Exception e) { |
30 |
|
System.out.println("Usage: java FJSums threads n reps"); |
31 |
|
return; |
32 |
|
} |
33 |
< |
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
33 |
> |
ForkJoinPool g = (procs == 0) ? new ForkJoinPool() : |
34 |
|
new ForkJoinPool(procs); |
35 |
|
System.out.println("Number of procs=" + g.getParallelism()); |
36 |
|
// for now hardwire Cumulate threshold to 8 * #CPUs leaf tasks |
157 |
|
* internal nodes, it becomes true when one child is cumulated. |
158 |
|
* When second child finishes cumulating, it then moves up tree, |
159 |
|
* executing complete() at the root. |
160 |
– |
* |
160 |
|
*/ |
161 |
|
static final class Cumulater extends ForkJoinTask<Void> { |
162 |
|
static final short CUMULATE = (short)1; |
254 |
|
par.out = par.left.out + par.right.out; |
255 |
|
int refork = |
256 |
|
((pb & CUMULATE) == 0 && |
257 |
< |
par.lo == 0)? CUMULATE : 0; |
257 |
> |
par.lo == 0) ? CUMULATE : 0; |
258 |
|
int nextPhase = pb|cb|refork; |
259 |
|
if (pb == nextPhase || |
260 |
|
phaseUpdater.compareAndSet(par, pb, nextPhase)) { |
275 |
|
} |
276 |
|
|
277 |
|
} |
279 |
– |
|
280 |
– |
|