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/publicdomain/zero/1.0/ |
5 |
+ |
*/ |
6 |
+ |
|
7 |
|
import java.util.concurrent.*; |
8 |
|
import java.util.*; |
9 |
|
import java.util.concurrent.TimeUnit; |
12 |
|
public final class DynamicLeftSpineFib extends RecursiveAction { |
13 |
|
|
14 |
|
static long lastStealCount; |
15 |
< |
|
15 |
> |
|
16 |
|
public static void main(String[] args) throws Exception { |
17 |
|
int procs = 0; |
18 |
|
int num = 45; |
27 |
|
return; |
28 |
|
} |
29 |
|
|
30 |
< |
|
30 |
> |
|
31 |
|
for (int reps = 0; reps < 2; ++reps) { |
32 |
< |
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
32 |
> |
ForkJoinPool g = (procs == 0) ? new ForkJoinPool() : |
33 |
|
new ForkJoinPool(procs); |
34 |
|
lastStealCount = g.getStealCount(); |
35 |
|
for (int i = 0; i < 20; ++i) { |
66 |
|
int number; |
67 |
|
DynamicLeftSpineFib next; |
68 |
|
|
69 |
< |
DynamicLeftSpineFib(int n, DynamicLeftSpineFib nxt) { |
70 |
< |
number = n; next = nxt; |
69 |
> |
DynamicLeftSpineFib(int n, DynamicLeftSpineFib nxt) { |
70 |
> |
number = n; next = nxt; |
71 |
|
} |
72 |
|
|
73 |
|
int getAnswer() { |
74 |
|
return number; |
75 |
|
} |
76 |
< |
public void compute() { |
77 |
< |
number = fib(number); |
76 |
> |
public void compute() { |
77 |
> |
number = fib(number); |
78 |
|
} |
79 |
|
|
80 |
|
static final int fib(int n) { |
103 |
|
r += collectRights(rt); |
104 |
|
return r; |
105 |
|
} |
106 |
< |
|
106 |
> |
|
107 |
|
static final int collectRights(DynamicLeftSpineFib rt) { |
108 |
|
int r = 0; |
109 |
|
while (rt != null) { |
131 |
|
} |
132 |
|
|
133 |
|
} |
128 |
– |
|