[Haskell-cafe] testing par with simple program
dons at galois.com
Fri Aug 21 14:30:21 EDT 2009
> A better test program
> import Control.Parallel
> main = a `par` b `pseq` print (a + b )
> a = ack 3 11
> b = fib 39
> ack 0 n = n+1
> ack m 0 = ack (m-1) 1
> ack m n = ack (m-1) (ack m (n-1))
> fib 0 = 0
> fib 1 = 1
> fib n = fib (n-1) + fib (n-2)
> running it , these are the results
> From the resource graph and the timings it is clear that the program is not
> able to use all the 2 cores powers, considering computing 'a' alone is about 7
> seconds and 'b' alone 9.
> What is retaining the cpu's to run full power ?
Some advice on analysing parallel programs:
* Read Simon Marlow's excellent paper:
"Runtime Support for Multicore Haskell"
* Install GHC Head from 2009, it includes spark profiling.
* Never bother measuring without using -O or -O2 -- unoptimized code
is just not useful to think about.
* Compile your program:
$ ghc-6.11.20090228 -O2 --make -threaded A.hs
[1 of 1] Compiling Main ( A.hs, A.o )
Linking A ...
* Run it with +RTS -sstderr
$ ./A +RTS -N2 -sstderr
./A +RTS -N2 -sstderr
Generation 0: 12021 collections, 0 parallel, 1.33s, 1.42s elapsed
Generation 1: 2 collections, 1 parallel, 0.00s, 0.00s elapsed
Parallel GC work balance: 1.03 (426 / 414, ideal 2)
SPARKS: 1 (1 converted, 0 pruned)
Productivity 90.7% of total user, 126.4% of total elapsed
And we see 3 things:
* It did use the parallel GC : good!
* It did convert 1 spark to a thread: good!
* Productivity was greater than 100%: good!
So this looks fine!
So I suspect you're falling into the ghc 6.10.x series bug where < 3 sparks would not be converted.
Try with either 3 sparks, or using GHC 6.11.x series.
More information about the Haskell-Cafe