什么是“火花”?在Haskell [英] What is a "spark" in Haskell
问题描述
我对spark的概念感到困惑
它是Haskell中的一个线程吗?或者是产生新线程的行为?
谢谢大家:
因此,总结一下,火花不是线程,而是更多的计算单位把它放在C#/ Java术语中)。所以这就是Haskell实现任务并行的方式。 解决方案
并行性由GPH中的
par
组合子引入,该组合子需要并行计算两个参数。表达式p`par` e
(这里我们使用Haskell的中缀操作符表示)具有与e
相同的值,并且在第一个参数中不是严格的,即bottom`par` e
的值为e
。 (bottom
表示一个非终止或失败的计算)。它的动态行为是指示p
可以通过一个新的并行线程,父线程继续评估e
。我们说p
已经被触发,并且随后可以创建一个线程来评估处理器是否空闲。由于线程不一定是创建的,因此p
类似于懒惰的未来。
[强调原创]
I'm confused about the notion of "spark"
Is it a thread in Haskell? Or is the action of spawning a new thread ?
Thanks everybody:
So to summarize, sparks are not thread but more of unit of computation (tasks to put it in C#/Java terms). So it's the Haskell way of implementing the task parallelism.
See A Gentle Introduction to Glasgow Parallel Haskell.
Parallelism is introduced in GPH by the
par
combinator, which takes two arguments that are to be evaluated in parallel. The expressionp `par` e
(here we use Haskell's infix operator notation) has the same value ase
, and is not strict in its first argument, i.e.bottom `par` e
has the value ofe
. (bottom
denotes a non-terminating or failing computation.) Its dynamic behaviour is to indicate thatp
could be evaluated by a new parallel thread, with the parent thread continuing evaluation ofe
. We say thatp
has been sparked, and a thread may subsequently be created to evaluate it if a processor becomes idle. Since the thread is not necessarily created,p
is similar to a lazy future.
[Emphasis in original]
这篇关于什么是“火花”?在Haskell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!