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

Comparing jsr166/src/test/loops/FJJacobi.java (file contents):
Revision 1.1 by dl, Fri Oct 23 19:57:06 2009 UTC vs.
Revision 1.2 by jsr166, Thu Oct 29 23:09:07 2009 UTC

# Line 13 | Line 13 | public class FJJacobi {
13  
14      static final int DEFAULT_GRANULARITY = 4096; // 1024;
15  
16 <    /**
17 <     * The maximum number of matrix cells
16 >    /**
17 >     * The maximum number of matrix cells
18       * at which to stop recursing down and instead directly update.
19       **/
20  
# Line 24 | Line 24 | public class FJJacobi {
24          int n = 2048;
25          int steps = 1000;
26          int granularity = DEFAULT_GRANULARITY;
27 <      
27 >
28          try {
29              if (args.length > 0)
30                  n = Integer.parseInt(args[0]);
31              if (args.length > 1)
32                  steps = Integer.parseInt(args[1]);
33 <            if (args.length > 2)
33 >            if (args.length > 2)
34                  granularity = Integer.parseInt(args[2]);
35          }
36 <      
36 >
37          catch (Exception e) {
38              System.out.println("Usage: java FJJacobi <matrix size> <max steps> [<leafcells>]");
39              return;
# Line 47 | Line 47 | public class FJJacobi {
47          double[][] a = new double[dim][dim];
48          double[][] b = new double[dim][dim];
49          // Initialize interiors to small value
50 <        double smallVal = 1.0/dim;
50 >        double smallVal = 1.0/dim;
51          for (int i = 1; i < dim-1; ++i) {
52              for (int j = 1; j < dim-1; ++j)
53                  a[i][j] = smallVal;
54          }
55 <        
55 >
56          int nreps = 3;
57          for (int rep = 0; rep < nreps; ++rep) {
58              // Fill all edges with 1's.
# Line 63 | Line 63 | public class FJJacobi {
63                  a[n+1][k] += 1.0;
64              }
65              Driver driver = new Driver(a, b, 1, n, 1, n, steps, granularity);
66 <      
66 >
67              long startTime = System.currentTimeMillis();
68              fjp.invoke(driver);
69 <            
69 >
70              long time = System.currentTimeMillis() - startTime;
71              double secs = ((double)time) / 1000.0;
72 <            
72 >
73              System.out.println("Compute Time: " + secs);
74              System.out.println("Workers: " + fjp.getPoolSize());
75              System.out.println(fjp);
# Line 79 | Line 79 | public class FJJacobi {
79  
80      abstract static class MatrixTree extends RecursiveAction {
81          // maximum difference between old and new values
82 <        double maxDiff;
83 <        public final double directCompute() {
84 <            compute();
82 >        double maxDiff;
83 >        public final double directCompute() {
84 >            compute();
85              return maxDiff;
86          }
87          public final double joinAndReinitialize(double md) {
88              if (tryUnfork())
89 <                compute();
89 >                compute();
90              else {
91                  //                quietlyJoin();
92                  quietlyHelpJoin();
# Line 109 | Line 109 | public class FJJacobi {
109  
110          int steps = 0; // track even/odd steps
111  
112 <        LeafNode(double[][] A, double[][] B,
112 >        LeafNode(double[][] A, double[][] B,
113                   int loRow, int hiRow,
114                   int loCol, int hiCol) {
115              this.A = A;   this.B = B;
# Line 117 | Line 117 | public class FJJacobi {
117              this.loCol = loCol; this.hiCol = hiCol;
118          }
119  
120 <        public void compute() {
120 >        public void compute() {
121              boolean AtoB = (steps++ & 1) == 0;
122              double[][] a = (AtoB)? A : B;
123              double[][] b = (AtoB)? B : A;
# Line 145 | Line 145 | public class FJJacobi {
145          final MatrixTree q2;
146          final MatrixTree q3;
147          final MatrixTree q4;
148 <        FourNode(MatrixTree q1, MatrixTree q2,
148 >        FourNode(MatrixTree q1, MatrixTree q2,
149                   MatrixTree q3, MatrixTree q4) {
150              this.q1 = q1; this.q2 = q2; this.q3 = q3; this.q4 = q4;
151          }
152  
153 <        public void compute() {
153 >        public void compute() {
154              q4.fork();
155              q3.fork();
156              q2.fork();
# Line 161 | Line 161 | public class FJJacobi {
161              maxDiff = md;
162          }
163      }
164 <        
164 >
165  
166      static final class TwoNode extends MatrixTree {
167          final MatrixTree q1;
# Line 171 | Line 171 | public class FJJacobi {
171              this.q1 = q1; this.q2 = q2;
172          }
173  
174 <        public void compute() {
174 >        public void compute() {
175              q2.fork();
176              maxDiff = q2.joinAndReinitialize(q1.directCompute());
177          }
178 <      
178 >
179      }
180 <        
180 >
181  
182      static final class Driver extends RecursiveAction {
183          MatrixTree mat;
# Line 188 | Line 188 | public class FJJacobi {
188          final int leafs;
189          int nleaf;
190  
191 <        Driver(double[][] A, double[][] B,
191 >        Driver(double[][] A, double[][] B,
192                 int firstRow, int lastRow,
193                 int firstCol, int lastCol,
194                 int steps, int leafs) {
# Line 212 | Line 212 | public class FJJacobi {
212  
213              int mr = (lr + hr) >>> 1; // midpoints
214              int mc = (lc + hc) >>> 1;
215 <      
215 >
216              int hrows = (mr - lr + 1);
217              int hcols = (mc - lc + 1);
218  
# Line 233 | Line 233 | public class FJJacobi {
233              else {
234                  return new TwoNode(build(a, b, lr,   mr, lc, hc, leafs),
235                                     build(a, b, mr+1, hr, lc, hc, leafs));
236 <        
236 >
237              }
238          }
239  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines