Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructing Scala parallel views with X.par.view vs X.view.par?

According to the paper on parallel collections and searching on the internet, parallel collections are supposed to work with views, but I am not clear on the difference between

coll.par.view.someChainedIterations

and

coll.view.par.someChainedIterations

It seems like coll.view.par looses the viewness of the collection:

scala> val coll = 1 to 3
coll: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3)

scala> coll.view.par
res2: scala.collection.parallel.ParSeq[Int] = ParArray(1, 2, 3)

scala> coll.par.view
res3: java.lang.Object with scala.collection.parallel.ParSeqView[Int,scala.collection.parallel.immutable.ParSeq[Int],scala.collection.immutable.Seq[Int]] = $anon$1(1, 2, 3)

but I do not know why. Is it a feature or a bug?

like image 446
Daniel Mahler Avatar asked Feb 28 '13 18:02

Daniel Mahler


1 Answers

This is probably an oversight, and should be fixed.

The par on sequential views could be implemented by calling the par on the underlying collection, which would result in a chain of recursive par calls until the underlying is a strict collection that the view was originally obtained from. If this collection can be turned into its corresponding parallel collection efficiently, than the newly obtained parallel view can be constructed efficiently (see here).

like image 183
axel22 Avatar answered Nov 03 '22 10:11

axel22