ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/ArrayPrefixHelpers.java
(Generate patch)

Comparing jsr166/src/main/java/util/ArrayPrefixHelpers.java (file contents):
Revision 1.1 by dl, Wed Jan 16 19:01:22 2013 UTC vs.
Revision 1.6 by jsr166, Sat Sep 19 18:51:03 2015 UTC

# Line 5 | Line 5
5   */
6  
7   package java.util;
8 < import java.util.concurrent.ForkJoinPool;
8 >
9   import java.util.concurrent.CountedCompleter;
10   import java.util.function.BinaryOperator;
11 + import java.util.function.DoubleBinaryOperator;
12   import java.util.function.IntBinaryOperator;
13   import java.util.function.LongBinaryOperator;
13 import java.util.function.DoubleBinaryOperator;
14  
15   /**
16   * ForkJoin tasks to perform Arrays.parallelPrefix operations.
# Line 19 | Line 19 | import java.util.function.DoubleBinaryOp
19   * @since 1.8
20   */
21   class ArrayPrefixHelpers {
22 <    private ArrayPrefixHelpers() {}; // non-instantiable
22 >    private ArrayPrefixHelpers() {} // non-instantiable
23  
24      /*
25       * Parallel prefix (aka cumulate, scan) task classes
# Line 79 | Line 79 | class ArrayPrefixHelpers {
79          T in, out;
80          final int lo, hi, origin, fence, threshold;
81  
82        /** Root task constructor */
83        public CumulateTask(CumulateTask<T> parent,
84                            BinaryOperator<T> function,
85                            T[] array, int lo, int hi) {
86            super(parent);
87            this.function = function; this.array = array;
88            this.lo = this.origin = lo; this.hi = this.fence = hi;
89            int p;
90            this.threshold =
91                (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
92                <= MIN_PARTITION ? MIN_PARTITION : p;
93        }
94
95        /** Subtask constructor */
82          CumulateTask(CumulateTask<T> parent, BinaryOperator<T> function,
83                       T[] array, int origin, int fence, int threshold,
84                       int lo, int hi) {
# Line 187 | Line 173 | class ArrayPrefixHelpers {
173                          sum = t.in;
174                      t.out = sum;
175                      for (CumulateTask<T> par;;) {             // propagate
176 <                        if ((par = (CumulateTask<T>)t.getCompleter()) == null) {
176 >                        @SuppressWarnings("unchecked") CumulateTask<T> partmp
177 >                            = (CumulateTask<T>)t.getCompleter();
178 >                        if ((par = partmp) == null) {
179                              if ((state & FINISHED) != 0)      // enable join
180                                  t.quietlyComplete();
181                              break outer;
# Line 229 | Line 217 | class ArrayPrefixHelpers {
217          long in, out;
218          final int lo, hi, origin, fence, threshold;
219  
232        /** Root task constructor */
233        public LongCumulateTask(LongCumulateTask parent,
234                                LongBinaryOperator function,
235                                long[] array, int lo, int hi) {
236            super(parent);
237            this.function = function; this.array = array;
238            this.lo = this.origin = lo; this.hi = this.fence = hi;
239            int p;
240            this.threshold =
241                (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
242                <= MIN_PARTITION ? MIN_PARTITION : p;
243        }
244
245        /** Subtask constructor */
220          LongCumulateTask(LongCumulateTask parent, LongBinaryOperator function,
221                           long[] array, int origin, int fence, int threshold,
222                           int lo, int hi) {
# Line 379 | Line 353 | class ArrayPrefixHelpers {
353          double in, out;
354          final int lo, hi, origin, fence, threshold;
355  
382        /** Root task constructor */
383        public DoubleCumulateTask(DoubleCumulateTask parent,
384                                DoubleBinaryOperator function,
385                                double[] array, int lo, int hi) {
386            super(parent);
387            this.function = function; this.array = array;
388            this.lo = this.origin = lo; this.hi = this.fence = hi;
389            int p;
390            this.threshold =
391                (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
392                <= MIN_PARTITION ? MIN_PARTITION : p;
393        }
394
395        /** Subtask constructor */
356          DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
357 <                         double[] array, int origin, int fence, int threshold,
358 <                         int lo, int hi) {
357 >                           double[] array, int origin, int fence, int threshold,
358 >                           int lo, int hi) {
359              super(parent);
360              this.function = function; this.array = array;
361              this.origin = origin; this.fence = fence;
# Line 529 | Line 489 | class ArrayPrefixHelpers {
489          int in, out;
490          final int lo, hi, origin, fence, threshold;
491  
532        /** Root task constructor */
533        public IntCumulateTask(IntCumulateTask parent,
534                                IntBinaryOperator function,
535                                int[] array, int lo, int hi) {
536            super(parent);
537            this.function = function; this.array = array;
538            this.lo = this.origin = lo; this.hi = this.fence = hi;
539            int p;
540            this.threshold =
541                (p = (hi - lo) / (ForkJoinPool.getCommonPoolParallelism() << 3))
542                <= MIN_PARTITION ? MIN_PARTITION : p;
543        }
544
545        /** Subtask constructor */
492          IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
493 <                         int[] array, int origin, int fence, int threshold,
494 <                         int lo, int hi) {
493 >                        int[] array, int origin, int fence, int threshold,
494 >                        int lo, int hi) {
495              super(parent);
496              this.function = function; this.array = array;
497              this.origin = origin; this.fence = fence;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines