diff options
author | Alberto Ruiz <aruiz@um.es> | 2008-06-06 12:08:01 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2008-06-06 12:08:01 +0000 |
commit | fa7d2f17cbba1de2e900432e07bf4e1e7da2caab (patch) | |
tree | fb910d7f2ff1176701d7a04cbe96fb46ffb8e94f /examples | |
parent | 4576f9c288b0f9cc48c2c4eff68ad8403b4fa4e0 (diff) |
safe wrappers and examples/parallel.hs
Diffstat (limited to 'examples')
-rw-r--r-- | examples/experiments/parallel.hs | 28 |
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 | ||
6 | inParallel = parMap rwhnf id | 6 | inParallel = parMap rwhnf id |
7 | 7 | ||
8 | parMul x y = fromBlocks [inParallel[x <> y1, x <> y2]] | 8 | parMul 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 | ||
12 | main = do | 12 | main = 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 | |
18 | a = (2><3) [1..6::Double] | 17 | time $ print $ vectorMax $ takeDiag $ parMul 4 m m |
19 | b = (3><4) [1..12::Double] | 18 | time $ print $ vectorMax $ takeDiag $ parMul 8 m m |
20 | |||
21 | splitRowsAt p m = (takeRows p m, dropRows p m) | ||
22 | splitColumnsAt p m = (takeColumns p m, dropColumns p m) | ||
23 | 19 | ||
24 | time act = do | 20 | time 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 | |||
26 | splitColumns 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 | |||
35 | splitRowsAt p m = (takeRows p m, dropRows p m) | ||
36 | splitColumnsAt p m = (takeColumns p m, dropColumns p m) | ||