diff options
Diffstat (limited to 'examples/experiments/parallel.hs')
-rw-r--r-- | examples/experiments/parallel.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/experiments/parallel.hs b/examples/experiments/parallel.hs new file mode 100644 index 0000000..7256fb6 --- /dev/null +++ b/examples/experiments/parallel.hs | |||
@@ -0,0 +1,28 @@ | |||
1 | import System(getArgs) | ||
2 | import Numeric.LinearAlgebra | ||
3 | import Control.Parallel.Strategies | ||
4 | import System.Time | ||
5 | |||
6 | inParallel = parMap rwhnf id | ||
7 | |||
8 | parMul x y = fromBlocks [inParallel[x <> y1, x <> y2]] | ||
9 | where p = cols y `div` 2 | ||
10 | (y1,y2) = splitColumnsAt p y | ||
11 | |||
12 | main = do | ||
13 | n <- (read . head) `fmap` getArgs | ||
14 | let m = ident n :: Matrix Double | ||
15 | time $ print $ vectorMax $ takeDiag $ parMul m m | ||
16 | time $ print $ vectorMax $ takeDiag $ m <> m | ||
17 | |||
18 | a = (2><3) [1..6::Double] | ||
19 | b = (3><4) [1..12::Double] | ||
20 | |||
21 | splitRowsAt p m = (takeRows p m, dropRows p m) | ||
22 | splitColumnsAt p m = (takeColumns p m, dropColumns p m) | ||
23 | |||
24 | time act = do | ||
25 | t0 <- getClockTime | ||
26 | act | ||
27 | t1 <- getClockTime | ||
28 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 | ||