diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-21 10:30:55 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-21 10:30:55 +0200 |
commit | 197e88c3b56d28840217010a2871c6ea3a4dd1a4 (patch) | |
tree | 825be9d6c9d87d23f7e5497c0133d11d52c63535 /examples/parallel.hs | |
parent | e07c3dee7235496b71a89233106d93f6cc94ada1 (diff) |
update dependencies, move examples etc
Diffstat (limited to 'examples/parallel.hs')
-rw-r--r-- | examples/parallel.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs new file mode 100644 index 0000000..e875407 --- /dev/null +++ b/examples/parallel.hs | |||
@@ -0,0 +1,28 @@ | |||
1 | -- $ ghc --make -O -rtsopts -threaded parallel.hs | ||
2 | -- $ ./parallel 3000 +RTS -N4 -s -A200M | ||
3 | |||
4 | import System.Environment(getArgs) | ||
5 | import Numeric.LinearAlgebra | ||
6 | import Control.Parallel.Strategies | ||
7 | import System.Time | ||
8 | |||
9 | inParallel = parMap rwhnf id | ||
10 | |||
11 | -- matrix product decomposed into p parallel subtasks | ||
12 | parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] | ||
13 | where [ys] = toBlocksEvery (rows y) (cols y `div` p) y | ||
14 | |||
15 | main = do | ||
16 | n <- (read . head) `fmap` getArgs | ||
17 | let m = ident n :: Matrix Double | ||
18 | time $ print $ maxElement $ takeDiag $ m <> m | ||
19 | time $ print $ maxElement $ takeDiag $ parMul 2 m m | ||
20 | time $ print $ maxElement $ takeDiag $ parMul 4 m m | ||
21 | time $ print $ maxElement $ takeDiag $ parMul 8 m m | ||
22 | |||
23 | time act = do | ||
24 | t0 <- getClockTime | ||
25 | act | ||
26 | t1 <- getClockTime | ||
27 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 | ||
28 | |||