module Main where import System.Environment import Control.Parallel.Eden import Control.Parallel.Eden.MapReduce -- import MapRedSkels import Control.Parallel.Eden.Auxiliary -- import MapSkels -- import Auxiliary main :: IO () main = getArgs >>= \ (n:_) -> putStrLn $ show (cpi (read n)) -- compute pi using integration cpi :: Integer -> Double cpi n = offlineParMapRedr (+) 0 (f.index) [1..n] / fromInteger n where f :: Double -> Double f x = 4 / (1 + x*x) index :: Integer -> Double index i = (fromInteger i - 0.5) / fromInteger n -- test n = mapFarmS (f.index) [1..n] {- parMapRed :: (Trans a, Trans b) => (b -> b -> b) -> b -> (a -> b) -> [a] -> b parMapRed g e f = if noPe == 1 then mapRed g e f else oFarm (splitIntoN noPe) (foldr g e) (mapRed g e f) oFarm :: (Trans a, Trans b) => (t -> [a]) -> ([b] -> c) -> (a -> b) -> t -> c oFarm distribute combine f xs = combine $ parMap (\ i -> f ((distribute xs)!!i)) [0..noPe-1] newtype LBox a = LBox {unLBox :: a} instance Trans a => Trans (LBox a) instance NFData a => NFData (LBox a) parMapRed2 :: (Trans a, Trans b) => (b -> b -> b) -> b -> (a -> b) -> [a] -> b parMapRed2 g e f = if noPe == 1 then mapRed g e f else (foldr g e) . (parMap (mapRed g e f)) . (splitIntoN noPe) parMapRed3 :: (Trans a, Trans b) => (b -> b -> b) -> b -> (a -> b) -> [a] -> b parMapRed3 g e f xs = if noPe == 1 then mapRed g e f xs else foldr g e $ parMap (\ i -> mapRed g e f (splitIntoN noPe xs!!i)) [0..noPe-1] mapRed :: (b -> c -> c) -> c -> (a -> b) -> [a] -> c mapRed g e f = (foldr g e) . (map f) -}