I understand how to set the parallelism level for a single parallel collection, via the mutable tasksupport
field (c.f. https://stackoverflow.com/a/5425354/8297
I looked at the sources briefly and if I understand things correctly, there are three system properties that can be used to configure the default execution context, which seems to be used as default task support. These determine the parallelism level of the task support object.
scala.concurrent.context.minThreads
: Int, minimum parallelism levelscala.concurrent.context.numThreads
: either an Int, to specify the parallelism level to use directly, or a String: an "x" followed by a Double (e.g. "x1.5"), which is then multiplied with Runtime.getRuntime.availableProcessors
scala.concurrent.context.maxThreads
: Int, maximum parallelism levelThe relevant source file (if I followed everything correctly) seems to be ExecutionContextImpl.
As for the second part of your question:
Transforming operations like map
, filter
etc. should preserve the task support that has been set on the originating collection. At least the sources look that way. :)
Most parallel operations are defined in ParIterableLike and they either call resultWithTaskSupport
in Combiner (which gets gets the originating task support set via the factory in lines 568 or 581 in ParIterableLike) or set the task support directly on the resulting collection.