parList implementation question

Marcus D. Gabriel marcus at
Fri Dec 18 13:31:03 EST 2009


In Control.Parallel.Strategies, parList is defined as

    parList strat []     = ()
    parList strat (x:xs) = strat x `par` (parList strat xs)


    parMap strat f xs = map f xs `using` parList strat.

I have recently found that if I define

    forceParMap strat f xs = map f xs `using` forceParList strat


    forceParList strat = foldl (\done -> (done>||) . strat) ()

then to date, forceParList via forceParMap gives faster results
than parList via parMap.  For example, in one experiment, parMap
with parList run at 0.81 the time of the serial solution whereas
forceParMap with forceParList run at 0.58 the time of the serial
solution.  This is to say, forceParList completed in 0.72 the
time of parList.  So,

1. Why is forceParList faster than parList?
2. Is this generic to the ghc runtime model or a particularity
   of the ghc implementation?

Thanks in advance for the clarification,
- Marcus

More information about the Libraries mailing list