[Haskell-cafe] Re: Problem getting code from AFP08 parallel
tutorial to run in parallel
Simon Marlow
marlowsd at gmail.com
Tue Nov 25 09:07:48 EST 2008
Don Stewart wrote:
> Which version of GHC are you using?
>
> This particular example triggers a "boundary condition" in ghc 6.10
> where, with only one spark, GHC doesn't fire up the extra cpu. Try it
> with 6.8.x to see that in action.
>
> Simon Marlow may be able to comment more.
Yes, it's a scheduling bug. I'll make sure it gets fixed for 6.10.2. If
you have more sparks then you shouldn't see this problem. Also, GHC HEAD
is quite a lot better with parallel programs than 6.10.1, I'll try to get
around to posting some figures sometime.
Cheers,
Simon
> -- Don
>
> olivier.boudry:
>> Hi all,
>>
>> I'm reading the following tutorial:
>> http://research.microsoft.com/~simonpj/papers/parallel/AFP08-notes.pdf
>> "A Tutorial on Parallel and Concurrent
>> Programming in Haskell" and have problems getting the expected speed
>> improvement from running two tasks in parallel. With any version of
>> the code present in pages 1-7 of the tutorial I keep getting the CPU
>> stick to 50%.
>>
>> I did not forget to compile the code with `-threaded` and run it with
>> `+RTS -N2` and it runs on a dual core machine on which I already used
>> the Control.Parallel.Strategies.parMap function and got 100% CPU
>> usage.
>>
>> The first version of the parallel function in the tutorial (page 6) is:
>>
>> parSumFibEuler :: Int −> Int −> Int
>> parSumFibEuler a b
>> = f 'par' (f + e)
>> where
>> f = fib a
>> e = sumEuler b
>>
>> In the tutorial, swapping f and e on the 3rd line does the job, but in
>> my case it doesn't change anything.
>>
>> C:\Temp\haskell>ghc --make -threaded SumEulerP6.hs
>> [1 of 1] Compiling Main ( SumEulerP6.hs, SumEulerP6.o )
>> Linking SumEulerP6.exe ...
>>
>> C:\Temp\haskell>SumEulerP6 +RTS -N1
>> sum: 119201850
>> time: 36.890625 seconds
>>
>> C:\Temp\haskell>SumEulerP6 +RTS -N2
>> sum: 119201850
>> time: 36.859375 seconds
>>
>> Next page of the tutorial the tasks are explicitly sequenced so the
>> code does not depend on the ordering of the two `+` operands:
>>
>> parSumFibEuler :: Int -> Int -> Int
>> parSumFibEuler a b
>> = f `par` (e `pseq` (f + e))
>> where
>> f = fib a
>> e = sumEuler b
>>
>> With once again a disappointing result:
>>
>> C:\Temp\haskell>ghc --make -threaded SumEulerP7.hs
>> [1 of 1] Compiling Main ( SumEulerP7.hs, SumEulerP7.o )
>> Linking SumEulerP7.exe ...
>>
>> C:\Temp\haskell>SumEulerP7 +RTS -N1
>> sum: 119201850
>> time: 36.875 seconds
>>
>> C:\Temp\haskell>SumEulerP7 +RTS -N2
>> sum: 119201850
>> time: 36.75 seconds
>>
>> I tried this on a Windows XP Dell Dual Core with GHC 6.10.1 and on a
>> iMac Dual Core with GHC 6.8.3 and got the same result on both. I'm
>> probably missing something really stupid but I'm lacking the "parallel
>> thinking" skills to understand how to look at the problem and resolve
>> it.
>>
>> Any pointers?
>>
>> Thanks,
>>
>> Olivier.
>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list