Problem getting code from AFP08 parallel tutorial to run in parallel

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.

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. -- 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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Nov 25, 2008 at 3:07 PM, Simon Marlow
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.
Yes, I tried it with 3 sparks and it works, Thanks for your help, Olivier.

olivier.boudry:
On Tue, Nov 25, 2008 at 3:07 PM, Simon Marlow
wrote: 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.
Yes, I tried it with 3 sparks and it works,
Thanks for your help,
What does the code look like? Simon : should we be start to try tthe HEAD for par stuff? -- Don

Don Stewart wrote:
olivier.boudry:
On Tue, Nov 25, 2008 at 3:07 PM, Simon Marlow
wrote: 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. Yes, I tried it with 3 sparks and it works,
Thanks for your help,
What does the code look like?
Simon : should we be start to try tthe HEAD for par stuff?
Please do - also I'm on the lookout for good benchmarks to add to nofib/parallel. Particularly programs that you think should speed up in parallel but don't - sometimes that helps us find bottlenecks in the runtime. Cheers, Simon

On Tue, Nov 25, 2008 at 11:07 PM, Don Stewart
What does the code look like?
It looks like that. Of course it doesn't compute the same number as the initial code, but it starts 3 sparks and I get the expected 100% CPU usage instead of 50%. parSumFibEuler :: Int -> Int -> Int -> Int parSumFibEuler a b c = f `par` (e `par` (g `pseq` (f + e + g))) where f = fib a e = sumEuler b g = sumEuler c r1 :: Int r1 = parSumFibEuler 40 7450 7449 Instead of: parSumFibEuler :: Int -> Int -> Int parSumFibEuler a b = f `par` (e `pseq` (f + e)) where f = fib a e = sumEuler b r1 :: Int r1 = parSumFibEuler 40 7450 Olivier.
participants (3)
-
Don Stewart
-
Olivier Boudry
-
Simon Marlow