From fa7d2f17cbba1de2e900432e07bf4e1e7da2caab Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 6 Jun 2008 12:08:01 +0000 Subject: safe wrappers and examples/parallel.hs --- examples/experiments/parallel.hs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/experiments/parallel.hs b/examples/experiments/parallel.hs index 7256fb6..dfbfd88 100644 --- a/examples/experiments/parallel.hs +++ b/examples/experiments/parallel.hs @@ -5,24 +5,32 @@ import System.Time inParallel = parMap rwhnf id -parMul x y = fromBlocks [inParallel[x <> y1, x <> y2]] - where p = cols y `div` 2 - (y1,y2) = splitColumnsAt p y +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 $ parMul m m time $ print $ vectorMax $ takeDiag $ m <> m - -a = (2><3) [1..6::Double] -b = (3><4) [1..12::Double] - -splitRowsAt p m = (takeRows p m, dropRows p m) -splitColumnsAt p m = (takeColumns p m, dropColumns p 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