9 Nov 2012 16:52
Waiting for garbage collection can kill parallelism?
Janek S. <fremenzone <at> poczta.onet.pl>
2012-11-09 15:52:37 GMT
2012-11-09 15:52:37 GMT
Today I was reading "Parallel Performance Tuning for Haskell" by Jones, Marlow and Singh and
wanted to replicate the results for their first case study. The code goes like this:
module Main where
import Control.Parallel
main :: IO ()
main = print . parSumFibEuler 38 $ 5300
parSumFibEuler :: Int -> Int -> Int
parSumFibEuler a b = f `par` (e `pseq` (e + f))
where f = fib a
e = sumEuler b
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
mkList :: Int -> [Int]
mkList n = [1..n-1]
relprime :: Int -> Int -> Bool
relprime x y = gcd x y == 1
euler :: Int -> Int
euler n = length (filter (relprime n) (mkList n))
sumEuler :: Int -> Int
sumEuler = sum . (map euler) . mkList
(Continue reading)
RSS Feed