diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-10-04 18:48:49 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-10-04 18:48:49 +0000 |
commit | 3017c66ca1a77b55032f75acd529347648dfc59b (patch) | |
tree | 029e6051886205079b99f03b2c00ab22f38a5fb2 /examples/parallel.hs | |
parent | ebb640befd87b956e97d5b2c854572dc1f9c11dd (diff) |
parallel multiply
Diffstat (limited to 'examples/parallel.hs')
-rw-r--r-- | examples/parallel.hs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs index 2ad686e..8f67863 100644 --- a/examples/parallel.hs +++ b/examples/parallel.hs | |||
@@ -1,10 +1,27 @@ | |||
1 | import System(getArgs) | 1 | import System(getArgs) |
2 | import Numeric.LinearAlgebra | 2 | import Numeric.LinearAlgebra |
3 | import Control.Parallel.Strategies | 3 | import Control.Parallel.Strategies |
4 | import System.Time | ||
4 | 5 | ||
5 | work k = vectorMax s | 6 | inParallel = parMap rwhnf id |
6 | where (_,s,_) = svd (ident k :: Matrix Double) | 7 | |
8 | parMul x y = fromBlocks [[ay],[by]] | ||
9 | where p = rows x `div` 2 | ||
10 | a = takeRows p x | ||
11 | b = dropRows p x | ||
12 | [ay,by] = inParallel [a<>y,b<>y] | ||
7 | 13 | ||
8 | main = do | 14 | main = do |
9 | args <- (read . head) `fmap` getArgs | 15 | n <- (read . head) `fmap` getArgs |
10 | print $ sum $ parMap rnf work args \ No newline at end of file | 16 | let m = ident n :: Matrix Double |
17 | time $ print $ vectorMax $ takeDiag $ parMul m m | ||
18 | time $ print $ vectorMax $ takeDiag $ m <> m | ||
19 | |||
20 | a = (2><3) [1..6::Double] | ||
21 | b = (3><4) [1..12::Double] | ||
22 | |||
23 | time act = do | ||
24 | t0 <- getClockTime | ||
25 | act | ||
26 | t1 <- getClockTime | ||
27 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 | ||