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

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

# Line 8 | Line 8 | public class ThreadPhaserJacobi {
8  
9      static final int nprocs = Runtime.getRuntime().availableProcessors();
10  
11 <    /**
11 >    /**
12       * The maximum submatrix length (both row-wise and column-wise)
13       * for any Segment
14       **/
# Line 26 | Line 26 | public class ThreadPhaserJacobi {
26              if (args.length > 1)
27                  steps = Integer.parseInt(args[1]);
28          }
29 <      
29 >
30          catch (Exception e) {
31              System.out.println("Usage: java ThreadPhaserJacobi <matrix size> <max steps>");
32              return;
# Line 41 | Line 41 | public class ThreadPhaserJacobi {
41          double[][] a = new double[dim][dim];
42          double[][] b = new double[dim][dim];
43          // Initialize interiors to small value
44 <        double smallVal = 1.0/dim;
44 >        double smallVal = 1.0/dim;
45          for (int i = 1; i < dim-1; ++i) {
46              for (int j = 1; j < dim-1; ++j)
47                  a[i][j] = smallVal;
48          }
49 <      
49 >
50          int nreps = 3;
51          for (int rep = 0; rep < nreps; ++rep) {
52              // Fill all edges with 1's.
# Line 59 | Line 59 | public class ThreadPhaserJacobi {
59              Driver driver = new Driver(a, b, 1, n, 1, n, steps);
60              long startTime = System.currentTimeMillis();
61              driver.compute();
62 <          
62 >
63              long time = System.currentTimeMillis() - startTime;
64              double secs = ((double)time) / 1000.0;
65 <          
65 >
66              System.out.println("Compute Time: " + secs);
67          }
68      }
# Line 73 | Line 73 | public class ThreadPhaserJacobi {
73          double[][] B; // matrix to put new values into
74  
75          // indices of current submatrix
76 <        final int loRow;  
76 >        final int loRow;
77          final int hiRow;
78          final int loCol;
79          final int hiCol;
# Line 81 | Line 81 | public class ThreadPhaserJacobi {
81          final Phaser barrier;
82          double maxDiff; // maximum difference between old and new values
83  
84 <        Segment(double[][] A, double[][] B,
84 >        Segment(double[][] A, double[][] B,
85                  int loRow, int hiRow,
86                  int loCol, int hiCol,
87                  int steps,
# Line 99 | Line 99 | public class ThreadPhaserJacobi {
99              try {
100                  double[][] a = A;
101                  double[][] b = B;
102 <        
102 >
103                  for (int i = 0; i < steps; ++i) {
104                      maxDiff = update(a, b);
105                      if (barrier.awaitAdvance(barrier.arrive()) < 0)
# Line 107 | Line 107 | public class ThreadPhaserJacobi {
107                      double[][] tmp = a; a = b; b = tmp;
108                  }
109              }
110 <            catch(Exception ex) {
110 >            catch(Exception ex) {
111                  ex.printStackTrace();
112                  return;
113              }
# Line 130 | Line 130 | public class ThreadPhaserJacobi {
130  
131              return md;
132          }
133 <        
133 >
134      }
135        
135  
136 <    static class Driver {
136 >
137 >    static class Driver {
138          double[][] A; // matrix to get old values from
139          double[][] B; // matrix to put new values into
140  
# Line 145 | Line 145 | public class ThreadPhaserJacobi {
145          final int steps;
146          Segment[] allSegments;
147  
148 <        Driver(double[][] mat1, double[][] mat2,
148 >        Driver(double[][] mat1, double[][] mat2,
149                 int firstRow, int lastRow,
150                 int firstCol, int lastCol,
151                 int steps) {
152 <      
152 >
153              this.A = mat1;   this.B = mat2;
154              this.loRow = firstRow; this.hiRow = lastRow;
155              this.loCol = firstCol; this.hiCol = lastCol;
# Line 159 | Line 159 | public class ThreadPhaserJacobi {
159              int cols = hiCol - loCol + 1;
160              int rblocks = (int)(Math.round((float)rows / dimGran));
161              int cblocks = (int)(Math.round((float)cols / dimGran));
162 <            
162 >
163              int n = rblocks * cblocks;
164 <            
164 >
165              Segment[] segs = new Segment[n];
166              Phaser barrier = new Phaser();
167              int k = 0;
# Line 169 | Line 169 | public class ThreadPhaserJacobi {
169                  int lr = loRow + i * dimGran;
170                  int hr = lr + dimGran;
171                  if (i == rblocks-1) hr = hiRow;
172 <                
172 >
173                  for (int j = 0; j < cblocks; ++j) {
174                      int lc = loCol + j * dimGran;
175                      int hc = lc + dimGran;
176                      if (j == cblocks-1) hc = hiCol;
177 <                    
177 >
178                      segs[k] = new Segment(A, B, lr, hr, lc, hc, steps, barrier);
179                      ++k;
180                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines