diff options
Diffstat (limited to 'examples')
-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 | ||