如何在parList和parBuffer之间进行选择? [英] How to choose between parList and parBuffer?
问题描述
r0,rseq,rdeepseq,parList,parMap
。现在我正在寻求更多的效率。所以这里是我的问题: parList
和 parBuffer
之间有什么区别?在哪些情况下,每个策略都是有效的? 解决方案这篇文章提到了这两个组合器( $ b $ p parList
进行评估,然后执行求和。
parBuffer
会计算前n个元素,当您消耗超过该元素时,它会引发下一个n,依此类推。因此,> parBuffer
在从一开始就要以区块形式使用列表时有意义 - 或者当列表非常大(或无限)时,您不会评估一切。例如,如果您想从一些昂贵的计算项目列表中找到前10个答案,则可以使用取10。使用
以便从列表中并行评估连续块,直到找到要查找的前10个项目。 parBuffer
过滤f
I'm starting in haskell parallelism, I've successfully learned how to use some Strategies like : r0, rseq, rdeepseq, parList, parMap
. Now I'm looking further for more efficiency. So here is my question : What is the difference between parList
and parBuffer
? In which cases each strategie is efficient ?
The paper mentions both these combinators (link here).
parList
evaluates all the items in parallel, setting them all off at once. I'd suggest that this is useful when you want to consume the entire list at once, for example in a map-fold problem. If you want to evaluate a bunch of numbers then sum them, use parList
for the evaluation, then perform the sum.
parBuffer
evaluates the first n elements, and when you consume beyond that, it sets off the next n, and so on. So parBuffer
makes sense when you are going to consume the list in chunks, starting at the beginning -- or when the list is very large (or infinite) and you won't evaluate it all. For example, if you want to find the first 10 answers from some list of expensive-to-calculate items, you can use take 10 . filter f
with parBuffer
to parallel-evaluate consecutive chunks from the list until you've found the first ten items that you're looking for.
这篇关于如何在parList和parBuffer之间进行选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!