如何在parList和parBuffer之间进行选择? [英] How to choose between parList and parBuffer?

查看:167
本文介绍了如何在parList和parBuffer之间进行选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用haskell并行,我已经学会了如何使用一些策略,比如: r0,rseq,rdeepseq,parList,parMap 。现在我正在寻求更多的效率。所以这里是我的问题: parList parBuffer 之间有什么区别?在哪些情况下,每个策略都是有效的? 解决方案

这篇文章提到了这两个组合器( $ b $ p $ c>并行评估所有项目,一次设置它们全部关闭。我建议,当你想要一次使用整个列表时,这很有用,例如在地图折叠问题中。如果你想评估一堆数字然后求和它们,使用 parList 进行评估,然后执行求和。



parBuffer 会计算前n个元素,当您消耗超过该元素时,它会引发下一个n,依此类推。因此,> parBuffer 在从一开始就要以区块形式使用列表时有意义 - 或者当列表非常大(或无限)时,您不会评估一切。例如,如果您想从一些昂贵的计算项目列表中找到前10个答案,则可以使用取10。使用 parBuffer 过滤f 以便从列表中并行评估连续块,直到找到要查找的前10个项目。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆