view test/ParWrite2.hs @ 24:278bd0dcec51

add Makefile for test
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Mon, 03 Feb 2014 19:35:08 +0900
parents 309e3474ae29
children
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
import System.IO.Unsafe

treeDepth = 6

main = do
  jungle <- createJungle
  createTree jungle "test_tree"
  node <- getRootNode jungle "test_tree"
  let
    x = testTree node treeDepth
    size_x = size x
  putStrLn $ show $ size_x
  updateRootNode jungle "test_tree" x
  t0 <- getCurrentTime
  printTimeSince t0
  let result = map (func jungle) [1..1000] `using` parList rseq
  print (length (filter (== size_x) result))
  printTimeSince t0


func jungle num = unsafePerformIO $ do 
  createTree jungle name
  node <- getRootNode jungle name
  let
    x = testTree node treeDepth
  updateRootNode jungle name x
  return (size x)
  where 
    name = show num


-- ある程度の大きさの木を作れる
-- 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)