diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-05-13 09:58:48 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-05-13 09:58:48 +0000 |
commit | 37f71ca5188ba487d4e1c274873b187ddcb30576 (patch) | |
tree | c752b450f8d5829d2eacbe94222aeab358ceb255 /examples/parallel.hs | |
parent | 6809103cf34a9345f8cb60a0ec3a8f55dd18d5ef (diff) |
removed old examples
Diffstat (limited to 'examples/parallel.hs')
-rw-r--r-- | examples/parallel.hs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs new file mode 100644 index 0000000..dfbfd88 --- /dev/null +++ b/examples/parallel.hs | |||
@@ -0,0 +1,36 @@ | |||
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 p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] | ||
9 | where ys = splitColumns p y | ||
10 | |||
11 | |||
12 | main = do | ||
13 | n <- (read . head) `fmap` getArgs | ||
14 | let m = ident n :: Matrix Double | ||
15 | time $ print $ vectorMax $ takeDiag $ m <> m | ||
16 | time $ print $ vectorMax $ takeDiag $ parMul 2 m m | ||
17 | time $ print $ vectorMax $ takeDiag $ parMul 4 m m | ||
18 | time $ print $ vectorMax $ takeDiag $ parMul 8 m m | ||
19 | |||
20 | time act = do | ||
21 | t0 <- getClockTime | ||
22 | act | ||
23 | t1 <- getClockTime | ||
24 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 | ||
25 | |||
26 | splitColumns n m = splitColumns' (f n (cols m)) m | ||
27 | where | ||
28 | splitColumns' [] m = [] | ||
29 | splitColumns' ((a,b):rest) m = subMatrix (0,a) (rows m, b-a+1) m : splitColumns' rest m | ||
30 | |||
31 | f :: Int -> Int -> [(Int,Int)] | ||
32 | f n c = zip ks (map pred $ tail ks) | ||
33 | where ks = map round $ toList $ linspace (fromIntegral n+1) (0,fromIntegral c) | ||
34 | |||
35 | splitRowsAt p m = (takeRows p m, dropRows p m) | ||
36 | splitColumnsAt p m = (takeColumns p m, dropColumns p m) | ||