ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/Fib.java
(Generate patch)

Comparing jsr166/src/test/loops/Fib.java (file contents):
Revision 1.1 by dl, Sun Sep 19 12:55:37 2010 UTC vs.
Revision 1.2 by jsr166, Mon Sep 20 20:42:37 2010 UTC

# Line 10 | Line 10 | import java.util.concurrent.*;
10   * Recursive task-based version of Fibonacci. Computes:
11   * <pre>
12   * Computes fibonacci(n) = fibonacci(n-1) + fibonacci(n-2);  for n> 1
13 < *          fibonacci(0) = 0;
14 < *          fibonacci(1) = 1.      
13 > *          fibonacci(0) = 0;
14 > *          fibonacci(1) = 1.
15   * </pre>
16   **/
17  
# Line 21 | Line 21 | public final class Fib extends Recursive
21      static int sequentialThreshold;
22  
23      static long lastStealCount;
24 <  
24 >
25      public static void main(String[] args) throws Exception {
26          int procs = 0;
27          int num = 45;
# Line 31 | Line 31 | public final class Fib extends Recursive
31                  procs = Integer.parseInt(args[0]);
32              if (args.length > 1)
33                  num = Integer.parseInt(args[1]);
34 <            if (args.length > 2)
34 >            if (args.length > 2)
35                  sequentialThreshold = Integer.parseInt(args[2]);
36          }
37          catch (Exception e) {
# Line 40 | Line 40 | public final class Fib extends Recursive
40          }
41  
42          for (int reps = 0; reps < 2; ++reps) {
43 <            ForkJoinPool g = procs == 0? new ForkJoinPool() :
43 >            ForkJoinPool g = procs == 0? new ForkJoinPool() :
44                  new ForkJoinPool(procs);
45              lastStealCount = g.getStealCount();
46              for (int i = 0; i < 20; ++i) {
# Line 72 | Line 72 | public final class Fib extends Recursive
72          long result = f.getAnswer();
73          System.out.print("Fib " + num + " = " + result);
74          System.out.printf("\tTime: %7.3f", secs);
75 <      
75 >
76          long sc = g.getStealCount();
77          long ns = sc - lastStealCount;
78          lastStealCount = sc;
# Line 99 | Line 99 | public final class Fib extends Recursive
99              else {
100                  Fib f1 = new Fib(n - 1);
101                  Fib f2 = new Fib(n - 2);
102 <                //                forkJoin(f1, f2);  
103 <                invokeAll(f1, f2);  
102 >                //                forkJoin(f1, f2);
103 >                invokeAll(f1, f2);
104                  number = f1.number + f2.number;
105              }
106          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines