diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-07-27 09:09:47 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-07-27 09:09:47 +0000 |
commit | 3630e9ba4552caf1813957a50b1d75d121b3babf (patch) | |
tree | 168680cfd315778fae8a412134e9a42876a59231 /src/library | |
parent | c6cc8c72820a5d540b9bfa4a8dc52eb0923936f1 (diff) | |
download | scala-3630e9ba4552caf1813957a50b1d75d121b3babf.tar.gz scala-3630e9ba4552caf1813957a50b1d75d121b3babf.tar.bz2 scala-3630e9ba4552caf1813957a50b1d75d121b3babf.zip |
Minor tweaks. No review.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/parallel/ParIterableLike.scala | 9 | ||||
-rw-r--r-- | src/library/scala/collection/parallel/package.scala | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala index 0769181150..ff37c89517 100644 --- a/src/library/scala/collection/parallel/ParIterableLike.scala +++ b/src/library/scala/collection/parallel/ParIterableLike.scala @@ -941,7 +941,14 @@ extends IterableLike[T, Repr] result = true } else pit.scanToArray(z, op, array, from) def newSubtask(p: ParIterator) = unsupported - override def shouldSplitFurther = len > size / 2 + override lazy val shouldSplitFurther = { + // we want less work stealings while prefix scanning + // and keep processors busier with merging + // (work stealing while prefix scanning means more work later) + val processors = parallelismLevel min availableProcessors + len > ((size / tweak(processors)) max 1) + } + private def tweak(p: Int) = if (p < 4) 2 else p / 2 override def split = { val pits = pit.split for ((p, untilp) <- pits zip pits.scanLeft(0)(_ + _.remaining); if untilp < len) yield { diff --git a/src/library/scala/collection/parallel/package.scala b/src/library/scala/collection/parallel/package.scala index c0379b819e..3d8e7208ae 100644 --- a/src/library/scala/collection/parallel/package.scala +++ b/src/library/scala/collection/parallel/package.scala @@ -12,6 +12,7 @@ import scala.collection.generic.CanCombineFrom package object parallel { val MIN_FOR_COPY = -1 // TODO: set to 5000 val CHECK_RATE = 512 + val SQRT2 = math.sqrt(2) /** Computes threshold from the size of the collection and the parallelism level. */ @@ -21,6 +22,8 @@ package object parallel { else sz } + val availableProcessors = java.lang.Runtime.getRuntime.availableProcessors + def unsupported(msg: String) = throw new UnsupportedOperationException(msg) def unsupported = throw new UnsupportedOperationException @@ -30,7 +33,7 @@ package object parallel { * * @tparam T type of the elements in the array, which is a subtype of AnyRef * @param array the array to be parallelized - * @return a `Parallelizable` object with a `par` method + * @return a `Parallelizable` object with a `par` method= */ implicit def array2ParArray[T <: AnyRef](array: Array[T]) = new Parallelizable[mutable.ParArray[T]] { def par = mutable.ParArray.handoff[T](array) |