如何替换 Scala 2.9 并行集合的 fork join 池?
我一直在研究新的 Scala 2.9 并行集合,并希望放弃我对类似事物的大量粗俗业余版本。特别是,我想用我自己的东西(例如,通过参与者在网络上分配任务评估的东西)替换作为默认实现基础的 fork join 池。我的理解是,这只是应用 Scala 的“可堆栈修改”范例的问题,但集合库足够令人生畏,我不确定哪些位需要修改!
一些具体问题:
- 标准并行实现仅通过
ForkJoinTasks
? - 我看到有一个替代特征
FutureThreadPoolTasks
。我将如何构建一个使用此特征而不是ForkJoinTasks
? - 我可以编写另一个替代方案(也许还有一个混合在
AdaptiveWorkStealingTasks
并以某种方式实例化使用此新特征的集合实例
(作为参考,上面提到的所有特征均在 Tasks.scala。 )
特别是代码示例非常受欢迎!
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:
- Is it correct that the standard parallel implementations interact with the fork join pool solely through the code in
ForkJoinTasks
? - I see that there's an alternative trait,
FutureThreadPoolTasks
. How would I build a collection which uses this trait instead ofForkJoinTasks
? - 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了提供一些有关如何组合在一起的更多信息(我怀疑您已经知道):fork-join 池通过
parallel
包对象的tasksupport
“插入”实现 scala.collection.parallel.TaskSupport 特征的值。反过来,它继承自
Tasks
(您提到的)并将此类操作定义为:但是,对我来说,如何覆盖显式的行为并不是很明显通过提供您自己的
TaskSupport
实现,由集合本身导入。例如,在 ParSeqLike 第 47 行中:事实上,我什至会说并行性绝对是不可重写的(除非我大错特错了,不过)我经常这样)。
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'stasksupport
value which implements thescala.collection.parallel.TaskSupport
trait.This, in turn, inherits from
Tasks
(which you mention) and defines such operations as: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, inParSeqLike
line 47: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).
这里是一个文档,描述如何在中切换
TaskSupport
对象斯卡拉 2.10。Here is a document describing how to switch
TaskSupport
objects in Scala 2.10.