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

Comparing jsr166/src/test/loops/MatrixMultiply.java (file contents):
Revision 1.3 by jsr166, Sat Oct 16 16:22:57 2010 UTC vs.
Revision 1.9 by dl, Sat Sep 12 19:39:26 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 jsr166y.*;
8   import java.util.concurrent.*;
9 import java.util.concurrent.TimeUnit;
10
9  
10   /**
11   * Divide and Conquer matrix multiply demo
# Line 17 | Line 15 | public class MatrixMultiply {
15      /** for time conversion */
16      static final long NPS = (1000L * 1000 * 1000);
17  
18 <    static final int DEFAULT_GRANULARITY = 32;
18 >    static final int DEFAULT_GRANULARITY = 16; // 32;
19  
20      /**
21       * The quadrant size at which to stop recursing down
# Line 32 | Line 30 | public class MatrixMultiply {
30  
31          int procs = 0;
32          int n = 2048;
33 <        int runs = 5;
33 >        int runs = 32;
34          try {
35              if (args.length > 0)
36                  procs = Integer.parseInt(args[0]);
# Line 56 | Line 54 | public class MatrixMultiply {
54              return;
55          }
56  
57 <        ForkJoinPool pool = procs == 0? new ForkJoinPool() :
57 >        ForkJoinPool pool = (procs == 0) ? ForkJoinPool.commonPool() :
58              new ForkJoinPool(procs);
59          System.out.println("procs: " + pool.getParallelism() +
60                             " n: " + n + " granularity: " + granularity +
# Line 69 | Line 67 | public class MatrixMultiply {
67          for (int i = 0; i < runs; ++i) {
68              init(a, b, n);
69              long start = System.nanoTime();
70 <            pool.invoke(new Multiplier(a, 0, 0, b, 0, 0, c, 0, 0, n));
70 >            new Multiplier(a, 0, 0, b, 0, 0, c, 0, 0, n).invoke();
71              long time = System.nanoTime() - start;
72              double secs = ((double)time) / NPS;
73              Thread.sleep(100);
74 <            System.out.printf("\tTime: %7.3f\n", secs);
74 >            System.out.printf("Time: %7.3f ", secs);
75 >            if ((i & 3) == 3) System.out.println();
76              // check(c, n);
77          }
78          System.out.println(pool.toString());
79 <        pool.shutdown();
79 >        if (pool != ForkJoinPool.commonPool())
80 >            pool.shutdown();
81 >        Thread.sleep(100);
82      }
83  
83
84      // To simplify checking, fill with all 1's. Answer should be all n's.
85      static void init(float[][] a, float[][] b, int n) {
86          for (int i = 0; i < n; ++i) {
# Line 111 | Line 111 | public class MatrixMultiply {
111       *  A21 | A22     B21 | B21     A21*B11 | A21*B21     A22*B21 | A22*B22
112       * </pre>
113       */
114
115
114      static class Multiplier extends RecursiveAction {
115          final float[][] A;   // Matrix A
116          final int aRow;      // first row    of current quadrant of A
# Line 250 | Line 248 | public class MatrixMultiply {
248              snd.invoke();
249          }
250      }
253
254
251   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines