Enabling and disabling parallel collections

#1

Is there a way for me to turn and off parallel collections for my program? I’d like to see the wall time difference of my algorithm using or not using parallel. I’m using iterable.par here and there. One way of course it to have two versions of the code, one with, and one without the .par. Is that the best way to go?

#2

I’d refactor it, and pull the iterable.par call into a function under my control, so I could turn the parallelism on and off with a config switch. If that function returns GenIterable or something like that, then you can either pass back the original Iterable unchanged, or the parallelized version, depending on the switch.

#3

Probably by default the executor for parallel collections is the same as Future’s global executor so controlling the number of threads could be done by adding such JVM switches:
-Dscala.concurrent.context.minThreads=N
-Dscala.concurrent.context.numThreads=N
-Dscala.concurrent.context.maxThreads=N

Haven’t tested that though.

1 Like
#4

Of course you’d still be using a parallel collection, but on a single thread.

#5

I considered trying to refactor my code this way but decided against it. It is not a feature I want to support in my library. It was just for testing to get an idea whether my parallelization efforts were paying off or not.