score:0

Accepted answer

There was an error in the version of scala I was using. It has since been fixed.

score:0

I can't reproduce this:

case class Obj(i: Int)
val list = List(1 to 12 map Obj: _*)
def f(o: Obj) = { println("f " + o); Obj(o.i + 1) }
val data = list.par.map(f)

Prints:

f Obj(1)
f Obj(2)
f Obj(3)
f Obj(4)
f Obj(5)
f Obj(6)
f Obj(7)
f Obj(8)
f Obj(10)
f Obj(11)
f Obj(12)
f Obj(9)
// data: ParVector(Obj(2), Obj(3), Obj(4), Obj(5), Obj(6), Obj(7), Obj(8), Obj(9),
// Obj(10), Obj(11), Obj(12), Obj(13))

See scala: parallel collections not working? for a similar symptoms and where adding some artificial delay showed things could happen in parallel.

How do you find out ifParallel is taking the otherwise route? I do this:

scala> collection.parallel.ParSeq.canBuildFrom[Int].isParallel
res0: Boolean = true

Also, what is the value of Runtime.getRuntime.availableProcessors?


Related Query

More Query from same tag