Slowdown in concurrent program
Facundo Domínguez
facundo.dominguez at tweag.io
Wed Jan 6 18:39:40 UTC 2016
Dear devs,
The following program shows worse measures when compiled with -O
with both ghc-7.10.2 and ghc-7.8.3.
Am I hitting a known bug? Or may someone point a mistake in the code?
It also shows worse measures when using anything other than -N1.
Thanks in advance,
Facundo
-- /opt/ghc-7.8.3/bin/ghc --make -threaded -fforce-recomp test.hs
-- time ./test: 10 seconds
--
-- /opt/ghc-7.8.3/bin/ghc --make -threaded -O -fforce-recomp test.hs
-- time ./test: 48 seconds
--
-- /opt/ghc-7.10.2/bin/ghc --make -threaded -fforce-recomp test.hs
-- time ./test: 23 seconds
--
-- /opt/ghc-7.10.2/bin/ghc --make -threaded -O -fforce-recomp test.hs
-- time ./test: 57 seconds
--
import Control.Concurrent
import Control.Monad
import Data.List
main :: IO ()
main = do
let xs = [ 1 .. 400000000]
mv <- newEmptyMVar
replicateM_ 4 $ forkIO $ putMVar mv $! foldl' (+) 0 xs
nums <- replicateM 4 $ takeMVar mv
print (nums :: [Integer])
More information about the ghc-devs
mailing list