diff options
author | Thomas Miedema <thomasmiedema@gmail.com> | 2016-06-18 22:44:19 +0200 |
---|---|---|
committer | Thomas Miedema <thomasmiedema@gmail.com> | 2016-06-20 16:22:07 +0200 |
commit | 3dc1202546e63b50f828a34474717b1ddcbed5c7 (patch) | |
tree | 745fde8e9712c6d0b0507d9ae4988736c678abdb /testsuite/tests/dph | |
parent | cf6e65693588cd9d40c895279f2e53d3d25a2c58 (diff) | |
download | haskell-3dc1202546e63b50f828a34474717b1ddcbed5c7.tar.gz |
Testsuite: tabs -> spaces [skip ci]
Diffstat (limited to 'testsuite/tests/dph')
-rw-r--r-- | testsuite/tests/dph/dotp/Main.hs | 32 | ||||
-rw-r--r-- | testsuite/tests/dph/nbody/Body.hs | 26 | ||||
-rw-r--r-- | testsuite/tests/dph/primespj/Main.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/dph/quickhull/Main.hs | 40 | ||||
-rw-r--r-- | testsuite/tests/dph/quickhull/SVG.hs | 34 | ||||
-rw-r--r-- | testsuite/tests/dph/quickhull/TestData.hs | 94 | ||||
-rw-r--r-- | testsuite/tests/dph/sumnats/Main.hs | 22 | ||||
-rw-r--r-- | testsuite/tests/dph/words/Main.hs | 64 | ||||
-rw-r--r-- | testsuite/tests/dph/words/WordsVect.hs | 82 |
9 files changed, 207 insertions, 207 deletions
diff --git a/testsuite/tests/dph/dotp/Main.hs b/testsuite/tests/dph/dotp/Main.hs index c6d4f1e91c..04eb407fc7 100644 --- a/testsuite/tests/dph/dotp/Main.hs +++ b/testsuite/tests/dph/dotp/Main.hs @@ -25,7 +25,7 @@ generateVectorU n = k = 1000 generateVector :: Int -> IO (PArray Double) -generateVector n +generateVector n = do vec <- generateVectorU n return $ P.fromUArray vec @@ -37,18 +37,18 @@ generateVectors n = w <- generateVector n return (v,w) -main - = do -- compute dot product with NDP - vectors <- generateVectors 100000 - let resultViaNDP = (uncurry dotp) vectors - - -- compute with lists - let (aVecX, aVecY) = vectors - let vecX = P.toList aVecX - let vecY = P.toList aVecY - let resultViaList = sum $ zipWith (*) vecX vecY - - -- ignore wibbles in low order bits - putStr $ (take 12 $ show resultViaNDP) ++ "\n" - putStr $ (take 12 $ show resultViaList) ++ "\n" - +main + = do -- compute dot product with NDP + vectors <- generateVectors 100000 + let resultViaNDP = (uncurry dotp) vectors + + -- compute with lists + let (aVecX, aVecY) = vectors + let vecX = P.toList aVecX + let vecY = P.toList aVecY + let resultViaList = sum $ zipWith (*) vecX vecY + + -- ignore wibbles in low order bits + putStr $ (take 12 $ show resultViaNDP) ++ "\n" + putStr $ (take 12 $ show resultViaList) ++ "\n" + diff --git a/testsuite/tests/dph/nbody/Body.hs b/testsuite/tests/dph/nbody/Body.hs index 3ba2149533..8a116993a8 100644 --- a/testsuite/tests/dph/nbody/Body.hs +++ b/testsuite/tests/dph/nbody/Body.hs @@ -6,7 +6,7 @@ module Body , Accel , MassPoint , Body - + , unitBody , massPointOfBody , setMassOfBody @@ -43,7 +43,7 @@ unitBody x y -- | Take the MassPoint of a body. massPointOfBody :: Body -> MassPoint -massPointOfBody (mp, vel, acc) +massPointOfBody (mp, vel, acc) = mp @@ -55,10 +55,10 @@ setMassOfBody mass ((x, y, _), vel, acc) -- | Set the acceleration of a body. setAccelOfBody :: Accel -> Body -> Body -setAccelOfBody acc' (mp, vel, _) +setAccelOfBody acc' (mp, vel, _) = (mp, vel, acc') - + -- | Set the starting velocity of a body. -- It is set to rotate around the origin, with the speed proportional -- to the sqrt of the distance from it. This seems to make nice simulations. @@ -68,18 +68,18 @@ setStartVelOfBody startVel (mp@(x, y, mass), vel, acc) (x', y') = normaliseV (x, y) vel' = (y', -x') vel'' = mulSV (sqrt (magV pos) * startVel) vel' - + in (mp, vel'', acc) -- | Advance a body forwards in time. advanceBody :: Double -> Body -> Body -advanceBody time - ( (px, py, mass) - , (vx, vy) - , acc@(ax, ay)) - - = ( (px + time * vx, py + time * vy, mass) - , (vx + time * ax, vy + time * ay) - , acc) +advanceBody time + ( (px, py, mass) + , (vx, vy) + , acc@(ax, ay)) + + = ( (px + time * vx, py + time * vy, mass) + , (vx + time * ax, vy + time * ay) + , acc) diff --git a/testsuite/tests/dph/primespj/Main.hs b/testsuite/tests/dph/primespj/Main.hs index 049e6a3e04..f7a3ed1fe5 100644 --- a/testsuite/tests/dph/primespj/Main.hs +++ b/testsuite/tests/dph/primespj/Main.hs @@ -12,19 +12,19 @@ primesList :: Int -> [Int] primesList 1 = [] primesList n = sps ++ [ i | i <- [sq+1..n], multiple sps i ] where - sps = primesList sq + sps = primesList sq sq = floor $ sqrt $ fromIntegral n multiple :: [Int] -> Int -> Bool multiple ps i = and [i `mod` p /= 0 | p <- ps] -main - = do let n = 1000 - let resultViaNDP = P.toList $ primesVect n - let resultViaLists = primesList n - - print resultViaNDP - print resultViaLists - print $ resultViaNDP == resultViaLists - +main + = do let n = 1000 + let resultViaNDP = P.toList $ primesVect n + let resultViaLists = primesList n + + print resultViaNDP + print resultViaLists + print $ resultViaNDP == resultViaLists + diff --git a/testsuite/tests/dph/quickhull/Main.hs b/testsuite/tests/dph/quickhull/Main.hs index 718a1630ef..e1dc04ba24 100644 --- a/testsuite/tests/dph/quickhull/Main.hs +++ b/testsuite/tests/dph/quickhull/Main.hs @@ -2,11 +2,11 @@ import qualified Types as QH import QuickHullVect (quickhull) -import qualified Data.Array.Parallel.Unlifted as U -import qualified Data.Array.Parallel.Prelude as P +import qualified Data.Array.Parallel.Unlifted as U +import qualified Data.Array.Parallel.Prelude as P import qualified Data.Array.Parallel.PArray as P -import Data.Array.Parallel.PArray (PArray) +import Data.Array.Parallel.PArray (PArray) import System.Environment import Data.List @@ -17,7 +17,7 @@ import TestData ----- runQuickhull :: PArray QH.Point -> [(Double, Double)] -runQuickhull pts +runQuickhull pts = let result = quickhull pts resxs = P.toUArray (QH.xsOf result) resys = P.toUArray (QH.ysOf result) @@ -25,19 +25,19 @@ runQuickhull pts -- Main Program --------------------------------------------------------------- -main - = do args <- getArgs - let n = case args of - [s] -> read s - _ -> 1000 - - paInput <- toPArrayPoints - $ genPointsCombo n - - let psHull = runQuickhull paInput - psInput = P.toList paInput - - putStr - $ makeSVG - (roundPoints psInput) - (roundPoints psHull) +main + = do args <- getArgs + let n = case args of + [s] -> read s + _ -> 1000 + + paInput <- toPArrayPoints + $ genPointsCombo n + + let psHull = runQuickhull paInput + psInput = P.toList paInput + + putStr + $ makeSVG + (roundPoints psInput) + (roundPoints psHull) diff --git a/testsuite/tests/dph/quickhull/SVG.hs b/testsuite/tests/dph/quickhull/SVG.hs index f4183a77d6..c750fb06f5 100644 --- a/testsuite/tests/dph/quickhull/SVG.hs +++ b/testsuite/tests/dph/quickhull/SVG.hs @@ -4,31 +4,31 @@ module SVG where -- Making a SVG diagram of the points and hull makeSVG :: [(Int, Int)] -> [(Int, Int)] -> String makeSVG points hull - = unlines - $ [ "<svg width=\"100%\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">" ] - ++ [svgPolygon hull] - ++ map svgPoint points - ++ map svgPointHull hull - ++ ["</svg>"] + = unlines + $ [ "<svg width=\"100%\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">" ] + ++ [svgPolygon hull] + ++ map svgPoint points + ++ map svgPointHull hull + ++ ["</svg>"] svgPolygon :: [(Int, Int)] -> String svgPolygon points - = "<polygon" - ++ " points=\"" ++ (concat [show x ++ "," ++ show y ++ " " | (x, y) <- points]) ++ "\"" - ++ " style=\"fill:#d0d0ff;stroke:#000000;stroke-width:1\"" - ++ "/>" + = "<polygon" + ++ " points=\"" ++ (concat [show x ++ "," ++ show y ++ " " | (x, y) <- points]) ++ "\"" + ++ " style=\"fill:#d0d0ff;stroke:#000000;stroke-width:1\"" + ++ "/>" svgPoint :: (Int, Int) -> String svgPoint (x, y) - = "<circle cx=\"" ++ show x ++ "\" cy=\"" ++ show y ++ "\" r=\"0.5\"" - ++ " style=\"stroke:#000000\"" - ++ "/>" + = "<circle cx=\"" ++ show x ++ "\" cy=\"" ++ show y ++ "\" r=\"0.5\"" + ++ " style=\"stroke:#000000\"" + ++ "/>" svgPointHull :: (Int, Int) -> String svgPointHull (x, y) - = "<circle cx=\"" ++ show x ++ "\" cy=\"" ++ show y ++ "\" r=\"1\"" - ++ " style=\"stroke:#ff0000\"" - ++ "/>" - + = "<circle cx=\"" ++ show x ++ "\" cy=\"" ++ show y ++ "\" r=\"1\"" + ++ " style=\"stroke:#ff0000\"" + ++ "/>" + roundPoints :: [(Double, Double)] -> [(Int, Int)] roundPoints ps = [(round x, round y) | (x, y) <- ps] diff --git a/testsuite/tests/dph/quickhull/TestData.hs b/testsuite/tests/dph/quickhull/TestData.hs index 2d07354de7..a27cca288e 100644 --- a/testsuite/tests/dph/quickhull/TestData.hs +++ b/testsuite/tests/dph/quickhull/TestData.hs @@ -1,17 +1,17 @@ -module TestData - ( genPointsUniform - , genPointsDisc - , genPointsCombo - , toPArrayPoints ) +module TestData + ( genPointsUniform + , genPointsDisc + , genPointsCombo + , toPArrayPoints ) where import qualified Types as QH -import qualified Data.Array.Parallel.Unlifted as U -import qualified Data.Array.Parallel.Prelude as P +import qualified Data.Array.Parallel.Unlifted as U +import qualified Data.Array.Parallel.Prelude as P import qualified Data.Array.Parallel.Prelude.Double as D import qualified Data.Array.Parallel.PArray as P -import Data.Array.Parallel.PArray (PArray) +import Data.Array.Parallel.PArray (PArray) import System.Random import Control.Exception @@ -22,71 +22,71 @@ import Control.Exception -- is between O (N) and O (N^2) depending on the input. -- To compare benchmark results, they always need to use the same -- input. -seed = 42742 +seed = 42742 -- | Some uniformly distributed points -genPointsUniform - :: Int -- ^ number of points - -> Double -- ^ minimum coordinate - -> Double -- ^ maximum coordinate - -> [(Double, Double)] +genPointsUniform + :: Int -- ^ number of points + -> Double -- ^ minimum coordinate + -> Double -- ^ maximum coordinate + -> [(Double, Double)] genPointsUniform n minXY maxXY = let - pointMin = 10 - pointMax = 510 - gen = mkStdGen seed - in toPairs $ take (2*n) $ randomRs (pointMin, pointMax) gen + pointMin = 10 + pointMax = 510 + gen = mkStdGen seed + in toPairs $ take (2*n) $ randomRs (pointMin, pointMax) gen toPairs [] = [] toPairs (x:y:pts) = (x, y) : toPairs pts -- | Some points distributed as a disc -genPointsDisc - :: Int -- ^ number of points - -> (Double, Double) -- ^ center of disc - -> Double -- ^ radius of disc - -> [(Double, Double)] +genPointsDisc + :: Int -- ^ number of points + -> (Double, Double) -- ^ center of disc + -> Double -- ^ radius of disc + -> [(Double, Double)] genPointsDisc n (originX, originY) radiusMax - = let (genRadius, genAngle) - = split $ mkStdGen seed - - radius = take n $ randomRs (0, radiusMax) genRadius - angle = take n $ randomRs (- pi, pi) genAngle + = let (genRadius, genAngle) + = split $ mkStdGen seed - makeXY (r, a) - = ( originX + r * cos a - , originY + r * sin a) + radius = take n $ randomRs (0, radiusMax) genRadius + angle = take n $ randomRs (- pi, pi) genAngle - in map makeXY $ zip radius angle + makeXY (r, a) + = ( originX + r * cos a + , originY + r * sin a) + + in map makeXY $ zip radius angle -- | A point cloud with areas of high an low density -genPointsCombo - :: Int -- ^ number of points - -> [(Double, Double)] +genPointsCombo + :: Int -- ^ number of points + -> [(Double, Double)] genPointsCombo n - = genPointsDisc (n `div` 5) (250, 250) 200 - ++ genPointsDisc (n `div` 5) (100, 100) 80 - ++ genPointsDisc (n `div` 5) (150, 300) 30 - ++ genPointsDisc (n `div` 5) (500, 120) 30 - ++ genPointsDisc (n `div` 5) (300, 200) 150 + = genPointsDisc (n `div` 5) (250, 250) 200 + ++ genPointsDisc (n `div` 5) (100, 100) 80 + ++ genPointsDisc (n `div` 5) (150, 300) 30 + ++ genPointsDisc (n `div` 5) (500, 120) 30 + ++ genPointsDisc (n `div` 5) (300, 200) 150 -- | Convert a list of points to a PArray toPArrayPoints :: [(Double, Double)] -> IO (PArray QH.Point) toPArrayPoints ps - = do let pts = QH.points (P.fromList (map fst ps)) - (P.fromList (map snd ps)) - evaluate $ force pts - return pts + = do let pts = QH.points (P.fromList (map fst ps)) + (P.fromList (map snd ps)) + evaluate $ force pts + return pts -- | Force points to be evaluated -force pts - = U.index "TestData" (P.toUArray (QH.xsOf pts)) 0 D.+ +force pts + = U.index "TestData" (P.toUArray (QH.xsOf pts)) 0 D.+ U.index "TestData" (P.toUArray (QH.ysOf pts)) 0 - + diff --git a/testsuite/tests/dph/sumnats/Main.hs b/testsuite/tests/dph/sumnats/Main.hs index 9e18e335a9..7c3ee7210b 100644 --- a/testsuite/tests/dph/sumnats/Main.hs +++ b/testsuite/tests/dph/sumnats/Main.hs @@ -5,17 +5,17 @@ import SumNatsVect (sumNats) -- Add all the natural numbers below 1000 that are multiples of 3 or 5. solutionLists maxN - = let sumOnetoN n = n * (n+1) `div` 2 - sumStep s n = s * sumOnetoN (n `div` s) - in sumStep 3 (maxN - 1) + sumStep 5 (maxN - 1) - sumStep 15 (maxN - 1) + = let sumOnetoN n = n * (n+1) `div` 2 + sumStep s n = s * sumOnetoN (n `div` s) + in sumStep 3 (maxN - 1) + sumStep 5 (maxN - 1) - sumStep 15 (maxN - 1) solutionLists2 maxN - = sum [ x | x <- [0.. maxN - 1] - , (x `mod` 3 == 0) || (x `mod` 5 == 0) ] + = sum [ x | x <- [0.. maxN - 1] + , (x `mod` 3 == 0) || (x `mod` 5 == 0) ] + +main + = do let n = 1000 + print $ solutionLists n + print $ solutionLists2 n + print $ sumNats n -main - = do let n = 1000 - print $ solutionLists n - print $ solutionLists2 n - print $ sumNats n -
\ No newline at end of file diff --git a/testsuite/tests/dph/words/Main.hs b/testsuite/tests/dph/words/Main.hs index 094a2ceb7d..b7c266921f 100644 --- a/testsuite/tests/dph/words/Main.hs +++ b/testsuite/tests/dph/words/Main.hs @@ -1,37 +1,37 @@ import WordsVect import Data.Array.Parallel -import qualified Data.Array.Parallel.Prelude.Word8 as W -import qualified Data.Array.Parallel.PArray as P -import qualified Data.Array.Parallel.Unlifted as U +import qualified Data.Array.Parallel.Prelude.Word8 as W +import qualified Data.Array.Parallel.PArray as P +import qualified Data.Array.Parallel.Unlifted as U import Data.Char -main - = do -- take the filename containing the words as the first arg - let str = "When I look into the looking glass I'm always sure to see" - ++ " no matter how I dodge about, me looking back at me." - - -- convert string to a PArray - let paStr :: PArray W.Word8 - paStr = P.fromUArray $ U.map W.fromInt $ U.fromList $ map ord str - - - -- break the string into words then flatten it back - let str' :: String - str' = map chr - $ map fromIntegral - $ P.toList - $ wordsOfPArray paStr - - - -- count the number of words in the string, using the vectorised program - let wordCountVect = fromIntegral $ wordCountOfPArray paStr - - -- count the number of words with the ye'olde list way - let wordCountList = length $ words str - - -- - putStr $ show str' ++ "\n" - ++ "word count vect = " ++ show wordCountVect ++ "\n" - ++ "word count lists = " ++ show wordCountList ++ "\n" -
\ No newline at end of file +main + = do -- take the filename containing the words as the first arg + let str = "When I look into the looking glass I'm always sure to see" + ++ " no matter how I dodge about, me looking back at me." + + -- convert string to a PArray + let paStr :: PArray W.Word8 + paStr = P.fromUArray $ U.map W.fromInt $ U.fromList $ map ord str + + + -- break the string into words then flatten it back + let str' :: String + str' = map chr + $ map fromIntegral + $ P.toList + $ wordsOfPArray paStr + + + -- count the number of words in the string, using the vectorised program + let wordCountVect = fromIntegral $ wordCountOfPArray paStr + + -- count the number of words with the ye'olde list way + let wordCountList = length $ words str + + -- + putStr $ show str' ++ "\n" + ++ "word count vect = " ++ show wordCountVect ++ "\n" + ++ "word count lists = " ++ show wordCountList ++ "\n" + diff --git a/testsuite/tests/dph/words/WordsVect.hs b/testsuite/tests/dph/words/WordsVect.hs index 344442f3fb..218e885dac 100644 --- a/testsuite/tests/dph/words/WordsVect.hs +++ b/testsuite/tests/dph/words/WordsVect.hs @@ -1,7 +1,7 @@ -- Break up a string into words in parallel. --- Based on the presentation "Breaking Sequential Habits of Thought", Guy Steele. --- http://groups.csail.mit.edu/mac/users/gjs/6.945/readings/MITApril2009Steele.pdf +-- Based on the presentation "Breaking Sequential Habits of Thought", Guy Steele. +-- http://groups.csail.mit.edu/mac/users/gjs/6.945/readings/MITApril2009Steele.pdf -- -- NOTE: This is a naive implementation, and I haven't benchmarked it. -- Using parallel arrays in Seg probably isn't helpful for performance, @@ -26,10 +26,10 @@ import qualified Prelude as Prel -- We can't use the Prelude Char and String types in vectorised code yet.. -type Char = Word8 -char_space = W.fromInt 32 +type Char = Word8 +char_space = W.fromInt 32 -type String = [: Char :] +type String = [: Char :] -- | Word state @@ -50,58 +50,58 @@ plusState str1 str2 (Seg al ass ar, Seg bl bss br) -> Seg al (ass +:+ joinEmpty [:ar +:+ bl:] +:+ bss) br joinEmpty :: [:[:Word8:]:] -> [:[:Word8:]:] -joinEmpty ws - | lengthP ws I.== 1 && lengthP (ws !: 0) I.== 0 = [::] - | otherwise = ws +joinEmpty ws + | lengthP ws I.== 1 && lengthP (ws !: 0) I.== 0 = [::] + | otherwise = ws -- | Convert a single char to a wordstate. stateOfChar :: Char -> State stateOfChar c - | c W.== char_space = Seg [::] [::] [::] - | otherwise = Chunk [:c:] - - + | c W.== char_space = Seg [::] [::] [::] + | otherwise = Chunk [:c:] + + -- | Break this string into words. stateOfString :: String -> State stateOfString str - = let len = lengthP str - result - | len I.== 0 = Chunk [::] - | len I.== 1 = stateOfChar (str !: 0) - | otherwise - = let half = len `div` 2 - s1 = sliceP 0 half str - s2 = sliceP half (len I.- half) str - in plusState (stateOfString s1) (stateOfString s2) - in result + = let len = lengthP str + result + | len I.== 0 = Chunk [::] + | len I.== 1 = stateOfChar (str !: 0) + | otherwise + = let half = len `div` 2 + s1 = sliceP 0 half str + s2 = sliceP half (len I.- half) str + in plusState (stateOfString s1) (stateOfString s2) + in result -- | Count the number of words in a string. countWordsOfState :: State -> Int countWordsOfState state = case state of - Chunk c -> wordsInChunkArr c - Seg c1 ws c2 -> wordsInChunkArr c1 I.+ lengthP ws I.+ wordsInChunkArr c2 - + Chunk c -> wordsInChunkArr c + Seg c1 ws c2 -> wordsInChunkArr c1 I.+ lengthP ws I.+ wordsInChunkArr c2 + wordsInChunkArr :: [:Word8:] -> Int wordsInChunkArr arr - | lengthP arr I.== 0 = 0 - | otherwise = 1 + | lengthP arr I.== 0 = 0 + | otherwise = 1 -- | Flatten a state back to an array of Word8s, --- inserting spaces between the words. +-- inserting spaces between the words. flattenState :: State -> [:Word8:] flattenState ss = case ss of - Chunk s -> s + Chunk s -> s - Seg w1 ws w2 - -> w1 - +:+ [:char_space:] - +:+ concatP [: w +:+ [:char_space:] | w <- ws :] - +:+ w2 + Seg w1 ws w2 + -> w1 + +:+ [:char_space:] + +:+ concatP [: w +:+ [:char_space:] | w <- ws :] + +:+ w2 -- Interface ------------------------------------------------------------------ @@ -109,17 +109,17 @@ flattenState ss wordsOfPArray :: PArray Word8 -> PArray Word8 {-# NOINLINE wordsOfPArray #-} wordsOfPArray arr - = let str = fromPArrayP arr - state = stateOfString str - strOut = flattenState state - in toPArrayP strOut + = let str = fromPArrayP arr + state = stateOfString str + strOut = flattenState state + in toPArrayP strOut -- | Count the number of words in an array wordCountOfPArray :: PArray Word8 -> Int {-# NOINLINE wordCountOfPArray #-} wordCountOfPArray arr - = let str = fromPArrayP arr - state = stateOfString str - in countWordsOfState state + = let str = fromPArrayP arr + state = stateOfString str + in countWordsOfState state |