Suppose I have an array of ~10K elements and I need to process all elements of the array. I would like to process them in such a way that only K elements are processed in parallel.
I use Scala 2.9. I tried parallel collections (see below) but I saw more than K elements processed in parallel.
import collection.parallel.ForkJoinTasks.defaultForkJoinPool._ val old = getParallelism setParallelism(K) val result = myArray.par.map(...) // process the array in parallel setParallelism(old)
How would you suggest process an array in Scala 2.9 in such a way that only K elements are processed in parallel ?