开发者

How do I replace the fork join pool for a Scala 2.9 parallel collection?

开发者 https://www.devze.com 2023-03-06 20:45 出处:网络
I\'ve been looking at the new Scala 2.9 parallel collections and am hoping to abandon a whole lot of my crufty amateur versions of similar things. In particular, I\'d like to replace the fork join poo

I've been looking at the new Scala 2.9 parallel collections and am hoping to abandon a whole lot of my crufty amateur versions of similar things. In particular, I'd like to replace the fork join pool which underlies the default implementation with something of my own (for example, something that distributes evaluation of tasks across a network, via actors). My understanding is that this is simply a matter of applying Scala's paradigm of "stackable modifications", but the collections library is intimidating enough that I'm not exactly sure which bits need modifying!

Some concrete questions:

  1. Is it correct that the 开发者_如何学Gostandard parallel implementations interact with the fork join pool solely through the code in ForkJoinTasks?
  2. I see that there's an alternative trait, FutureThreadPoolTasks. How would I build a collection which uses this trait instead of ForkJoinTasks?
  3. Can I just write yet another alternative (and perhaps a corresponding boilerplate class that mixes in AdaptiveWorkStealingTasks and somehow instantiate collections instances that use this new trait?

(For reference, all of the traits mentioned above are defined in Tasks.scala.)

Especially code examples are very welcome!


Just to provide some more information on how things fit together (which I suspect you already know): the fork-join pool is "plugged in" via the parallel package object's tasksupport value which implements the scala.collection.parallel.TaskSupport trait.

This, in turn, inherits from Tasks (which you mention) and defines such operations as:

def execute[R, Tp](fjtask: Task[R, Tp]): () => R

def executeAndWaitResult[R, Tp](task: Task[R, Tp]): R

However, it's not immediately obvious to me how you can override the behaviour which is explicitly imported by the collections themselves by supplying your own TaskSupport implementation. For example, in ParSeqLike line 47:

import tasksupport._

In fact,I would go so far as saying it looks like the parallelism is definitively not overridable (unless I am very much mistaken, though I often am).


Here is a document describing how to switch TaskSupport objects in Scala 2.10.

0

精彩评论

暂无评论...
验证码 换一张
取 消