diff options
-rw-r--r-- | README | 28 | ||||
-rw-r--r-- | examples/parallel.hs | 25 |
2 files changed, 41 insertions, 12 deletions
@@ -10,10 +10,10 @@ INSTALLATION | |||
10 | (More detailed information is included in the "tutorial", | 10 | (More detailed information is included in the "tutorial", |
11 | available in the web page of the project.) | 11 | available in the web page of the project.) |
12 | 12 | ||
13 | $ runhaskell Setup.hs configure --prefix=$HOME | 13 | $ runhaskell Setup.lhs configure --prefix=$HOME |
14 | $ runhaskell Setup.hs build | 14 | $ runhaskell Setup.lhs build |
15 | $ runhaskell Setup.hs haddock | 15 | $ runhaskell Setup.lhs haddock |
16 | $ runhaskell Setup.hs install --user | 16 | $ runhaskell Setup.lhs install --user |
17 | 17 | ||
18 | USING ATLAS | 18 | USING ATLAS |
19 | 19 | ||
@@ -27,11 +27,23 @@ $ runhaskell examples/tests.hs | |||
27 | EXAMPLES | 27 | EXAMPLES |
28 | 28 | ||
29 | $ ghci | 29 | $ ghci |
30 | Prelude> :m + GSL | 30 | Prelude> :m + Numeric.GSL |
31 | Prelude GSL> let quad = integrateQNG 1E-10 | 31 | Prelude Numeric.GSL> let quad = integrateQNG 1E-10 |
32 | Prelude GSL> quad (^2) 0 1 | 32 | Prelude Numeric.GSL> quad (^2) 0 1 |
33 | (0.3333333333333333,3.700743415417188e-15) | 33 | (0.3333333333333333,3.700743415417188e-15) |
34 | Prelude GSL> :q | 34 | |
35 | Prelude Numeric.GSL> :m + Numeric.LinearAlgebra | ||
36 | Prelude Numeric.LinearAlgebra> let m = (2><3)[1,2,3,4,5,6::Double] | ||
37 | Prelude Numeric.LinearAlgebra> let (u,d,v) = full svd m | ||
38 | Prelude Numeric.LinearAlgebra> d | ||
39 | (2><3) | ||
40 | [ 9.508032000695724, 0.0, 0.0 | ||
41 | , 0.0, 0.7728696356734838, 0.0 ] | ||
42 | Prelude Numeric.LinearAlgebra> u <> d <> trans v | ||
43 | (2><3) | ||
44 | [ 1.0000000000000004, 2.0, 3.0 | ||
45 | , 3.9999999999999996, 5.000000000000001, 6.0 ] | ||
46 | Prelude Numeric.GSL> :q | ||
35 | Leaving GHCi. | 47 | Leaving GHCi. |
36 | 48 | ||
37 | -------------------------------------------------------------------------------------- | 49 | -------------------------------------------------------------------------------------- |
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 @@ | |||
1 | import System(getArgs) | 1 | import System(getArgs) |
2 | import Numeric.LinearAlgebra | 2 | import Numeric.LinearAlgebra |
3 | import Control.Parallel.Strategies | 3 | import Control.Parallel.Strategies |
4 | import System.Time | ||
4 | 5 | ||
5 | work k = vectorMax s | 6 | inParallel = parMap rwhnf id |
6 | where (_,s,_) = svd (ident k :: Matrix Double) | 7 | |
8 | parMul 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 | ||
8 | main = do | 14 | main = 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 | |||
20 | a = (2><3) [1..6::Double] | ||
21 | b = (3><4) [1..12::Double] | ||
22 | |||
23 | time act = do | ||
24 | t0 <- getClockTime | ||
25 | act | ||
26 | t1 <- getClockTime | ||
27 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 | ||