26 |
|
static ForkJoinPool defaultExecutor() { |
27 |
|
ForkJoinPool p = defaultExecutor; // double-check |
28 |
|
if (p == null) { |
29 |
< |
synchronized(poolLock) { |
29 |
> |
synchronized (poolLock) { |
30 |
|
p = defaultExecutor; |
31 |
|
if (p == null) { |
32 |
|
// use ceil(7/8 * ncpus) |
1491 |
|
if ((filtered && !pap.isSelected(k)) || |
1492 |
|
(x = src[k]) == null) |
1493 |
|
continue; |
1494 |
< |
int hc = byIdentity? System.identityHashCode(x): x.hashCode(); |
1494 |
> |
int hc = byIdentity ? System.identityHashCode(x) : x.hashCode(); |
1495 |
|
int hash = hash(hc); |
1496 |
|
long entry = (((long)hash) << 32) + (k + 1); |
1497 |
|
int idx = hash & mask; |
1657 |
|
this.gran = gran; |
1658 |
|
} |
1659 |
|
|
1660 |
< |
public void compute() { |
1660 |
> |
public void compute() { |
1661 |
|
int l = origin; |
1662 |
|
int g = gran; |
1663 |
|
if (n > g) { |
1693 |
|
this.a = a; this.w = w; this.origin = origin; this.n = n; |
1694 |
|
this.gran = gran; |
1695 |
|
} |
1696 |
< |
public void compute() { |
1696 |
> |
public void compute() { |
1697 |
|
int l = origin; |
1698 |
|
int g = gran; |
1699 |
|
if (n > g) { |
1730 |
|
this.a = a; this.w = w; this.origin = origin; this.n = n; |
1731 |
|
this.gran = gran; |
1732 |
|
} |
1733 |
< |
public void compute() { |
1733 |
> |
public void compute() { |
1734 |
|
int l = origin; |
1735 |
|
int g = gran; |
1736 |
|
if (n > g) { |
1754 |
|
l+h, n-h, l, g, null).compute(); |
1755 |
|
} |
1756 |
|
else |
1757 |
< |
Arrays.sort(a, l, l+n, cmp); |
1757 |
> |
dquickSort(a, cmp, l, l+n-1); |
1758 |
|
} |
1759 |
|
} |
1760 |
|
|
1766 |
|
this.a = a; this.w = w; this.origin = origin; this.n = n; |
1767 |
|
this.gran = gran; |
1768 |
|
} |
1769 |
< |
public void compute() { |
1769 |
> |
public void compute() { |
1770 |
|
int l = origin; |
1771 |
|
int g = gran; |
1772 |
|
if (n > g) { |
1804 |
|
this.gran = gran; |
1805 |
|
} |
1806 |
|
|
1807 |
< |
public void compute() { |
1807 |
> |
public void compute() { |
1808 |
|
int l = origin; |
1809 |
|
int g = gran; |
1810 |
|
if (n > g) { |
1828 |
|
l+h, n-h, l, g, null).compute(); |
1829 |
|
} |
1830 |
|
else |
1831 |
< |
Arrays.sort(a, l, l+n, cmp); |
1831 |
> |
lquickSort(a, cmp, l, l+n-1); |
1832 |
|
} |
1833 |
|
} |
1834 |
|
|
1840 |
|
this.a = a; this.w = w; this.origin = origin; this.n = n; |
1841 |
|
this.gran = gran; |
1842 |
|
} |
1843 |
< |
public void compute() { |
1843 |
> |
public void compute() { |
1844 |
|
int l = origin; |
1845 |
|
int g = gran; |
1846 |
|
if (n > g) { |
2302 |
|
} |
2303 |
|
} |
2304 |
|
|
2305 |
+ |
/** Cutoff for when to use insertion-sort instead of quicksort */ |
2306 |
+ |
static final int INSERTION_SORT_THRESHOLD = 8; |
2307 |
+ |
|
2308 |
+ |
// versions of quicksort with comparators |
2309 |
+ |
|
2310 |
+ |
|
2311 |
+ |
static void dquickSort(double[] a, DoubleComparator cmp, int lo, int hi) { |
2312 |
+ |
for (;;) { |
2313 |
+ |
if (hi - lo <= INSERTION_SORT_THRESHOLD) { |
2314 |
+ |
for (int i = lo + 1; i <= hi; i++) { |
2315 |
+ |
double t = a[i]; |
2316 |
+ |
int j = i - 1; |
2317 |
+ |
while (j >= lo && cmp.compare(t, a[j]) < 0) { |
2318 |
+ |
a[j+1] = a[j]; |
2319 |
+ |
--j; |
2320 |
+ |
} |
2321 |
+ |
a[j+1] = t; |
2322 |
+ |
} |
2323 |
+ |
return; |
2324 |
+ |
} |
2325 |
+ |
|
2326 |
+ |
int mid = (lo + hi) >>> 1; |
2327 |
+ |
if (cmp.compare(a[lo], a[mid]) > 0) { |
2328 |
+ |
double t = a[lo]; a[lo] = a[mid]; a[mid] = t; |
2329 |
+ |
} |
2330 |
+ |
if (cmp.compare(a[mid], a[hi]) > 0) { |
2331 |
+ |
double t = a[mid]; a[mid] = a[hi]; a[hi] = t; |
2332 |
+ |
if (cmp.compare(a[lo], a[mid]) > 0) { |
2333 |
+ |
double u = a[lo]; a[lo] = a[mid]; a[mid] = u; |
2334 |
+ |
} |
2335 |
+ |
} |
2336 |
+ |
|
2337 |
+ |
double pivot = a[mid]; |
2338 |
+ |
int left = lo+1; |
2339 |
+ |
int right = hi-1; |
2340 |
+ |
boolean sameLefts = true; |
2341 |
+ |
for (;;) { |
2342 |
+ |
while (cmp.compare(pivot, a[right]) < 0) |
2343 |
+ |
--right; |
2344 |
+ |
int c; |
2345 |
+ |
while (left < right && |
2346 |
+ |
(c = cmp.compare(pivot, a[left])) >= 0) { |
2347 |
+ |
if (c != 0) |
2348 |
+ |
sameLefts = false; |
2349 |
+ |
++left; |
2350 |
+ |
} |
2351 |
+ |
if (left < right) { |
2352 |
+ |
double t = a[left]; a[left] = a[right]; a[right] = t; |
2353 |
+ |
--right; |
2354 |
+ |
} |
2355 |
+ |
else break; |
2356 |
+ |
} |
2357 |
+ |
|
2358 |
+ |
if (sameLefts && right == hi - 1) |
2359 |
+ |
return; |
2360 |
+ |
if (left - lo <= hi - right) { |
2361 |
+ |
dquickSort(a, cmp, lo, left); |
2362 |
+ |
lo = left + 1; |
2363 |
+ |
} |
2364 |
+ |
else { |
2365 |
+ |
dquickSort(a, cmp, right, hi); |
2366 |
+ |
hi = left; |
2367 |
+ |
} |
2368 |
+ |
} |
2369 |
+ |
} |
2370 |
+ |
|
2371 |
+ |
static void lquickSort(long[] a, LongComparator cmp, int lo, int hi) { |
2372 |
+ |
for (;;) { |
2373 |
+ |
if (hi - lo <= INSERTION_SORT_THRESHOLD) { |
2374 |
+ |
for (int i = lo + 1; i <= hi; i++) { |
2375 |
+ |
long t = a[i]; |
2376 |
+ |
int j = i - 1; |
2377 |
+ |
while (j >= lo && cmp.compare(t, a[j]) < 0) { |
2378 |
+ |
a[j+1] = a[j]; |
2379 |
+ |
--j; |
2380 |
+ |
} |
2381 |
+ |
a[j+1] = t; |
2382 |
+ |
} |
2383 |
+ |
return; |
2384 |
+ |
} |
2385 |
+ |
|
2386 |
+ |
int mid = (lo + hi) >>> 1; |
2387 |
+ |
if (cmp.compare(a[lo], a[mid]) > 0) { |
2388 |
+ |
long t = a[lo]; a[lo] = a[mid]; a[mid] = t; |
2389 |
+ |
} |
2390 |
+ |
if (cmp.compare(a[mid], a[hi]) > 0) { |
2391 |
+ |
long t = a[mid]; a[mid] = a[hi]; a[hi] = t; |
2392 |
+ |
if (cmp.compare(a[lo], a[mid]) > 0) { |
2393 |
+ |
long u = a[lo]; a[lo] = a[mid]; a[mid] = u; |
2394 |
+ |
} |
2395 |
+ |
} |
2396 |
+ |
|
2397 |
+ |
long pivot = a[mid]; |
2398 |
+ |
int left = lo+1; |
2399 |
+ |
int right = hi-1; |
2400 |
+ |
boolean sameLefts = true; |
2401 |
+ |
for (;;) { |
2402 |
+ |
while (cmp.compare(pivot, a[right]) < 0) |
2403 |
+ |
--right; |
2404 |
+ |
int c; |
2405 |
+ |
while (left < right && |
2406 |
+ |
(c = cmp.compare(pivot, a[left])) >= 0) { |
2407 |
+ |
if (c != 0) |
2408 |
+ |
sameLefts = false; |
2409 |
+ |
++left; |
2410 |
+ |
} |
2411 |
+ |
if (left < right) { |
2412 |
+ |
long t = a[left]; a[left] = a[right]; a[right] = t; |
2413 |
+ |
--right; |
2414 |
+ |
} |
2415 |
+ |
else break; |
2416 |
+ |
} |
2417 |
+ |
|
2418 |
+ |
if (sameLefts && right == hi - 1) |
2419 |
+ |
return; |
2420 |
+ |
if (left - lo <= hi - right) { |
2421 |
+ |
lquickSort(a, cmp, lo, left); |
2422 |
+ |
lo = left + 1; |
2423 |
+ |
} |
2424 |
+ |
else { |
2425 |
+ |
lquickSort(a, cmp, right, hi); |
2426 |
+ |
hi = left; |
2427 |
+ |
} |
2428 |
+ |
} |
2429 |
+ |
} |
2430 |
+ |
|
2431 |
|
/** |
2432 |
|
* Cumulative scan |
2433 |
|
* |
2555 |
|
op.pushUp(par, par.left, par.right); |
2556 |
|
int refork = |
2557 |
|
((pb & CUMULATE) == 0 && |
2558 |
< |
par.lo == op.origin)? CUMULATE : 0; |
2558 |
> |
par.lo == op.origin) ? CUMULATE : 0; |
2559 |
|
int nextPhase = pb|cb|refork; |
2560 |
|
if (pb == nextPhase || |
2561 |
|
phaseUpdater.compareAndSet(par, pb, nextPhase)) { |