Mercurial > hg > Members > toma > Jungle-haskell
annotate test/ParRead.hs @ 9:947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 21 Jan 2014 13:17:02 +0900 |
parents | f03876c8236a |
children | a30ec665df9d |
rev | line source |
---|---|
8 | 1 {-# LANGUAGE OverloadedStrings #-} |
2 | |
3 import Control.Parallel | |
4 import Control.Parallel.Strategies | |
5 import Text.Printf | |
6 import Jungle | |
7 import Data.Maybe | |
8 import Data.List | |
9 import Data.Time.Clock | |
10 import qualified Data.ByteString.Lazy.Char8 as B | |
11 import Control.Exception | |
12 import System.Environment | |
13 | |
14 | |
15 main = do | |
16 let | |
17 jungle = createJungle | |
18 new_jungle <- createTree jungle "test_tree" | |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
19 node <- getRootNode new_jungle "test_tree" |
8 | 20 let |
21 x = testTree node 7 | |
22 putStrLn $ show $ size x | |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
23 updateRootNode new_jungle "test_tree" x |
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
24 node2 <- getRootNode new_jungle "test_tree" |
8 | 25 t0 <- getCurrentTime |
26 printTimeSince t0 | |
27 r <- evaluate (runEval $ test node2) | |
28 print r | |
29 printTimeSince t0 | |
30 | |
31 | |
32 test node = do | |
33 x <- rpar (func node) | |
34 y <- rseq (func2 node) | |
35 rseq x | |
36 return (x,y) | |
37 | |
38 func :: Node -> Int | |
39 func node = size node | |
40 | |
41 func2 :: Node -> Int | |
42 func2 node = size node2 | |
43 where | |
44 node2 = addNewChildAt node [0,0] 0 | |
45 | |
46 | |
47 -- ある程度の大きさの木を作れる | |
48 -- size $ testTree y 1 = 10 | |
49 -- size $ testTree y 5 = 11742 | |
50 -- size $ testTree y 7 = 876808 | |
51 testTree node h = foldl' (add h) node (concatMap permutations . subsequences $ [0..h]) | |
52 where | |
53 add w node h = addc node h w | |
54 | |
55 addc node h w = foldl' (add h) node [0..w] | |
56 where | |
57 add h node pos = addNewChildAt node h pos | |
58 | |
59 printTimeSince t0 = do | |
60 t1 <- getCurrentTime | |
61 printf "time: %.2fs\n" (realToFrac (diffUTCTime t1 t0) :: Double) |