Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

parallel processing - Set the parallelism level for all collections in Scala 2.10?

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/82970).

How can I set the parallelism level for all new parallel collections in Scala 2.10?

A subsidiary question --- is the tasksupport associated to a parallel collection 'inherited' by new parallel collections built out of it? (e.g. with take, map, etc.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. 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 level
    • scala.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 level

    The relevant source file (if I followed everything correctly) seems to be ExecutionContextImpl.

  2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...