7 |
|
package java.util; |
8 |
|
|
9 |
|
import java.util.concurrent.CountedCompleter; |
10 |
+ |
import java.util.concurrent.ForkJoinPool; |
11 |
|
import java.util.function.BinaryOperator; |
12 |
|
import java.util.function.DoubleBinaryOperator; |
13 |
|
import java.util.function.IntBinaryOperator; |
74 |
|
static final int MIN_PARTITION = 16; |
75 |
|
|
76 |
|
static final class CumulateTask<T> extends CountedCompleter<Void> { |
77 |
+ |
@SuppressWarnings("serial") // Not statically typed as Serializable |
78 |
|
final T[] array; |
79 |
|
final BinaryOperator<T> function; |
80 |
|
CumulateTask<T> left, right; |
81 |
< |
T in, out; |
81 |
> |
@SuppressWarnings("serial") // Not statically typed as Serializable |
82 |
> |
T in; |
83 |
> |
@SuppressWarnings("serial") // Not statically typed as Serializable |
84 |
> |
T out; |
85 |
|
final int lo, hi, origin, fence, threshold; |
86 |
|
|
87 |
+ |
/** Root task constructor */ |
88 |
+ |
public CumulateTask(CumulateTask<T> parent, |
89 |
+ |
BinaryOperator<T> function, |
90 |
+ |
T[] array, int lo, int hi) { |
91 |
+ |
super(parent); |
92 |
+ |
this.function = function; this.array = array; |
93 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
94 |
+ |
int p; |
95 |
+ |
this.threshold = |
96 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
97 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
98 |
+ |
} |
99 |
+ |
|
100 |
+ |
/** Subtask constructor */ |
101 |
|
CumulateTask(CumulateTask<T> parent, BinaryOperator<T> function, |
102 |
|
T[] array, int origin, int fence, int threshold, |
103 |
|
int lo, int hi) { |
122 |
|
int mid = (l + h) >>> 1; |
123 |
|
f = rt = t.right = |
124 |
|
new CumulateTask<T>(t, fn, a, org, fnc, th, mid, h); |
125 |
< |
t = lt = t.left = |
125 |
> |
t = lt = t.left = |
126 |
|
new CumulateTask<T>(t, fn, a, org, fnc, th, l, mid); |
127 |
|
} |
128 |
|
else { // possibly refork |
226 |
|
} |
227 |
|
} |
228 |
|
} |
229 |
+ |
// OPENJDK @java.io.Serial |
230 |
|
private static final long serialVersionUID = 5293554502939613543L; |
231 |
|
} |
232 |
|
|
233 |
|
static final class LongCumulateTask extends CountedCompleter<Void> { |
234 |
|
final long[] array; |
235 |
+ |
@SuppressWarnings("serial") // Not statically typed as Serializable |
236 |
|
final LongBinaryOperator function; |
237 |
|
LongCumulateTask left, right; |
238 |
|
long in, out; |
239 |
|
final int lo, hi, origin, fence, threshold; |
240 |
|
|
241 |
+ |
/** Root task constructor */ |
242 |
+ |
public LongCumulateTask(LongCumulateTask parent, |
243 |
+ |
LongBinaryOperator function, |
244 |
+ |
long[] array, int lo, int hi) { |
245 |
+ |
super(parent); |
246 |
+ |
this.function = function; this.array = array; |
247 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
248 |
+ |
int p; |
249 |
+ |
this.threshold = |
250 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
251 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
252 |
+ |
} |
253 |
+ |
|
254 |
+ |
/** Subtask constructor */ |
255 |
|
LongCumulateTask(LongCumulateTask parent, LongBinaryOperator function, |
256 |
|
long[] array, int origin, int fence, int threshold, |
257 |
|
int lo, int hi) { |
276 |
|
int mid = (l + h) >>> 1; |
277 |
|
f = rt = t.right = |
278 |
|
new LongCumulateTask(t, fn, a, org, fnc, th, mid, h); |
279 |
< |
t = lt = t.left = |
279 |
> |
t = lt = t.left = |
280 |
|
new LongCumulateTask(t, fn, a, org, fnc, th, l, mid); |
281 |
|
} |
282 |
|
else { // possibly refork |
378 |
|
} |
379 |
|
} |
380 |
|
} |
381 |
+ |
// OPENJDK @java.io.Serial |
382 |
|
private static final long serialVersionUID = -5074099945909284273L; |
383 |
|
} |
384 |
|
|
385 |
|
static final class DoubleCumulateTask extends CountedCompleter<Void> { |
386 |
|
final double[] array; |
387 |
+ |
@SuppressWarnings("serial") // Not statically typed as Serializable |
388 |
|
final DoubleBinaryOperator function; |
389 |
|
DoubleCumulateTask left, right; |
390 |
|
double in, out; |
391 |
|
final int lo, hi, origin, fence, threshold; |
392 |
|
|
393 |
+ |
/** Root task constructor */ |
394 |
+ |
public DoubleCumulateTask(DoubleCumulateTask parent, |
395 |
+ |
DoubleBinaryOperator function, |
396 |
+ |
double[] array, int lo, int hi) { |
397 |
+ |
super(parent); |
398 |
+ |
this.function = function; this.array = array; |
399 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
400 |
+ |
int p; |
401 |
+ |
this.threshold = |
402 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
403 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
404 |
+ |
} |
405 |
+ |
|
406 |
+ |
/** Subtask constructor */ |
407 |
|
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, |
408 |
|
double[] array, int origin, int fence, int threshold, |
409 |
|
int lo, int hi) { |
428 |
|
int mid = (l + h) >>> 1; |
429 |
|
f = rt = t.right = |
430 |
|
new DoubleCumulateTask(t, fn, a, org, fnc, th, mid, h); |
431 |
< |
t = lt = t.left = |
431 |
> |
t = lt = t.left = |
432 |
|
new DoubleCumulateTask(t, fn, a, org, fnc, th, l, mid); |
433 |
|
} |
434 |
|
else { // possibly refork |
530 |
|
} |
531 |
|
} |
532 |
|
} |
533 |
+ |
// OPENJDK @java.io.Serial |
534 |
|
private static final long serialVersionUID = -586947823794232033L; |
535 |
|
} |
536 |
|
|
537 |
|
static final class IntCumulateTask extends CountedCompleter<Void> { |
538 |
|
final int[] array; |
539 |
+ |
@SuppressWarnings("serial") // Not statically typed as Serializable |
540 |
|
final IntBinaryOperator function; |
541 |
|
IntCumulateTask left, right; |
542 |
|
int in, out; |
543 |
|
final int lo, hi, origin, fence, threshold; |
544 |
|
|
545 |
+ |
/** Root task constructor */ |
546 |
+ |
public IntCumulateTask(IntCumulateTask parent, |
547 |
+ |
IntBinaryOperator function, |
548 |
+ |
int[] array, int lo, int hi) { |
549 |
+ |
super(parent); |
550 |
+ |
this.function = function; this.array = array; |
551 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
552 |
+ |
int p; |
553 |
+ |
this.threshold = |
554 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
555 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
556 |
+ |
} |
557 |
+ |
|
558 |
+ |
/** Subtask constructor */ |
559 |
|
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function, |
560 |
|
int[] array, int origin, int fence, int threshold, |
561 |
|
int lo, int hi) { |
580 |
|
int mid = (l + h) >>> 1; |
581 |
|
f = rt = t.right = |
582 |
|
new IntCumulateTask(t, fn, a, org, fnc, th, mid, h); |
583 |
< |
t = lt = t.left = |
583 |
> |
t = lt = t.left = |
584 |
|
new IntCumulateTask(t, fn, a, org, fnc, th, l, mid); |
585 |
|
} |
586 |
|
else { // possibly refork |
682 |
|
} |
683 |
|
} |
684 |
|
} |
685 |
+ |
// OPENJDK @java.io.Serial |
686 |
|
private static final long serialVersionUID = 3731755594596840961L; |
687 |
|
} |
620 |
– |
|
688 |
|
} |