From 37f71ca5188ba487d4e1c274873b187ddcb30576 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 13 May 2009 09:58:48 +0000 Subject: removed old examples --- examples/parallel.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/parallel.hs (limited to 'examples/parallel.hs') diff --git a/examples/parallel.hs b/examples/parallel.hs new file mode 100644 index 0000000..dfbfd88 --- /dev/null +++ b/examples/parallel.hs @@ -0,0 +1,36 @@ +import System(getArgs) +import Numeric.LinearAlgebra +import Control.Parallel.Strategies +import System.Time + +inParallel = parMap rwhnf id + +parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] + where ys = splitColumns p y + + +main = do + n <- (read . head) `fmap` getArgs + let m = ident n :: Matrix Double + time $ print $ vectorMax $ takeDiag $ m <> m + time $ print $ vectorMax $ takeDiag $ parMul 2 m m + time $ print $ vectorMax $ takeDiag $ parMul 4 m m + time $ print $ vectorMax $ takeDiag $ parMul 8 m m + +time act = do + t0 <- getClockTime + act + t1 <- getClockTime + print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 + +splitColumns n m = splitColumns' (f n (cols m)) m + where + splitColumns' [] m = [] + splitColumns' ((a,b):rest) m = subMatrix (0,a) (rows m, b-a+1) m : splitColumns' rest m + + f :: Int -> Int -> [(Int,Int)] + f n c = zip ks (map pred $ tail ks) + where ks = map round $ toList $ linspace (fromIntegral n+1) (0,fromIntegral c) + +splitRowsAt p m = (takeRows p m, dropRows p m) +splitColumnsAt p m = (takeColumns p m, dropColumns p m) -- cgit v1.2.3