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; |
80 |
|
T in, out; |
81 |
|
final int lo, hi, origin, fence, threshold; |
82 |
|
|
83 |
+ |
/** Root task constructor */ |
84 |
+ |
public CumulateTask(CumulateTask<T> parent, |
85 |
+ |
BinaryOperator<T> function, |
86 |
+ |
T[] array, int lo, int hi) { |
87 |
+ |
super(parent); |
88 |
+ |
this.function = function; this.array = array; |
89 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
90 |
+ |
int p; |
91 |
+ |
this.threshold = |
92 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
93 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
94 |
+ |
} |
95 |
+ |
|
96 |
+ |
/** Subtask constructor */ |
97 |
|
CumulateTask(CumulateTask<T> parent, BinaryOperator<T> function, |
98 |
|
T[] array, int origin, int fence, int threshold, |
99 |
|
int lo, int hi) { |
118 |
|
int mid = (l + h) >>> 1; |
119 |
|
f = rt = t.right = |
120 |
|
new CumulateTask<T>(t, fn, a, org, fnc, th, mid, h); |
121 |
< |
t = lt = t.left = |
121 |
> |
t = lt = t.left = |
122 |
|
new CumulateTask<T>(t, fn, a, org, fnc, th, l, mid); |
123 |
|
} |
124 |
|
else { // possibly refork |
232 |
|
long in, out; |
233 |
|
final int lo, hi, origin, fence, threshold; |
234 |
|
|
235 |
+ |
/** Root task constructor */ |
236 |
+ |
public LongCumulateTask(LongCumulateTask parent, |
237 |
+ |
LongBinaryOperator function, |
238 |
+ |
long[] array, int lo, int hi) { |
239 |
+ |
super(parent); |
240 |
+ |
this.function = function; this.array = array; |
241 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
242 |
+ |
int p; |
243 |
+ |
this.threshold = |
244 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
245 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
246 |
+ |
} |
247 |
+ |
|
248 |
+ |
/** Subtask constructor */ |
249 |
|
LongCumulateTask(LongCumulateTask parent, LongBinaryOperator function, |
250 |
|
long[] array, int origin, int fence, int threshold, |
251 |
|
int lo, int hi) { |
270 |
|
int mid = (l + h) >>> 1; |
271 |
|
f = rt = t.right = |
272 |
|
new LongCumulateTask(t, fn, a, org, fnc, th, mid, h); |
273 |
< |
t = lt = t.left = |
273 |
> |
t = lt = t.left = |
274 |
|
new LongCumulateTask(t, fn, a, org, fnc, th, l, mid); |
275 |
|
} |
276 |
|
else { // possibly refork |
382 |
|
double in, out; |
383 |
|
final int lo, hi, origin, fence, threshold; |
384 |
|
|
385 |
+ |
/** Root task constructor */ |
386 |
+ |
public DoubleCumulateTask(DoubleCumulateTask parent, |
387 |
+ |
DoubleBinaryOperator function, |
388 |
+ |
double[] array, int lo, int hi) { |
389 |
+ |
super(parent); |
390 |
+ |
this.function = function; this.array = array; |
391 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
392 |
+ |
int p; |
393 |
+ |
this.threshold = |
394 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
395 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
396 |
+ |
} |
397 |
+ |
|
398 |
+ |
/** Subtask constructor */ |
399 |
|
DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function, |
400 |
|
double[] array, int origin, int fence, int threshold, |
401 |
|
int lo, int hi) { |
420 |
|
int mid = (l + h) >>> 1; |
421 |
|
f = rt = t.right = |
422 |
|
new DoubleCumulateTask(t, fn, a, org, fnc, th, mid, h); |
423 |
< |
t = lt = t.left = |
423 |
> |
t = lt = t.left = |
424 |
|
new DoubleCumulateTask(t, fn, a, org, fnc, th, l, mid); |
425 |
|
} |
426 |
|
else { // possibly refork |
532 |
|
int in, out; |
533 |
|
final int lo, hi, origin, fence, threshold; |
534 |
|
|
535 |
+ |
/** Root task constructor */ |
536 |
+ |
public IntCumulateTask(IntCumulateTask parent, |
537 |
+ |
IntBinaryOperator function, |
538 |
+ |
int[] array, int lo, int hi) { |
539 |
+ |
super(parent); |
540 |
+ |
this.function = function; this.array = array; |
541 |
+ |
this.lo = this.origin = lo; this.hi = this.fence = hi; |
542 |
+ |
int p; |
543 |
+ |
this.threshold = |
544 |
+ |
(p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3)) |
545 |
+ |
<= MIN_PARTITION ? MIN_PARTITION : p; |
546 |
+ |
} |
547 |
+ |
|
548 |
+ |
/** Subtask constructor */ |
549 |
|
IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function, |
550 |
|
int[] array, int origin, int fence, int threshold, |
551 |
|
int lo, int hi) { |
570 |
|
int mid = (l + h) >>> 1; |
571 |
|
f = rt = t.right = |
572 |
|
new IntCumulateTask(t, fn, a, org, fnc, th, mid, h); |
573 |
< |
t = lt = t.left = |
573 |
> |
t = lt = t.left = |
574 |
|
new IntCumulateTask(t, fn, a, org, fnc, th, l, mid); |
575 |
|
} |
576 |
|
else { // possibly refork |
674 |
|
} |
675 |
|
private static final long serialVersionUID = 3731755594596840961L; |
676 |
|
} |
620 |
– |
|
677 |
|
} |