--- jsr166/src/test/loops/LU.java 2010/09/19 12:55:37 1.1 +++ jsr166/src/test/loops/LU.java 2015/09/12 18:59:08 1.9 @@ -1,26 +1,23 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ //import jsr166y.*; import java.util.concurrent.*; -import java.util.concurrent.TimeUnit; - /** * LU matrix decomposition demo * Based on those in Cilk and Hood - **/ - + */ public final class LU { /** for time conversion */ static final long NPS = (1000L * 1000 * 1000); // granularity is hard-wired as compile-time constant here - static final int BLOCK_SIZE = 16; + static final int BLOCK_SIZE = 16; static final boolean CHECK = false; // set true to check answer public static void main(String[] args) throws Exception { @@ -29,13 +26,13 @@ public final class LU { int procs = 0; int n = 2048; - int runs = 5; + int runs = 32; try { if (args.length > 0) procs = Integer.parseInt(args[0]); if (args.length > 1) n = Integer.parseInt(args[1]); - if (args.length > 2) + if (args.length > 2) runs = Integer.parseInt(args[2]); } catch (Exception e) { System.out.println(usage); @@ -46,9 +43,9 @@ public final class LU { System.out.println(usage); return; } - ForkJoinPool pool = procs == 0? new ForkJoinPool() : + ForkJoinPool pool = (procs == 0) ? ForkJoinPool.commonPool() : new ForkJoinPool(procs); - System.out.println("procs: " + pool.getParallelism() + + System.out.println("procs: " + pool.getParallelism() + " n: " + n + " runs: " + runs); for (int run = 0; run < runs; ++run) { double[][] m = new double[n][n]; @@ -67,7 +64,8 @@ public final class LU { pool.invoke(new LowerUpper(n, M)); long time = System.nanoTime() - start; double secs = ((double)time) / NPS; - System.out.printf("\tTime: %7.3f\n", secs); + System.out.printf("Time: %7.3f ", secs); + if ((run & 3) == 3) System.out.println(); if (CHECK) check(m, copy, n); } @@ -75,7 +73,6 @@ public final class LU { pool.shutdown(); } - static void randomInit(double[][] M, int n) { java.util.Random rng = new java.util.Random(); for (int i = 0; i < n; ++i) @@ -106,7 +103,6 @@ public final class LU { System.out.println("Max difference = " + maxDiff); } - // Blocks record underlying matrix, and offsets into current block static final class Block { final double[][] m; @@ -161,7 +157,7 @@ public final class LU { Block W01 = new Block(W.m, W.loRow, W.loCol+h); Block W10 = new Block(W.m, W.loRow+h, W.loCol); Block W11 = new Block(W.m, W.loRow+h, W.loCol+h); - + Seq2 s3 = seq(new Schur(h, V10, W01, M11), new Schur(h, V11, W11, M11)); s3.fork(); @@ -219,12 +215,11 @@ public final class LU { Block L10 = new Block(L.m, L.loRow+h, L.loCol); Block L11 = new Block(L.m, L.loRow+h, L.loCol+h); - - Seq3 s1 = + Seq3 s1 = seq(new Lower(h, L00, M00), new Schur(h, L10, M00, M10), new Lower(h, L11, M10)); - Seq3 s2 = + Seq3 s2 = seq(new Lower(h, L00, M01), new Schur(h, L10, M01, M11), new Lower(h, L11, M11)); @@ -235,7 +230,6 @@ public final class LU { } } - static final class Upper extends RecursiveAction { final int size; final Block U; @@ -259,7 +253,6 @@ public final class LU { } } - public void compute() { if (size == BLOCK_SIZE) { upper(); @@ -277,11 +270,11 @@ public final class LU { Block U10 = new Block(U.m, U.loRow+h, U.loCol); Block U11 = new Block(U.m, U.loRow+h, U.loCol+h); - Seq3 s1 = + Seq3 s1 = seq(new Upper(h, U00, M00), new Schur(h, M00, U01, M01), new Upper(h, U11, M01)); - Seq3 s2 = + Seq3 s2 = seq(new Upper(h, U00, M10), new Schur(h, M10, U01, M11), new Upper(h, U11, M11)); @@ -291,7 +284,6 @@ public final class LU { } } } - static final class LowerUpper extends RecursiveAction { final int size; @@ -339,9 +331,9 @@ public final class LU { } } - static Seq2 seq(RecursiveAction task1, - RecursiveAction task2) { - return new Seq2(task1, task2); + static Seq2 seq(RecursiveAction task1, + RecursiveAction task2) { + return new Seq2(task1, task2); } static final class Seq2 extends RecursiveAction { @@ -357,17 +349,17 @@ public final class LU { } } - static Seq3 seq(RecursiveAction task1, + static Seq3 seq(RecursiveAction task1, RecursiveAction task2, - RecursiveAction task3) { - return new Seq3(task1, task2, task3); + RecursiveAction task3) { + return new Seq3(task1, task2, task3); } static final class Seq3 extends RecursiveAction { final RecursiveAction fst; final RecursiveAction snd; final RecursiveAction thr; - public Seq3(RecursiveAction task1, + public Seq3(RecursiveAction task1, RecursiveAction task2, RecursiveAction task3) { fst = task1; @@ -380,8 +372,4 @@ public final class LU { thr.invoke(); } } - - - } -