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

Comparing jsr166/src/test/loops/Heat.java (file contents):
Revision 1.1 by dl, Sun Sep 19 13:38:47 2010 UTC vs.
Revision 1.9 by jsr166, Sat Sep 12 19:09:00 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   // Adapted from a cilk benchmark
# Line 47 | Line 47 | public class Heat {
47              return;
48          }
49  
50 <        ForkJoinPool g = procs == 0? new ForkJoinPool() :
50 >        ForkJoinPool g = (procs == 0) ? new ForkJoinPool() :
51              new ForkJoinPool(procs);
52 <        
52 >
53          System.out.print("parallelism = " + g.getParallelism());
54          System.out.print(" granularity = " + leafmaxcol);
55          System.out.print(" rows = " + nx);
56          System.out.print(" columns = " + ny);
57          System.out.println(" steps = " + nt);
58 <    
58 >
59          oldm = new double[nx][ny];
60          newm = new double[nx][ny];
61  
# Line 91 | Line 91 | public class Heat {
91  
92      static final double dx = (xo - xu) / (nx - 1);
93      static final double dy = (yo - yu) / (ny - 1);
94 <    static final double dt = (to - tu) / nt;    
94 >    static final double dt = (to - tu) / nt;
95      static final double dtdxsq = dt / (dx * dx);
96      static final double dtdysq = dt / (dy * dy);
97  
98 <
99 <    // the function being applied across the cells
100 <    static final double f(double x, double y) {
101 <        return Math.sin(x) * Math.sin(y);
98 >    /** the function being applied across the cells */
99 >    static final double f(double x, double y) {
100 >        return Math.sin(x) * Math.sin(y);
101      }
102  
103      // random starting values
104  
105 <    static final double randa(double x, double t) {
106 <        return 0.0;
105 >    static final double randa(double x, double t) {
106 >        return 0.0;
107      }
108 <    static final double randb(double x, double t) {
109 <        return Math.exp(-2*t) * Math.sin(x);
108 >    static final double randb(double x, double t) {
109 >        return Math.exp(-2*t) * Math.sin(x);
110      }
111 <    static final double randc(double y, double t) {
112 <        return 0.0;
111 >    static final double randc(double y, double t) {
112 >        return 0.0;
113      }
114 <    static final double randd(double y, double t) {
115 <        return Math.exp(-2*t) * Math.sin(y);
114 >    static final double randd(double y, double t) {
115 >        return Math.exp(-2*t) * Math.sin(y);
116      }
117 <    static final double solu(double x, double y, double t) {
118 <        return Math.exp(-2*t) * Math.sin(x) * Math.sin(y);
117 >    static final double solu(double x, double y, double t) {
118 >        return Math.exp(-2*t) * Math.sin(x) * Math.sin(y);
119      }
120  
122
123
124
121      static final class Compute extends RecursiveAction {
122          final int lb;
123          final int ub;
# Line 132 | Line 128 | public class Heat {
128              ub = upperBound;
129              time = timestep;
130          }
131 <    
131 >
132          public void compute() {
133              if (ub - lb > leafmaxcol) {
134                  int mid = (lb + ub) >>> 1;
# Line 149 | Line 145 | public class Heat {
145                  compstripe(oldm, newm);
146          }
147  
148 <
153 <        /** Update all cells **/
148 >        /** Updates all cells. */
149          final void compstripe(double[][] newMat, double[][] oldMat) {
150  
151              // manually mangled to reduce array indexing
# Line 184 | Line 179 | public class Heat {
179                      nv[b] = cell
180                          + dtdysq * (prev    - twoc + next)
181                          + dtdxsq * (east[b] - twoc + west[b]);
187
182                  }
183              }
184  
185 <            edges(newMat, llb, lub,  tu + time * dt);
185 >            edges(newMat, llb, lub, tu + time * dt);
186          }
187  
188 <
195 <        // the original version from cilk
188 >        /** the original version from cilk */
189          final void origcompstripe(double[][] newMat, double[][] oldMat) {
190 <      
190 >
191              final int llb = (lb == 0)  ? 1 : lb;
192              final int lub = (ub == nx) ? nx - 1 : ub;
193  
# Line 205 | Line 198 | public class Heat {
198                      newMat[a][b] = cell
199                          + dtdxsq * (oldMat[a+1][b] - twoc + oldMat[a-1][b])
200                          + dtdysq * (oldMat[a][b+1] - twoc + oldMat[a][b-1]);
208
201                  }
202              }
203  
204              edges(newMat, llb, lub,  tu + time * dt);
205          }
206  
207 <
216 <        /** Initialize all cells **/
207 >        /** Initializes all cells. */
208          final void init() {
209              final int llb = (lb == 0) ? 1 : lb;
210              final int lub = (ub == nx) ? nx - 1 : ub;
211  
212 <            for (int a = llb; a < lub; a++) {   /* inner nodes */
212 >            for (int a = llb; a < lub; a++) {   /* inner nodes */
213                  double[] ov = oldm[a];
214                  double x = xu + a * dx;
215                  double y = yu;
# Line 229 | Line 220 | public class Heat {
220              }
221  
222              edges(oldm, llb, lub, 0);
232
223          }
224  
225 <        /** Fill in edges with boundary values **/
225 >        /** Fills in edges with boundary values. */
226          final void edges(double [][] m, int llb, int lub, double t) {
227  
228              for (int a = llb; a < lub; a++) {
# Line 252 | Line 242 | public class Heat {
242              }
243  
244              if (ub == nx) {
245 <                double[] v = m[nx - 1];
245 >                double[] v = m[nx - 1];
246                  double y = yu;
247                  for (int b = 0; b < ny; b++) {
248                      y += dy;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines