# parList implementation question

Marcus D. Gabriel marcus at gabriel.name
Mon Dec 21 11:43:43 EST 2009

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 recommend trying out the new parallel package, here:
>