[Haskell-cafe] parMap doesn't work fine
Brandon Moore
brandon_m_moore at yahoo.com
Thu May 12 16:36:55 CEST 2011
> Hello!
>
> I've just started using parallel computations in Haskell. parMap works fine,
>it is so easy to use. However, parMap fails with functions returning lazy
>structures, e.g. tuples.
>
> This code works as expected:
>
> (parMap rpar) bm tvalues
Using rpar is redundant. That strategy schedules a value to maybe be computed
later in parallel, but parMap already distributed work between
cores, so you might as well use rseq or something.
> bm :: Double -> Double is some heavy function. But if I want to return list of
>pairs (t, bm t) it doesn't use cpu cores fine (only one is in use):
>
> (parMap rpar) (\t -> (t, bm t)) tvalues
That's only evaluating the pair in parallel. bm t will only be computed when you
open up the pairs afterwards.
Try rdeepseq instead.
Brandon
More information about the Haskell-Cafe
mailing list