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.6 by dl, Sun Sep 19 12:55:36 2010 UTC vs.
Revision 1.7 by jsr166, Mon Sep 20 20:42:37 2010 UTC

# Line 12 | Line 12 | public class FJJacobi {
12  
13      static final int DEFAULT_GRANULARITY = 4096; // 1024;
14  
15 <    /**
16 <     * The maximum number of matrix cells
15 >    /**
16 >     * The maximum number of matrix cells
17       * at which to stop recursing down and instead directly update.
18       **/
19  
# Line 23 | Line 23 | public class FJJacobi {
23          int n = 2048;
24          int steps = 1000;
25          int granularity = DEFAULT_GRANULARITY;
26 <      
26 >
27          try {
28              if (args.length > 0)
29                  n = Integer.parseInt(args[0]);
30              if (args.length > 1)
31                  steps = Integer.parseInt(args[1]);
32 <            if (args.length > 2)
32 >            if (args.length > 2)
33                  granularity = Integer.parseInt(args[2]);
34          }
35 <      
35 >
36          catch (Exception e) {
37              System.out.println("Usage: java FJJacobi <matrix size> <max steps> [<leafcells>]");
38              return;
# Line 46 | Line 46 | public class FJJacobi {
46          double[][] a = new double[dim][dim];
47          double[][] b = new double[dim][dim];
48          // Initialize interiors to small value
49 <        double smallVal = EPSILON; // 1.0/dim;
49 >        double smallVal = EPSILON; // 1.0/dim;
50          for (int i = 1; i < dim-1; ++i) {
51              for (int j = 1; j < dim-1; ++j)
52                  a[i][j] = smallVal;
# Line 65 | Line 65 | public class FJJacobi {
65          int nreps = 10;
66          for (int rep = 0; rep < nreps; ++rep) {
67              Driver driver = new Driver(a, b, 1, n, 1, n, steps, granularity);
68 <      
68 >
69              long startTime = System.currentTimeMillis();
70              fjp.invoke(driver);
71 <            
71 >
72              long time = System.currentTimeMillis() - startTime;
73              double secs = ((double)time) / 1000.0;
74 <            
74 >
75              System.out.println("Compute Time: " + secs);
76              System.out.println(fjp);
77          }
# Line 80 | Line 80 | public class FJJacobi {
80  
81      abstract static class MatrixTree extends RecursiveAction {
82          // maximum difference between old and new values
83 <        double maxDiff;
84 <        public final double directCompute() {
85 <            compute();
83 >        double maxDiff;
84 >        public final double directCompute() {
85 >            compute();
86              return maxDiff;
87          }
88          public final double joinAndReinitialize(double md) {
89              if (tryUnfork())
90 <                compute();
90 >                compute();
91              else {
92                  quietlyJoin();
93                  reinitialize();
# 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 129 | Line 129 | public class FJJacobi {
129                      double v = 0.25 * (a[i-1][j] + a[i][j-1] +
130                                         a[i+1][j] + a[i][j+1]);
131                      b[i][j] = v;
132 <                    
132 >
133                      double diff = v - a[i][j];
134                      if (diff < 0) diff = -diff;
135                      if (diff > md) md = diff;
# 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