是否有并行的方案实现?

发布于 2024-09-10 13:08:35 字数 244 浏览 7 评论 0原文

是否有 R5RS 或更高版本的方案实现可以并行化?例如,如果我说做:

(map (lambda (x) 
        (pure-functional-stuff x))
     '(1 3 5 7 11 13))

它会同时处理1、3、5、7,如果机器能做到的话?这应该是函数式编程的一大优势,但我找不到一个维护的、最新的方案来做到这一点。我会同意一个不会并行化它的函数,除非我断言该函数没有副作用。

Is there a R5RS-or-higher Scheme implementation that does parallelization? For example, if I say to do:

(map (lambda (x) 
        (pure-functional-stuff x))
     '(1 3 5 7 11 13))

it will process 1, 3, 5, and 7 simultaneously if the machine can do it? That's supposed to be one of the big advantages of functional programming, but I can't find a maintained, up-to-date Scheme that does it. I'd be fine with one that wouldn't parallelize it unless I assert that the function doesn't have side-effects.

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

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

发布评论

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

评论(4

蓝海 2024-09-17 13:08:36

球拍futures 做的事情与此非常相似,并且在不久的将来还将有第二种并行方法(称为“地方”)。

Racket has futures that do something very similar to this, and will also have a second approach for parallelism in the near future (which will be called "places").

乜一 2024-09-17 13:08:36

事实证明,您并不真正希望编译器尝试并行化所有内容,因为这样您最终就会浪费时间来协调工作,即使是在做一些简单的事情时,比如

(map add1 '(1 2 3))

在一个线程上执行会更快。然而,当“add1”实际上是“真正的长计算”时,现在的许多函数式语言使您可以轻松地进行这种并行。每种语言都有自己的方法,但我建议使用 future 来利用 Racket 中的多个核心。

虽然编译器自动为您决定事情很好,但将“map”更改为“pmap”并不是一个糟糕的权衡,您认为它可能会有所帮助,而不是处理其他地方的减速问题,因为编译器过于雄心勃勃。

如果明智地使用一些基本的东西

(define (pmap f xs)
  (map touch (map (λ(x) (future (λ() (f x)))) xs)))

可以让你走得很远,但你应该尝试将数据分块以提供给并行线程。

It turns out that you don't really want the compiler to try to parallelize everything because then you end up wasting time coordinating efforts even when doing something simple like,

(map add1 '(1 2 3))

that would be faster to just do on one thread. However, many functional languages these days make it easy for you to make this parallel when "add1" is actually "really-long-computation". Each language has its own approach, but I'd recommend taking advantage of multiple cores in Racket using futures.

While the compiler deciding things automatically for you is nice, it's not a bad tradeoff to change a "map" to a "pmap" where you think it might help rather than deal with slowdowns in other places because the compiler was too ambitious.

Something as basic as

(define (pmap f xs)
  (map touch (map (λ(x) (future (λ() (f x)))) xs)))

can get you pretty far when used judiciously, but you should experiment with chunking up your data to feed to parallel threads.

〆一缕阳光ご 2024-09-17 13:08:36

我刚刚发现 Schemik

http://schemik.sourceforge.net/

似乎至少维持到 2009 年,虽然我不知道是不是R5RS。

I just found Schemik

http://schemik.sourceforge.net/

which seems to be maintained to at least 2009, though I don't know if it's R5RS.

勿忘初心 2024-09-17 13:08:35

我是 Schemik 的开发人员,我认为这就是您正在寻找的方案。该项目仍在开发和维护中。今年年初,我发布了一个改进了与 R5RS 兼容性的版本。不幸的是,Schemik是一个专注于表达评估过程的研究项目,因此,它的标准库仍然相对较小。 Schemak 中是否有您错过的特定功能?

I'm a developer of Schemik and I think that it is the Scheme you are looking for. The project is still developed and maintained. Early this year, I released a version which improves compatibility with R5RS. Unfortunately, Schemik is a research project focused on the process of expression evaluation, thus, its standard library is still relatively small. Is there any particular functionality you miss in Schemik?

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