--- jsr166/src/test/loops/ScalarLongSort.java 2010/09/19 12:55:37 1.4 +++ jsr166/src/test/loops/ScalarLongSort.java 2011/10/10 16:59:04 1.10 @@ -1,7 +1,7 @@ /* * 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 java.util.concurrent.*; @@ -10,27 +10,30 @@ import java.util.*; class ScalarLongSort { static final long NPS = (1000L * 1000 * 1000); - static int THRESHOLD; + static int THRESHOLD = -1; static final boolean warmup = true; - public static void main (String[] args) throws Exception { + public static void main(String[] args) throws Exception { int procs = 0; int n = 1 << 22; int reps = 20; int sreps = 2; + int st = -1; try { if (args.length > 0) procs = Integer.parseInt(args[0]); if (args.length > 1) n = Integer.parseInt(args[1]); if (args.length > 2) - reps = Integer.parseInt(args[1]); + reps = Integer.parseInt(args[2]); + if (args.length > 3) + st = Integer.parseInt(args[3]); } catch (Exception e) { - System.out.println("Usage: java ScalarLongSort threads n reps"); + System.out.println("Usage: java ScalarLongSort threads n reps sequential-threshold"); return; } - ForkJoinPool pool = procs == 0? new ForkJoinPool() : + ForkJoinPool pool = (procs == 0) ? new ForkJoinPool() : new ForkJoinPool(procs); long[] a = new long[n]; @@ -46,10 +49,10 @@ class ScalarLongSort { checkSorted(a); } - // for now hardwire 8 * #CPUs leaf tasks - THRESHOLD = 1 + ((n + 7) >>> 3) / pool.getParallelism(); - // THRESHOLD = 1 + ((n + 15) >>> 4) / pool.getParallelism(); - // THRESHOLD = 1 + ((n + 31) >>> 5) / pool.getParallelism(); + if (st <= 0) // for now hardwire 8 * #CPUs leaf tasks + THRESHOLD = 1 + ((n + 7) >>> 3) / pool.getParallelism(); + else + THRESHOLD = st; System.out.printf("Sorting %d longs, %d replications\n", n, reps); for (int i = 0; i < reps; ++i) { @@ -80,15 +83,15 @@ class ScalarLongSort { } static final class Sorter extends RecursiveAction { - final long[] a; + final long[] a; final long[] w; - final int origin; + final int origin; final int n; Sorter(long[] a, long[] w, int origin, int n) { this.a = a; this.w = w; this.origin = origin; this.n = n; } - public void compute() { + public void compute() { int l = origin; if (n <= THRESHOLD) Arrays.sort(a, l, l+n); @@ -111,7 +114,7 @@ class ScalarLongSort { } } } - + static final class SubSorter extends RecursiveAction { final Sorter left; final Sorter right; @@ -145,7 +148,7 @@ class ScalarLongSort { * and finding index of right closest to split point. * Uses left-spine decomposition to generate all * merge tasks before bottomming out at base case. - * + * */ public final void compute() { Merger rights = null; @@ -169,11 +172,11 @@ class ScalarLongSort { nleft = lh; nright = rh; } - + merge(nleft, nright); - if (rights != null) + if (rights != null) collectRights(rights); - + } final void merge(int nleft, int nright) { @@ -206,11 +209,11 @@ class ScalarLongSort { } - static void checkSorted (long[] a) { + static void checkSorted(long[] a) { int n = a.length; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i+1]) { - throw new Error("Unsorted at " + i + ": " + + throw new Error("Unsorted at " + i + ": " + a[i] + " / " + a[i+1]); } }