From 0c1b8611b9cc55cc646c708b63442f3aaac1249d Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 24 Apr 2010 09:47:42 +0000 Subject: examples/parallel using toBlocks --- examples/parallel.hs | 19 ++----------------- lib/Numeric/LinearAlgebra/Algorithms.hs | 8 ++++---- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/examples/parallel.hs b/examples/parallel.hs index 3c83c54..435e367 100644 --- a/examples/parallel.hs +++ b/examples/parallel.hs @@ -6,19 +6,16 @@ import Control.Parallel.Strategies import System.Time inParallel = parMap rwhnf id --- rdeepseq (or older rnf) not needed in this case + -- matrix product decomposed into p parallel subtasks parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] - where ys = splitColumns p y - --- x <||> y = fromColumns . inParallel . map (x <>) . toColumns $ y + 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 $ vectorMax $ takeDiag $ m <> m --- time $ print $ vectorMax $ takeDiag $ m <||> m time $ print $ vectorMax $ takeDiag $ parMul 2 m m time $ print $ vectorMax $ takeDiag $ parMul 4 m m time $ print $ vectorMax $ takeDiag $ parMul 8 m m @@ -28,15 +25,3 @@ time act = do act t1 <- getClockTime print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 - -splitColumns n m = splitColumns' (f n (cols m)) m - where - splitColumns' [] m = [] - splitColumns' ((a,b):rest) m = subMatrix (0,a) (rows m, b-a+1) m : splitColumns' rest m - - f :: Int -> Int -> [(Int,Int)] - f n c = zip ks (map pred $ tail ks) - where ks = map round $ toList $ linspace (fromIntegral n+1) (0,fromIntegral c) - -splitRowsAt p m = (takeRows p m, dropRows p m) -splitColumnsAt p m = (takeColumns p m, dropColumns p m) diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 580f4bb..fc2fcb2 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs @@ -329,15 +329,15 @@ ctrans = ctrans' -- | Matrix product. multiply :: Field t => Matrix t -> Matrix t -> Matrix t -multiply = multiply' +multiply = {-# SCC "multiply" #-} multiply' -- | Similar to 'cholSH', but instead of an error (e.g., caused by a matrix not positive definite) it returns 'Nothing'. mbCholSH :: Field t => Matrix t -> Maybe (Matrix t) -mbCholSH = mbCholSH' +mbCholSH = {-# SCC "mbCholSH" #-} mbCholSH' -- | Similar to 'chol', without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. cholSH :: Field t => Matrix t -> Matrix t -cholSH = cholSH' +cholSH = {-# SCC "cholSH" #-} cholSH' -- | Cholesky factorization of a positive definite hermitian or symmetric matrix. -- @@ -351,7 +351,7 @@ chol m | exactHermitian m = cholSH m -- | Determinant of a square matrix. det :: Field t => Matrix t -> t -det m | square m = s * (product $ toList $ takeDiag $ lup) +det m | square m = {-# SCC "det" #-} s * (product $ toList $ takeDiag $ lup) | otherwise = error "det of nonsquare matrix" where (lup,perm) = luPacked m s = signlp (rows m) perm -- cgit v1.2.3