如何替换 Scala 2.9 并行集合的 fork join 池?

发布于 2024-11-08 02:42:43 字数 1204 浏览 4 评论 0原文

我一直在研究新的 Scala 2.9 并行集合,并希望放弃我对类似事物的大量粗俗业余版本。特别是,我想用我自己的东西(例如,通过参与者在网络上分配任务评估的东西)替换作为默认实现基础的 fork join 池。我的理解是,这只是应用 Scala 的“可堆栈修改”范例的问题,但集合库足够令人生畏,我不确定哪些位需要修改!

一些具体问题:

  1. 标准并行实现仅通过 ForkJoinTasks
  2. 我看到有一个替代特征 FutureThreadPoolTask​​s。我将如何构建一个使用此特征而不是 ForkJoinTasks
  3. 我可以编写另一个替代方案(也许还有一个混合在 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:

  1. Is it correct that the standard 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江挽川 2024-11-15 02:42:43

只是为了提供一些有关如何组合在一起的更多信息(我怀疑您已经知道):fork-join 池通过 parallel 包对象的 tasksupport“插入”实现 scala.collection.parallel.TaskSupport 特征的值。

反过来,它继承自 Tasks (您提到的)并将此类操作定义为:

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

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

但是,对我来说,如何覆盖显式的行为并不是很明显通过提供您自己的 TaskSupport 实现,由集合本身导入。例如,在 ParSeqLike 第 47 行中:

import tasksupport._

事实上,我什至会说并行性绝对是不可重写的(除非我大错特错了,不过)我经常这样)。

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

酷到爆炸 2024-11-15 02:42:43

这里是一个文档,描述如何在中切换 TaskSupport 对象斯卡拉 2.10。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文