Enabling and disabling parallel collections

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?

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.

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:

Haven’t tested that though.

1 Like

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

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.