Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose between parList and parBuffer?

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 ?

like image 305
Fopa Léon Constantin Avatar asked Mar 18 '11 13:03

Fopa Léon Constantin


1 Answers

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.

like image 173
Neil Brown Avatar answered Sep 27 '22 23:09

Neil Brown