From 1925c123d7d8184a1d2ddc0a413e0fd2776e1083 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 8 May 2014 08:48:12 +0200 Subject: empty hmatrix-base --- packages/hmatrix/examples/parallel.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 packages/hmatrix/examples/parallel.hs (limited to 'packages/hmatrix/examples/parallel.hs') diff --git a/packages/hmatrix/examples/parallel.hs b/packages/hmatrix/examples/parallel.hs new file mode 100644 index 0000000..e875407 --- /dev/null +++ b/packages/hmatrix/examples/parallel.hs @@ -0,0 +1,28 @@ +-- $ ghc --make -O -rtsopts -threaded parallel.hs +-- $ ./parallel 3000 +RTS -N4 -s -A200M + +import System.Environment(getArgs) +import Numeric.LinearAlgebra +import Control.Parallel.Strategies +import System.Time + +inParallel = parMap rwhnf id + +-- matrix product decomposed into p parallel subtasks +parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] + where [ys] = toBlocksEvery (rows y) (cols y `div` p) y + +main = do + n <- (read . head) `fmap` getArgs + let m = ident n :: Matrix Double + time $ print $ maxElement $ takeDiag $ m <> m + time $ print $ maxElement $ takeDiag $ parMul 2 m m + time $ print $ maxElement $ takeDiag $ parMul 4 m m + time $ print $ maxElement $ takeDiag $ parMul 8 m m + +time act = do + t0 <- getClockTime + act + t1 <- getClockTime + print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 + -- cgit v1.2.3