diff options
Diffstat (limited to 'packages/hmatrix/examples/parallel.hs')
-rw-r--r-- | packages/hmatrix/examples/parallel.hs | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/packages/hmatrix/examples/parallel.hs b/packages/hmatrix/examples/parallel.hs deleted file mode 100644 index e875407..0000000 --- a/packages/hmatrix/examples/parallel.hs +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
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 | |||