[Haskell-cafe] derivation of mapP, a parallel, lazy map

Dan Zwell dzwell at gmail.com
Mon Feb 25 22:49:34 EST 2008

Felipe Lessa wrote:
> On Sun, Feb 24, 2008 at 1:45 AM, Dan Zwell <dzwell at gmail.com> wrote:
>>  If anybody is curious to see this, the page is
>>  http://zwell.net/content/haskell.html#mapP . I would appreciate any
>>  criticism, too. I hope somebody finds this helpful.
> Have you seen parBuffer? I'd also recommend looking at its source.
> http://haskell.org/ghc/docs/latest/html/libraries/parallel/Control-Parallel-Strategies.html#v%3AparBuffer
Thanks. parBuffer looks more elegant than what I wrote, though it seems 
that it performs slightly slower--I assume that pattern matching (x:[]) 
versus (x:y:[]) (etc.) is faster than recursing and keeping a count of 
the number of elements left to spark. I tested this with

mapP f xs = parBuffer 2 rwhnf $ map f xs
(though I had to change the test from doing a few slow operations to 
doing many fast operations, to see any difference.)

Clearly using parBuffer would be a win on machines with lots of CPUs, 
but is there any reason that I would want to use it instead of the mapP 
I've already defined?


More information about the Haskell-Cafe mailing list