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.5 by jsr166, Sat Sep 19 18:36:55 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.concurrent.ForkJoinPool;
11   import java.util.function.BinaryOperator;
12 + import java.util.function.DoubleBinaryOperator;
13   import java.util.function.IntBinaryOperator;
14   import java.util.function.LongBinaryOperator;
13 import java.util.function.DoubleBinaryOperator;
15  
16   /**
17   * ForkJoin tasks to perform Arrays.parallelPrefix operations.
# Line 19 | Line 20 | import java.util.function.DoubleBinaryOp
20   * @since 1.8
21   */
22   class ArrayPrefixHelpers {
23 <    private ArrayPrefixHelpers() {}; // non-instantiable
23 >    private ArrayPrefixHelpers() {} // non-instantiable
24  
25      /*
26       * Parallel prefix (aka cumulate, scan) task classes
# Line 79 | Line 80 | class ArrayPrefixHelpers {
80          T in, out;
81          final int lo, hi, origin, fence, threshold;
82  
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 */
83          CumulateTask(CumulateTask<T> parent, BinaryOperator<T> function,
84                       T[] array, int origin, int fence, int threshold,
85                       int lo, int hi) {
# Line 187 | Line 174 | class ArrayPrefixHelpers {
174                          sum = t.in;
175                      t.out = sum;
176                      for (CumulateTask<T> par;;) {             // propagate
177 <                        if ((par = (CumulateTask<T>)t.getCompleter()) == null) {
177 >                        @SuppressWarnings("unchecked") CumulateTask<T> partmp
178 >                            = (CumulateTask<T>)t.getCompleter();
179 >                        if ((par = partmp) == null) {
180                              if ((state & FINISHED) != 0)      // enable join
181                                  t.quietlyComplete();
182                              break outer;
# Line 229 | Line 218 | class ArrayPrefixHelpers {
218          long in, out;
219          final int lo, hi, origin, fence, threshold;
220  
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 */
221          LongCumulateTask(LongCumulateTask parent, LongBinaryOperator function,
222                           long[] array, int origin, int fence, int threshold,
223                           int lo, int hi) {
# Line 379 | Line 354 | class ArrayPrefixHelpers {
354          double in, out;
355          final int lo, hi, origin, fence, threshold;
356  
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 */
357          DoubleCumulateTask(DoubleCumulateTask parent, DoubleBinaryOperator function,
358 <                         double[] array, int origin, int fence, int threshold,
359 <                         int lo, int hi) {
358 >                           double[] array, int origin, int fence, int threshold,
359 >                           int lo, int hi) {
360              super(parent);
361              this.function = function; this.array = array;
362              this.origin = origin; this.fence = fence;
# Line 529 | Line 490 | class ArrayPrefixHelpers {
490          int in, out;
491          final int lo, hi, origin, fence, threshold;
492  
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 */
493          IntCumulateTask(IntCumulateTask parent, IntBinaryOperator function,
494 <                         int[] array, int origin, int fence, int threshold,
495 <                         int lo, int hi) {
494 >                        int[] array, int origin, int fence, int threshold,
495 >                        int lo, int hi) {
496              super(parent);
497              this.function = function; this.array = array;
498              this.origin = origin; this.fence = fence;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines