--- jsr166/src/test/loops/CCJacobi.java 2012/05/05 17:09:23 1.2 +++ jsr166/src/test/loops/CCJacobi.java 2015/09/12 18:15:47 1.6 @@ -38,7 +38,7 @@ public class CCJacobi { return; } - ForkJoinPool fjp = new ForkJoinPool(); + ForkJoinPool fjp = ForkJoinPool.commonPool(); // allocate enough space for edges int dim = n+2; @@ -67,24 +67,23 @@ public class CCJacobi { Driver driver = new Driver(a, b, 1, n, 1, n, steps, granularity); long startTime = System.currentTimeMillis(); - fjp.invoke(driver); + driver.invoke(); long time = System.currentTimeMillis() - startTime; double secs = ((double)time) / 1000.0; System.out.println("Compute Time: " + secs); System.out.println(fjp); + System.gc(); } } - - abstract static class MatrixTree extends CountedCompleter { + abstract static class MatrixTree extends CountedCompleter { // maximum difference between old and new values double maxDiff; - MatrixTree(CountedCompleter p, int c) { super(p, c); } + MatrixTree(CountedCompleter p, int c) { super(p, c); } } - static final class LeafNode extends MatrixTree { final double[][] A; // matrix to get old values from final double[][] B; // matrix to put new values into @@ -95,7 +94,7 @@ public class CCJacobi { int steps = 0; // track even/odd steps - LeafNode(CountedCompleter p, + LeafNode(CountedCompleter p, double[][] A, double[][] B, int loRow, int hiRow, int loCol, int hiCol) { @@ -111,14 +110,13 @@ public class CCJacobi { double[][] b = AtoB ? B : A; double md = 0.0; // local for computing max diff - for (int i = loRow; i <= hiRow; ++i) { for (int j = loCol; j <= hiCol; ++j) { double v = 0.25 * (a[i-1][j] + a[i][j-1] + a[i+1][j] + a[i][j+1]); b[i][j] = v; - - double diff = v - a[i][j]; + double prev = a[i][j]; + double diff = v - prev; if (diff < 0) diff = -diff; if (diff > md) md = diff; } @@ -134,11 +132,11 @@ public class CCJacobi { MatrixTree q2; MatrixTree q3; MatrixTree q4; - FourNode(CountedCompleter p) { + FourNode(CountedCompleter p) { super(p, 3); } - public void onCompletion(CountedCompleter caller) { + public void onCompletion(CountedCompleter caller) { double md = q1.maxDiff, m; if ((m = q2.maxDiff) > md) md = m; @@ -158,16 +156,15 @@ public class CCJacobi { } } - static final class TwoNode extends MatrixTree { MatrixTree q1; MatrixTree q2; - TwoNode(CountedCompleter p) { + TwoNode(CountedCompleter p) { super(p, 1); } - public void onCompletion(CountedCompleter caller) { + public void onCompletion(CountedCompleter caller) { double md = q1.maxDiff, m; if ((m = q2.maxDiff) > md) md = m; @@ -179,7 +176,6 @@ public class CCJacobi { q2.fork(); q1.compute(); } - } static final class Driver extends RecursiveAction { @@ -205,7 +201,6 @@ public class CCJacobi { this.leafs = leafs; mat = build(null, A, B, firstRow, lastRow, firstCol, lastCol, leafs); System.out.println("Using " + nleaf + " segments"); - } MatrixTree build(MatrixTree p, @@ -260,6 +255,4 @@ public class CCJacobi { System.out.println("max diff after " + steps + " steps = " + md); } } - - }