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

Comparing jsr166/src/test/loops/ScalarLongSort.java (file contents):
Revision 1.4 by dl, Sun Sep 19 12:55:37 2010 UTC vs.
Revision 1.13 by jsr166, Thu Jan 15 18:34:19 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 import java.util.concurrent.*;
7   import java.util.*;
8 + import java.util.concurrent.*;
9  
10   class ScalarLongSort {
11      static final long NPS = (1000L * 1000 * 1000);
12  
13 <    static int THRESHOLD;
13 >    static int THRESHOLD = -1;
14      static final boolean warmup = true;
15  
16 <    public static void main (String[] args) throws Exception {
16 >    public static void main(String[] args) throws Exception {
17          int procs = 0;
18          int n = 1 << 22;
19          int reps = 20;
20          int sreps = 2;
21 +        int st = -1;
22          try {
23              if (args.length > 0)
24                  procs = Integer.parseInt(args[0]);
25              if (args.length > 1)
26                  n = Integer.parseInt(args[1]);
27              if (args.length > 2)
28 <                reps = Integer.parseInt(args[1]);
28 >                reps = Integer.parseInt(args[2]);
29 >            if (args.length > 3)
30 >                st = Integer.parseInt(args[3]);
31          }
32          catch (Exception e) {
33 <            System.out.println("Usage: java ScalarLongSort threads n reps");
33 >            System.out.println("Usage: java ScalarLongSort threads n reps sequential-threshold");
34              return;
35          }
36 <        ForkJoinPool pool = procs == 0? new ForkJoinPool() :
36 >        ForkJoinPool pool = (procs == 0) ? new ForkJoinPool() :
37              new ForkJoinPool(procs);
38  
39          long[] a = new long[n];
# Line 46 | Line 49 | class ScalarLongSort {
49              checkSorted(a);
50          }
51  
52 <        // for now hardwire 8 * #CPUs leaf tasks
53 <        THRESHOLD = 1 + ((n + 7) >>> 3) / pool.getParallelism();
54 <        //        THRESHOLD = 1 + ((n + 15) >>> 4) / pool.getParallelism();
55 <        //        THRESHOLD = 1 + ((n + 31) >>> 5) / pool.getParallelism();
52 >        if (st <= 0) // for now hardwire 8 * #CPUs leaf tasks
53 >            THRESHOLD = 1 + ((n + 7) >>> 3) / pool.getParallelism();
54 >        else
55 >            THRESHOLD = st;
56  
57          System.out.printf("Sorting %d longs, %d replications\n", n, reps);
58          for (int i = 0; i < reps; ++i) {
# Line 75 | Line 78 | class ScalarLongSort {
78          }
79          System.out.println(pool);
80  
78
81          pool.shutdown();
82      }
83  
84      static final class Sorter extends RecursiveAction {
85 <        final long[] a;
85 >        final long[] a;
86          final long[] w;
87 <        final int origin;
87 >        final int origin;
88          final int n;
89          Sorter(long[] a, long[] w, int origin, int n) {
90              this.a = a; this.w = w; this.origin = origin; this.n = n;
91          }
92  
93 <        public void compute()  {
93 >        public void compute() {
94              int l = origin;
95              if (n <= THRESHOLD)
96                  Arrays.sort(a, l, l+n);
# Line 111 | Line 113 | class ScalarLongSort {
113              }
114          }
115      }
116 <    
116 >
117      static final class SubSorter extends RecursiveAction {
118          final Sorter left;
119          final Sorter right;
# Line 145 | Line 147 | class ScalarLongSort {
147           * and finding index of right closest to split point.
148           * Uses left-spine decomposition to generate all
149           * merge tasks before bottomming out at base case.
148         *
150           */
151          public final void compute() {
152              Merger rights = null;
# Line 169 | Line 170 | class ScalarLongSort {
170                  nleft = lh;
171                  nright = rh;
172              }
173 <            
173 >
174              merge(nleft, nright);
175 <            if (rights != null)
175 >            if (rights != null)
176                  collectRights(rights);
177 <            
177 >
178          }
179  
180          final void merge(int nleft, int nright) {
# Line 206 | Line 207 | class ScalarLongSort {
207  
208      }
209  
210 <    static void checkSorted (long[] a)  {
210 >    static void checkSorted(long[] a) {
211          int n = a.length;
212          for (int i = 0; i < n - 1; i++) {
213              if (a[i] > a[i+1]) {
214 <                throw new Error("Unsorted at " + i + ": " +
214 >                throw new Error("Unsorted at " + i + ": " +
215                                  a[i] + " / " + a[i+1]);
216              }
217          }
# Line 244 | Line 245 | class ScalarLongSort {
245              }
246          }
247      }
247
248
248   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines