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

Comparing jsr166/src/test/loops/FibTask.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 4 | Line 4 | import java.util.concurrent.*;
4   * Recursive task-based version of Fibonacci. Computes:
5   * <pre>
6   * Computes fibonacci(n) = fibonacci(n-1) + fibonacci(n-2);  for n> 1
7 < *          fibonacci(0) = 0;
8 < *          fibonacci(1) = 1.      
7 > *          fibonacci(0) = 0;
8 > *          fibonacci(1) = 1.
9   * </pre>
10   **/
11  
# Line 15 | Line 15 | public final class FibTask extends Recur
15      static int sequentialThreshold;
16  
17      static long lastStealCount;
18 <  
18 >
19      public static void main(String[] args) throws Exception {
20          int procs = 0;
21          int num = 45;
# Line 25 | Line 25 | public final class FibTask extends Recur
25                  procs = Integer.parseInt(args[0]);
26              if (args.length > 1)
27                  num = Integer.parseInt(args[1]);
28 <            if (args.length > 2)
28 >            if (args.length > 2)
29                  sequentialThreshold = Integer.parseInt(args[2]);
30          }
31          catch (Exception e) {
# Line 34 | Line 34 | public final class FibTask extends Recur
34          }
35  
36          for (int reps = 0; reps < 2; ++reps) {
37 <            ForkJoinPool g = procs == 0? new ForkJoinPool() :
37 >            ForkJoinPool g = procs == 0? new ForkJoinPool() :
38                  new ForkJoinPool(procs);
39              lastStealCount = g.getStealCount();
40              for (int i = 0; i < 20; ++i) {
# Line 58 | Line 58 | public final class FibTask extends Recur
58          double secs = ((double)time) / NPS;
59          System.out.print("FibTask " + num + " = " + result);
60          System.out.printf("\tTime: %7.3f", secs);
61 <      
61 >
62          long sc = g.getStealCount();
63          long ns = sc - lastStealCount;
64          lastStealCount = sc;
# Line 89 | Line 89 | public final class FibTask extends Recur
89              FibTask f1 = new FibTask(n - 1);
90              f1.fork();
91              FibTask f2 = new FibTask(n - 2);
92 <            return f2.compute() + f1.join();
92 >            return f2.compute() + f1.join();
93          }
94      }
95  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines