14 Nov 2012 22:43
I killed performance of my code with Eval and Strategies
Janek S. <fremenzone <at> poczta.onet.pl>
2012-11-14 21:43:08 GMT
2012-11-14 21:43:08 GMT
Dear Haskellers,
I am reading Simon Marlow's tutorial on parallelism and I have problems with correctly using Eval
monad and Strategies. I *thought* I understand them but after writing some code it turns out that
obviously I don't because parallelized code is about 20 times slower. Here's a short example
(code + criterion benchmarks):
{-# LANGUAGE BangPatterns #-}
module Main where
import Control.Parallel.Strategies
import Criterion.Main
main :: IO ()
main = defaultMain [
bench "Seq" $ nf calculateSeq xs
, bench "Par" $ nf calculatePar xs ]
where xs = [1..16384]
calculateSeq :: [Double] -> [Double]
calculateSeq [] = []
calculateSeq (x:xs) = (sin . sqrt $ x) : xs
calculatePar :: [Double] -> [Double]
calculatePar xss = runEval $ go xss
where
go :: Strategy [Double]
go [] = return []
go xs = do
lsh <- (rpar `dot` rdeepseq) $ calculateSeq as
(Continue reading)
RSS Feed