Mercurial > hg > Members > toma > Jungle-haskell
annotate test/ParWrite.hs @ 20:97d1e67aef15
add STM in Jungle map
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 24 Jan 2014 06:06:30 +0900 |
parents | 824543aea6fc |
children | 309e3474ae29 |
rev | line source |
---|---|
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 {-# LANGUAGE OverloadedStrings #-} |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 import Control.Parallel |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 import Control.Parallel.Strategies |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
5 import Control.Concurrent |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 import Text.Printf |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 import Jungle |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 import Data.Maybe |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 import Data.List |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 import Data.Time.Clock |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 import qualified Data.ByteString.Lazy.Char8 as B |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 import Control.Exception |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 import System.Environment |
18
8d4e37c1a86a
Print attrSize in ParWrite
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
14 import Control.Monad.IO.Class |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 treeId :: String |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 treeId = "test_tree" |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 treeId2 :: String |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 treeId2 = "hoge_tree" |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 treeDepth :: Int |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 treeDepth = 5 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 lastPos :: [Int] |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 lastPos = last $ concatMap permutations . subsequences $ [0..treeDepth] |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 writeCount :: Int |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 writeCount = 100000 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 main = do |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 jungle <- createTree createJungle treeId |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 jungle <- createTree jungle treeId2 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 node <- getRootNode jungle treeId |
18
8d4e37c1a86a
Print attrSize in ParWrite
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
36 node2 <- getRootNode jungle treeId2 |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 let |
15 | 38 miniTree = testTree node treeDepth |
39 miniTree2 = testTree node2 treeDepth | |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 updateRootNode jungle treeId miniTree |
15 | 42 updateRootNode jungle treeId2 miniTree2 |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 putStrLn $ show $ size miniTree |
15 | 45 putStrLn $ show $ size miniTree2 |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 t0 <- getCurrentTime |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 printTimeSince t0 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
50 forkIO (func jungle treeId) |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
51 func jungle treeId2 |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 printTimeSince t0 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 -- parallel write for two trees by singleWrite |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 dualWrite jungle = do |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
57 x <- rpar (func jungle treeId) |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
58 y <- rpar (func jungle treeId2) |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
59 return (x, y) |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
61 func jungle id = do |
16 | 62 updateRootNodeWith (writeFunctions writeCount) jungle id |
63 tree <- getRootNode jungle id | |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
18
diff
changeset
|
64 liftIO $ print (show $ attrSize tree) |
16 | 65 |
15 | 66 -- generate functions to node update |
67 writeFunctions :: Int -> Node -> Node | |
18
8d4e37c1a86a
Print attrSize in ParWrite
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
16
diff
changeset
|
68 writeFunctions writeCount node = foldl' apply node [0..writeCount] |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 where |
15 | 70 apply node x = putAttribute node lastPos (show x) (B.pack . show $ x) |
12
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 -- utils from ParRead |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 testTree node h = foldl' (add h) node (concatMap permutations . subsequences $ [0..h]) |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 where |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 add w node h = addc node h w |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 addc node h w = foldl' (add h) node [0..w] |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 where |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 add h node pos = addNewChildAt node h pos |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 printTimeSince t0 = do |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 t1 <- getCurrentTime |
d6e95f88cda9
Write test script for check time to parallel write.
Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 printf "time: %.2fs\n" (realToFrac (diffUTCTime t1 t0) :: Double) |