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.2 by jsr166, Mon Sep 20 20:42:37 2010 UTC vs.
Revision 1.9 by jsr166, Sat Sep 12 18:59:49 2015 UTC

# Line 1 | Line 1
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.concurrent.*;
# Line 13 | Line 13 | import java.util.concurrent.*;
13   *          fibonacci(0) = 0;
14   *          fibonacci(1) = 1.
15   * </pre>
16 < **/
17 <
16 > */
17   public final class Fib extends RecursiveAction {
18  
19      // Performance-tuning constant:
# Line 40 | Line 39 | public final class Fib extends Recursive
39          }
40  
41          for (int reps = 0; reps < 2; ++reps) {
42 <            ForkJoinPool g = procs == 0? new ForkJoinPool() :
42 >            ForkJoinPool g = (procs == 0) ? ForkJoinPool.commonPool() :
43                  new ForkJoinPool(procs);
44              lastStealCount = g.getStealCount();
45              for (int i = 0; i < 20; ++i) {
# Line 49 | Line 48 | public final class Fib extends Recursive
48                  //                    Thread.sleep(100);
49              }
50              System.out.println(g);
51 <            g.shutdown();
52 <            if (!g.awaitTermination(10, TimeUnit.SECONDS))
54 <                throw new Error();
55 <            g = null;
51 >            if (g != ForkJoinPool.commonPool())
52 >                g.shutdown();
53              Thread.sleep(500);
54          }
55      }
56  
60
57      /** for time conversion */
58      static final long NPS = (1000L * 1000 * 1000);
59  
60      static void test(ForkJoinPool g, int num) throws Exception {
61          int ps = g.getParallelism();
66        //        g.setParallelism(ps);
62          long start = System.nanoTime();
63          Fib f = new Fib(num);
64          g.invoke(f);
# Line 81 | Line 76 | public final class Fib extends Recursive
76          System.out.println();
77      }
78  
84
79      // Initialized with argument; replaced with result
80      int number;
81  
# Line 99 | Line 93 | public final class Fib extends Recursive
93              else {
94                  Fib f1 = new Fib(n - 1);
95                  Fib f2 = new Fib(n - 2);
102                //                forkJoin(f1, f2);
96                  invokeAll(f1, f2);
97                  number = f1.number + f2.number;
98              }
# Line 117 | Line 110 | public final class Fib extends Recursive
110      }
111  
112   }
120

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines