[Haskell-cafe] Parallel foldl doesn't work correctly

Philip Beadling phil at beadling.co.uk
Fri Dec 11 21:57:22 EST 2009


Can anyone put me right here.  I am trying to use a setup similar to
parMap to spark each valuation in a list in parallel, where the
resulting (evaluated) list is folded to produce a final single result.

Having done the obligatory google, I modified a few common examples to

pfoldl f acc xs =  foldl' f acc (xs `using` parList rwhnf)

This compiles and if I monitor my CPUs it starts to use both cores, but
after approx 10 seconds, one core drops to low rate (I'm using a 2 core

The end result is that -N2 is actually a bit slower than -N1!

I'm guessing I haven't grasped the concept properly - although as map is
just 'foldl (+) 0' I'm at a loss to see why this approach wouldn't work
given it is pretty similar to parMap - could anyone point out what I'm

If it's any use the context of the code is below.

Many thanks!


mc :: MonteCarloUserData -> [[Double]] -> Double
mc userData rndss = 
  existentialResult (pfoldl f existenAvg rndss) $ numOfSims userData
    where f           = flip $ existentialCombine . payOff' .
          payOff'     = existentialPayOff userData
          expiryValue = foldl' (existentialEvolve userData) (stock
          existenAvg  = averager userData

More information about the Haskell-Cafe mailing list