[Haskell-cafe] Parallel foldl doesn't work correctly
Philip Beadling
phil at beadling.co.uk
Fri Dec 11 21:57:22 EST 2009
Hi,
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
give:
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
machine).
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
missing?
If it's any use the context of the code is below.
Many thanks!
Phil.
mc :: MonteCarloUserData -> [[Double]] -> Double
mc userData rndss =
existentialResult (pfoldl f existenAvg rndss) $ numOfSims userData
where f = flip $ existentialCombine . payOff' .
expiryValue
payOff' = existentialPayOff userData
expiryValue = foldl' (existentialEvolve userData) (stock
userData)
existenAvg = averager userData
More information about the Haskell-Cafe
mailing list