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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With