是否有并行的方案实现?
是否有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
球拍有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").
事实证明,您并不真正希望编译器尝试并行化所有内容,因为这样您最终就会浪费时间来协调工作,即使是在做一些简单的事情时,比如
在一个线程上执行会更快。然而,当“add1”实际上是“真正的长计算”时,现在的许多函数式语言使您可以轻松地进行这种并行。每种语言都有自己的方法,但我建议使用 future 来利用 Racket 中的多个核心。
虽然编译器自动为您决定事情很好,但将“map”更改为“pmap”并不是一个糟糕的权衡,您认为它可能会有所帮助,而不是处理其他地方的减速问题,因为编译器过于雄心勃勃。
如果明智地使用一些基本的东西
可以让你走得很远,但你应该尝试将数据分块以提供给并行线程。
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,
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
can get you pretty far when used judiciously, but you should experiment with chunking up your data to feed to parallel threads.
我刚刚发现 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.
我是 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?