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.2 by jsr166, Mon Sep 20 20:42:37 2010 UTC vs.
Revision 1.8 by jsr166, Thu Jan 15 18:34:19 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
12 < **/
15 <
12 > */
13   public class MatrixMultiply {
14  
15      /** for time conversion */
# Line 20 | Line 17 | public class MatrixMultiply {
17  
18      static final int DEFAULT_GRANULARITY = 32;
19  
20 <    /** The quadrant size at which to stop recursing down
20 >    /**
21 >     * The quadrant size at which to stop recursing down
22       * and instead directly multiply the matrices.
23       * Must be a power of two. Minimum value is 2.
24 <     **/
24 >     */
25      static int granularity = DEFAULT_GRANULARITY;
26  
27      public static void main(String[] args) throws Exception {
# Line 56 | Line 54 | public class MatrixMultiply {
54              return;
55          }
56  
57 <        ForkJoinPool pool = procs == 0? new ForkJoinPool() :
57 >        ForkJoinPool pool = (procs == 0) ? new ForkJoinPool() :
58              new ForkJoinPool(procs);
59          System.out.println("procs: " + pool.getParallelism() +
60                             " n: " + n + " granularity: " + granularity +
# Line 80 | Line 78 | public class MatrixMultiply {
78          pool.shutdown();
79      }
80  
83
81      // To simplify checking, fill with all 1's. Answer should be all n's.
82      static void init(float[][] a, float[][] b, int n) {
83          for (int i = 0; i < n; ++i) {
# Line 111 | Line 108 | public class MatrixMultiply {
108       *  A21 | A22     B21 | B21     A21*B11 | A21*B21     A22*B21 | A22*B22
109       * </pre>
110       */
114
115
111      static class Multiplier extends RecursiveAction {
112          final float[][] A;   // Matrix A
113          final int aRow;      // first row    of current quadrant of A
# Line 193 | Line 188 | public class MatrixMultiply {
188           * Note that the results are added into C, not just set into C.
189           * This works well here because Java array elements
190           * are created with all zero values.
191 <         **/
197 <
191 >         */
192          void multiplyStride2() {
193              for (int j = 0; j < size; j+=2) {
194                  for (int i = 0; i < size; i +=2) {
# Line 251 | Line 245 | public class MatrixMultiply {
245              snd.invoke();
246          }
247      }
254
255
248   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines