Mercurial > hg > Members > toma > Jungle-haskell
view test/ParRead.hs @ 21:451bf8dcdc9c
using parList
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 24 Jan 2014 09:50:27 +0900 |
parents | 97d1e67aef15 |
children | efb4e880ac7f |
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 jungle <- createJungle createTree jungle "test_tree" node <- getRootNode jungle "test_tree" let x = testTree node 8 size_x = size x putStrLn $ show $ size_x updateRootNode jungle "test_tree" x node2 <- getRootNode jungle "test_tree" t0 <- getCurrentTime printTimeSince t0 let result = map (func node2) [1..1000] `using` parList rseq print (length (filter (> size_x) result)) printTimeSince t0 func node num = size (addc c node [1,1]) where c = num `mod` 5 -- ある程度の大きさの木を作れる -- size $ testTree y 2 = 10 -- size $ testTree y 6 = 11742 -- size $ testTree y 8 = 876808 testTree node h = foldl' (add (h-1)) node (concatMap permutations . subsequences $ [1..h]) where add x node h = addc x node h -- x回addNewChildAtする addc 0 node h = addNewChildAt node h addc x node h = addNewChildAt (addc (x-1) node h) h printTimeSince t0 = do t1 <- getCurrentTime printf "time: %.2fs\n" (realToFrac (diffUTCTime t1 t0) :: Double)