16 |
|
public static void main(String[] args) throws Exception { |
17 |
|
int procs = 0; |
18 |
|
int n = 1 << 22; |
19 |
< |
int reps = 20; |
19 |
> |
int reps = 30; |
20 |
|
int sreps = 2; |
21 |
|
try { |
22 |
|
if (args.length > 0) |
45 |
|
for (int i = 0; i < n; ++i) |
46 |
|
numbers[i] = Long.valueOf(i); |
47 |
|
Long[] a = new Long[n]; |
48 |
< |
ForkJoinPool pool = new ForkJoinPool(procs); |
48 |
> |
// ForkJoinPool pool = new ForkJoinPool(procs); |
49 |
> |
ForkJoinPool pool = ForkJoinPool.commonPool(); |
50 |
|
seqTest(a, numbers, pool, 1); |
51 |
|
System.out.println(pool); |
52 |
|
parTest(a, numbers, pool, reps); |
61 |
|
System.out.printf("Sorting %d longs, %d replications\n", n, reps); |
62 |
|
long start = System.nanoTime(); |
63 |
|
for (int i = 0; i < reps; ++i) { |
64 |
< |
pool.invoke(new RandomRepacker(numbers, a, 0, n, n)); |
64 |
> |
new RandomRepacker(numbers, a, 0, n, n).invoke(); |
65 |
|
// pool.invoke(new TaskChecker()); |
66 |
|
long last = System.nanoTime(); |
67 |
|
// quickSort(a, 0, n-1); |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
< |
static void parTest(Long[] a, Long[] numbers, ForkJoinPool pool, int reps) { |
79 |
> |
static void parTest(Long[] a, Long[] numbers, ForkJoinPool pool, int reps) throws Exception { |
80 |
|
int n = numbers.length; |
81 |
|
Long[] w = new Long[n]; |
82 |
|
System.out.printf("Sorting %d longs, %d replications\n", n, reps); |
83 |
|
long start = System.nanoTime(); |
84 |
|
for (int i = 0; i < reps; ++i) { |
85 |
|
// Arrays.fill(w, 0, n, null); |
86 |
< |
pool.invoke(new RandomRepacker(numbers, a, 0, n, n)); |
86 |
> |
new RandomRepacker(numbers, a, 0, n, n).invoke(); |
87 |
> |
// Thread.sleep(500); |
88 |
|
// pool.invoke(new TaskChecker()); |
89 |
|
long last = System.nanoTime(); |
90 |
< |
pool.invoke(new Sorter(a, w, 0, n)); |
90 |
> |
new Sorter(a, w, 0, n).invoke(); |
91 |
|
long now = System.nanoTime(); |
92 |
|
// pool.invoke(new TaskChecker()); |
93 |
|
double total = (double)(now - start) / NPS; |