summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2008-06-06 12:08:01 +0000
committerAlberto Ruiz <aruiz@um.es>2008-06-06 12:08:01 +0000
commitfa7d2f17cbba1de2e900432e07bf4e1e7da2caab (patch)
treefb910d7f2ff1176701d7a04cbe96fb46ffb8e94f /examples
parent4576f9c288b0f9cc48c2c4eff68ad8403b4fa4e0 (diff)
safe wrappers and examples/parallel.hs
Diffstat (limited to 'examples')
-rw-r--r--examples/experiments/parallel.hs28
1 files changed, 18 insertions, 10 deletions
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
5 5
6inParallel = parMap rwhnf id 6inParallel = parMap rwhnf id
7 7
8parMul x y = fromBlocks [inParallel[x <> y1, x <> y2]] 8parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ]
9 where p = cols y `div` 2 9 where ys = splitColumns p y
10 (y1,y2) = splitColumnsAt p y 10
11 11
12main = do 12main = do
13 n <- (read . head) `fmap` getArgs 13 n <- (read . head) `fmap` getArgs
14 let m = ident n :: Matrix Double 14 let m = ident n :: Matrix Double
15 time $ print $ vectorMax $ takeDiag $ parMul m m
16 time $ print $ vectorMax $ takeDiag $ m <> m 15 time $ print $ vectorMax $ takeDiag $ m <> m
17 16 time $ print $ vectorMax $ takeDiag $ parMul 2 m m
18a = (2><3) [1..6::Double] 17 time $ print $ vectorMax $ takeDiag $ parMul 4 m m
19b = (3><4) [1..12::Double] 18 time $ print $ vectorMax $ takeDiag $ parMul 8 m m
20
21splitRowsAt p m = (takeRows p m, dropRows p m)
22splitColumnsAt p m = (takeColumns p m, dropColumns p m)
23 19
24time act = do 20time act = do
25 t0 <- getClockTime 21 t0 <- getClockTime
26 act 22 act
27 t1 <- getClockTime 23 t1 <- getClockTime
28 print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 24 print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0
25
26splitColumns n m = splitColumns' (f n (cols m)) m
27 where
28 splitColumns' [] m = []
29 splitColumns' ((a,b):rest) m = subMatrix (0,a) (rows m, b-a+1) m : splitColumns' rest m
30
31 f :: Int -> Int -> [(Int,Int)]
32 f n c = zip ks (map pred $ tail ks)
33 where ks = map round $ toList $ linspace (fromIntegral n+1) (0,fromIntegral c)
34
35splitRowsAt p m = (takeRows p m, dropRows p m)
36splitColumnsAt p m = (takeColumns p m, dropColumns p m)