Mercurial > hg > Members > toma > Jungle-haskell
view test/ParRead.hs @ 8:f03876c8236a
add ParRead
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 14 Jan 2014 18:09:51 +0900 |
parents | |
children | 947c5cfa4149 |
line wrap: on
line source
{-# LANGUAGE OverloadedStrings #-} import Control.Parallel import Control.Parallel.Strategies import Text.Printf import Jungle import Data.Maybe import Data.List import Data.Time.Clock import qualified Data.ByteString.Lazy.Char8 as B import Control.Exception import System.Environment main = do let jungle = createJungle new_jungle <- createTree jungle "test_tree" let tree = fromJust $ getTreeByName new_jungle "test_tree" node <- getRootNode tree let x = testTree node 7 putStrLn $ show $ size x updateRootNode tree x node2 <- getRootNode tree t0 <- getCurrentTime printTimeSince t0 r <- evaluate (runEval $ test node2) print r printTimeSince t0 test node = do x <- rpar (func node) y <- rseq (func2 node) rseq x return (x,y) func :: Node -> Int func node = size node func2 :: Node -> Int func2 node = size node2 where node2 = addNewChildAt node [0,0] 0 -- ある程度の大きさの木を作れる -- size $ testTree y 1 = 10 -- size $ testTree y 5 = 11742 -- size $ testTree y 7 = 876808 testTree node h = foldl' (add h) node (concatMap permutations . subsequences $ [0..h]) where add w node h = addc node h w addc node h w = foldl' (add h) node [0..w] where add h node pos = addNewChildAt node h pos printTimeSince t0 = do t1 <- getCurrentTime printf "time: %.2fs\n" (realToFrac (diffUTCTime t1 t0) :: Double)