summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/parallel/package.scala
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-06-18 15:06:17 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-06-18 15:06:17 +0000
commit9923b97157725ae1f7853a4834ef5e31283a1b98 (patch)
tree6252cf350a91d6bed178b07ed3ddc7fdd21d2890 /src/library/scala/collection/parallel/package.scala
parentceec792d1af5bb7b2d618f27f6fd48cdf75cf92f (diff)
downloadscala-9923b97157725ae1f7853a4834ef5e31283a1b98.tar.gz
scala-9923b97157725ae1f7853a4834ef5e31283a1b98.tar.bz2
scala-9923b97157725ae1f7853a4834ef5e31283a1b98.zip
Moved parallel collections to library dir, chan...
Moved parallel collections to library dir, changed sabbus script. Added `par` to some of the classes. No review.
Diffstat (limited to 'src/library/scala/collection/parallel/package.scala')
-rw-r--r--src/library/scala/collection/parallel/package.scala70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/library/scala/collection/parallel/package.scala b/src/library/scala/collection/parallel/package.scala
new file mode 100644
index 0000000000..cddf098966
--- /dev/null
+++ b/src/library/scala/collection/parallel/package.scala
@@ -0,0 +1,70 @@
+package scala.collection
+
+
+import java.lang.Thread._
+
+import scala.collection.generic.CanBuildFrom
+import scala.collection.generic.CanCombineFrom
+
+
+/** Package object for parallel collections.
+ */
+package object parallel {
+ val MIN_FOR_COPY = -1 // TODO: set to 5000
+ val CHECK_RATE = 512
+
+ /** Computes threshold from the size of the collection and the parallelism level.
+ */
+ def thresholdFromSize(sz: Int, parallelismLevel: Int) = {
+ val p = parallelismLevel
+ if (p > 1) 1 + sz / (8 * p)
+ else sz
+ }
+
+ /** An implicit conversion providing arrays with a `par` method, which
+ * returns a parallel array.
+ *
+ * @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
+ */
+ implicit def array2ParallelArray[T <: AnyRef](array: Array[T]) = new Parallelizable[mutable.ParallelArray[T]] {
+ def par = mutable.ParallelArray.handoff[T](array)
+ }
+
+ implicit def factory2ops[From, Elem, To](bf: CanBuildFrom[From, Elem, To]) = new {
+ def isParallel = bf.isInstanceOf[Parallel]
+ def asParallel = bf.asInstanceOf[CanCombineFrom[From, Elem, To]]
+ def ifParallel[R](isbody: CanCombineFrom[From, Elem, To] => R) = new {
+ def otherwise(notbody: => R) = if (isParallel) isbody(asParallel) else notbody
+ }
+ }
+
+ implicit def traversable2ops[T](t: TraversableOnce[T]) = new {
+ def isParallel = t.isInstanceOf[Parallel]
+ def isParallelIterable = t.isInstanceOf[ParallelIterable[_]]
+ def asParallelIterable = t.asInstanceOf[ParallelIterable[T]]
+ def isParallelSeq = t.isInstanceOf[ParallelSeq[_]]
+ def asParallelSeq = t.asInstanceOf[ParallelSeq[T]]
+ def ifParallelSeq[R](isbody: ParallelSeq[T] => R) = new {
+ def otherwise(notbody: => R) = if (isParallel) isbody(asParallelSeq) else notbody
+ }
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+