News

I’m excited about GHC 6.12 and hope it is released soon. Currently I have some problems with Ubuntu 9.10 and its Linux kernel 2.6.31-14. It seems that GHC 6.12 will solve (some) of my problems.

For the examplary unoptimized code

-- Compile with ghc-6.10.4 -O2 -threaded --make Example.hs -o example
module Main where
import GHC.Conc
import Control.Concurrent
import Control.Monad
import System.Environment
import Data.List
------------------------------------------------------------
main :: IO ()
main = do
    args <- getArgs
    let threads = numCapabilities    -- threads determined by -N...
        taskDur = 1000000            -- big enough magic number
        taskNum = (read . head) args -- Number of tasks is 1st parameter
 
    queue    <- newChan
    finished <- newChan
    writeList2Chan queue (replicate taskNum taskDur)
    replicateM_ threads (forkIO (thread queue finished))
    replicateM_ taskNum (readChan finished)
------------------------------------------------------------
thread :: Chan Int -> Chan Int -> IO ()
thread queue finished =
    forever $ do
        task <- readChan queue
        workFor task
        writeChan finished 1
  where workFor n = foldl' (\a b -> a + sqrt (2^b)) 1 [1..n] `pseq`
           return ()

we get the following runtimes on my Dualcore Notebook:

$ time e-6.12 +RTS -N1 -RTS 16

real	0m43.994s
user	0m43.630s
sys	0m0.040s
$ time e-6.12 +RTS -N2 -RTS 16

real	0m25.987s
user	0m48.790s
sys	0m0.230s
$ time e-6.10 +RTS -N1 -RTS 16

real	0m45.883s
user	0m44.500s
sys	0m0.400s
$ time e-6.10 +RTS -N2 -RTS 16

real	0m38.930s
user	0m46.040s
sys	0m0.490s

As you can see, e-6.12 (the version compiled with ghc-6.12-20091010) delivers a good speedup whereas ghc-6.10 does not use my two cores very much. This makes testing, benchmarking and developing my parallel Haskell code currently quite difficult.


Leave a Reply