summaryrefslogtreecommitdiff
path: root/examples/parallel.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-05-13 09:58:48 +0000
committerAlberto Ruiz <aruiz@um.es>2009-05-13 09:58:48 +0000
commit37f71ca5188ba487d4e1c274873b187ddcb30576 (patch)
treec752b450f8d5829d2eacbe94222aeab358ceb255 /examples/parallel.hs
parent6809103cf34a9345f8cb60a0ec3a8f55dd18d5ef (diff)
removed old examples
Diffstat (limited to 'examples/parallel.hs')
-rw-r--r--examples/parallel.hs36
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 @@
1import System(getArgs)
2import Numeric.LinearAlgebra
3import Control.Parallel.Strategies
4import System.Time
5
6inParallel = parMap rwhnf id
7
8parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ]
9 where ys = splitColumns p y
10
11
12main = 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
20time act = do
21 t0 <- getClockTime
22 act
23 t1 <- getClockTime
24 print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0
25
26splitColumns 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
35splitRowsAt p m = (takeRows p m, dropRows p m)
36splitColumnsAt p m = (takeColumns p m, dropColumns p m)