summaryrefslogtreecommitdiff
path: root/examples/parallel.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-04 18:48:49 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-04 18:48:49 +0000
commit3017c66ca1a77b55032f75acd529347648dfc59b (patch)
tree029e6051886205079b99f03b2c00ab22f38a5fb2 /examples/parallel.hs
parentebb640befd87b956e97d5b2c854572dc1f9c11dd (diff)
parallel multiply
Diffstat (limited to 'examples/parallel.hs')
-rw-r--r--examples/parallel.hs25
1 files changed, 21 insertions, 4 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs
index 2ad686e..8f67863 100644
--- a/examples/parallel.hs
+++ b/examples/parallel.hs
@@ -1,10 +1,27 @@
1import System(getArgs) 1import System(getArgs)
2import Numeric.LinearAlgebra 2import Numeric.LinearAlgebra
3import Control.Parallel.Strategies 3import Control.Parallel.Strategies
4import System.Time
4 5
5work k = vectorMax s 6inParallel = parMap rwhnf id
6 where (_,s,_) = svd (ident k :: Matrix Double) 7
8parMul x y = fromBlocks [[ay],[by]]
9 where p = rows x `div` 2
10 a = takeRows p x
11 b = dropRows p x
12 [ay,by] = inParallel [a<>y,b<>y]
7 13
8main = do 14main = do
9 args <- (read . head) `fmap` getArgs 15 n <- (read . head) `fmap` getArgs
10 print $ sum $ parMap rnf work args \ No newline at end of file 16 let m = ident n :: Matrix Double
17 time $ print $ vectorMax $ takeDiag $ parMul m m
18 time $ print $ vectorMax $ takeDiag $ m <> m
19
20a = (2><3) [1..6::Double]
21b = (3><4) [1..12::Double]
22
23time act = do
24 t0 <- getClockTime
25 act
26 t1 <- getClockTime
27 print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0