parList implementation question

Marcus D. Gabriel marcus at gabriel.name
Mon Dec 21 13:01:18 EST 2009


Thanks Simon.  Parallel 2.2.0.1 was straight forward.  I just replaced rnf
with rdeepseq and my original use of parMap worked like a charm giving
twice the performance for my dual-core system as I original expected and
now find.

Thanks,
- Marcus

Marcus D. Gabriel wrote:
> Thank you Simon, I will obtain parallel 2.2.0.1 and work with it.
> Actually, the reason I asked my question was because I did not
> think forceParList should yield better performance than parList
> (unless it was becasue of the foldl?).
>
> I read the release notes for 6.12.1 about the work done on the ghc
> parallel framework and did just a little bit more experimenting.
> You might find this of interesting.
>
> ghc 6.10.4 with parallel 1.1.0.1 (as reported before):
>     Serial algorithm:                        1.00 unit of time
>     Parallel algorithm with parList:         0.81 units of time
>     Parallel algorithm with forceParList:    0.58 units of time
>
> ghc 6.12.1 with parallel 1.1.0.1:
>     Serial algorithm:                        1.00 unit of time
>     Parallel algorithm with parList:         0.58 units of time*
>     Parallel algorithm with forceParList:    0.58 units of time*
>
> Interesting.  Well, from my perspective, 6.12.1 is certainly an
> improvement here.
>
> Cheers,
> - Marcus
>  
> Simon Marlow wrote:
>   
>> On 18/12/2009 18:31, Marcus D. Gabriel wrote:
>>     
>>> Hello,
>>>
>>> In Control.Parallel.Strategies, parList is defined as
>>>
>>>      parList strat []     = ()
>>>      parList strat (x:xs) = strat x `par` (parList strat xs)
>>>
>>> with
>>>
>>>      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
>>>
>>> where
>>>
>>>      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?
>>>       
>> I'm not sure.  Your forceParList looks equivalent to parList, unless
>> I'm misreading it.
>>
>> I recommend trying out the new parallel package, here:
>>
>>   http://hackage.haskell.org/package/parallel
>>
>> which has a new implementation of Strategies.  The version of parList
>> you quoted above has a space leak problem which may be affecting your
>> results.
>>
>> Cheers,
>>     Simon
>>     



More information about the Glasgow-haskell-users mailing list