How to choose between parList and parBuffer?

I start with haskell parallelism, I have successfully learned to use some Strategies like: r0, rseq, rdeepseq, parList, parMap . Now I am looking for more opportunities to increase efficiency. So here is my question: what is the difference between parList and parBuffer ? When is each strategy effective?

+7
source share
1 answer

The document mentions both of these combinators ( here) .

parList evaluates all elements in parallel, while disabling them all. I would suggest that this is useful when you want to use the entire list at once, for example, in a problem with a brief display. If you want to evaluate a bunch of numbers, then sum them up, use parList to evaluate, then do the sum.

parBuffer evaluates the first n elements, and when you consume more than that, it sets the next n and so on. Therefore, parBuffer makes sense when you are going to use the list in pieces, starting from the very beginning, or when the list is very large (or endless) and you will not evaluate everything. For example, if you want to find the first 10 answers from some list of expensive calculations, you can use take 10 . filter f take 10 . filter f with parBuffer to evaluate consecutive snippets from the list in parallel until you find the top ten you're looking for.

+8
source

All Articles