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.