[Haskell-beginners] Performance of parallel mergesort

Jon Harrop jon at ffconsultancy.com
Wed Dec 23 16:14:24 EST 2009

I took the parallel merge sort described here:


and added a simple test:

main :: IO ()
main = do
    putStrLn $ show $ sum $ mergesort $ [sin x | x <- [1.0 .. 1000000.0]]

Compiled it with GHC 6.8.2 from Debian testing and ran it with various 
+RTS -N<n> arguments to measure its performance and obtained the following 
results on an 8 core:

$ ghc --make -O2 -threaded mergesort.hs -o mergesort
[1 of 1] Compiling Main             ( mergesort.hs, mergesort.o )
Linking mergesort ...
$ time ./mergesort +RTS -N1

real    0m9.723s
user    0m9.461s
sys     0m0.232s
$ time ./mergesort +RTS -N2

real    0m13.574s
user    0m15.225s
sys     0m0.140s
$ time ./mergesort +RTS -N3

real    0m13.185s
user    0m15.529s
sys     0m0.184s
$ time ./mergesort +RTS -N4

real    0m13.251s
user    0m15.829s
sys     0m0.336s
$ time ./mergesort +RTS -N5

real    0m13.093s
user    0m16.929s
sys     0m0.164s
$ time ./mergesort +RTS -N6
Segmentation fault

real    0m5.711s
user    0m7.408s
sys     0m0.136s

That segfault must be due to a bug in GHC so I thought perhaps a newer version 
of GHC might fix the segfault but I installed GHC 6.10.4 from Sid and now I 

$ ghc --make -O2 -threaded mergesort.hs -o mergesort
Binary: Int64 truncated to fit in 32 bit Int
ghc: panic! (the 'impossible' happened)
  (GHC version 6.10.4 for i386-unknown-linux):
        Prelude.chr: bad argument

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

I'll try the haskell-platform package next. Are these known problems?

Dr Jon Harrop, Flying Frog Consultancy Ltd.

More information about the Beginners mailing list