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 |
5 |
+ |
*/ |
6 |
+ |
|
7 |
|
//import jsr166y.*; |
8 |
|
import java.util.*; |
9 |
|
import java.util.concurrent.*; |
12 |
|
|
13 |
|
// Performance-tuning constant: |
14 |
|
static long lastStealCount; |
15 |
< |
|
15 |
> |
|
16 |
|
public static void main(String[] args) throws Exception { |
17 |
|
int procs = 0; |
18 |
|
int num = 43; |
23 |
|
num = Integer.parseInt(args[1]); |
24 |
|
} |
25 |
|
catch (Exception e) { |
26 |
< |
System.out.println("Usage: java DynamicLeftSpineFib <threads> <number> [<sequntialThreshold>]"); |
26 |
> |
System.out.println("Usage: java DynamicLeftSpineFib <threads> <number> [<sequentialThreshold>]"); |
27 |
|
return; |
28 |
|
} |
29 |
|
|
30 |
< |
|
30 |
> |
|
31 |
|
for (int reps = 0; reps < 2; ++reps) { |
32 |
|
ForkJoinPool g = procs == 0? new ForkJoinPool() : |
33 |
|
new ForkJoinPool(procs); |
63 |
|
int number; |
64 |
|
DynamicLeftSpineFib next; |
65 |
|
|
66 |
< |
DynamicLeftSpineFib(int n, DynamicLeftSpineFib nxt) { |
67 |
< |
number = n; next = nxt; |
66 |
> |
DynamicLeftSpineFib(int n, DynamicLeftSpineFib nxt) { |
67 |
> |
number = n; next = nxt; |
68 |
|
} |
69 |
|
|
70 |
|
int getAnswer() { |
91 |
|
|
92 |
|
// Sequential version for arguments less than threshold |
93 |
|
static int seqFib(int n) { |
94 |
< |
if (n <= 1) |
94 |
> |
if (n <= 1) |
95 |
|
return n; |
96 |
< |
else |
96 |
> |
else |
97 |
|
return seqFib(n-1) + seqFib(n-2); |
98 |
|
} |
93 |
– |
|
94 |
– |
} |
99 |
|
|
100 |
+ |
} |