質問

I have this simple query to run and I want to parallelize it:

val res : Array[Int] = valuesRand
.groupBy(v => v)
.toSeq
.sortBy(_._1)
.map(_._2.size)
.toArray

Is the following the performant equivalent of my query?

val res : Array[Int] = valuesRand
.par
.groupBy(v => v)
.par
.toIndexedSeq
.sortBy(_._1)
.map(_._2.size)
.toArray

I am asking that, because I couldn't find the sortBy method into ParSeq, although it exists in Seq.

役に立ちましたか?

解決

The ParSeq class does not directly extend SeqLike which provides for the sortBy. You can see this from the definition of ParSeqLike:

trait ParSeqLike[+T, +Repr <: ParSeq[T], +Sequential <: scala.Seq[T] with SeqLike[T, Sequential]] extends GenSeqLike[T, Repr] with ParIterableLike[T, Repr, Sequential]

which ParSeq extends via

ParSeqLike[T, ParSeq[T], scala.Seq[T]]

Hence, only the Splitter in the underlying implementation is able to do a sortBy which does not help you one bit.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top