diff options
Diffstat (limited to 'testsuite/tests/dph/sumnats')
-rw-r--r-- | testsuite/tests/dph/sumnats/Main.hs | 21 | ||||
-rw-r--r-- | testsuite/tests/dph/sumnats/Makefile | 3 | ||||
-rw-r--r-- | testsuite/tests/dph/sumnats/SumNatsVect.hs | 14 | ||||
-rw-r--r-- | testsuite/tests/dph/sumnats/dph-sumnats.T | 10 | ||||
-rw-r--r-- | testsuite/tests/dph/sumnats/dph-sumnats.stdout | 3 |
5 files changed, 51 insertions, 0 deletions
diff --git a/testsuite/tests/dph/sumnats/Main.hs b/testsuite/tests/dph/sumnats/Main.hs new file mode 100644 index 0000000000..9e18e335a9 --- /dev/null +++ b/testsuite/tests/dph/sumnats/Main.hs @@ -0,0 +1,21 @@ + +import SumNatsVect (sumNats) + +-- Solution for 1st Euler problem +-- 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) + +solutionLists2 maxN + = 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 +
\ No newline at end of file diff --git a/testsuite/tests/dph/sumnats/Makefile b/testsuite/tests/dph/sumnats/Makefile new file mode 100644 index 0000000000..9101fbd40a --- /dev/null +++ b/testsuite/tests/dph/sumnats/Makefile @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/testsuite/tests/dph/sumnats/SumNatsVect.hs b/testsuite/tests/dph/sumnats/SumNatsVect.hs new file mode 100644 index 0000000000..f51f207d0c --- /dev/null +++ b/testsuite/tests/dph/sumnats/SumNatsVect.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE ParallelArrays #-} +{-# OPTIONS -fvectorise #-} +module SumNatsVect (sumNats) where + +import Data.Array.Parallel.Prelude +import Data.Array.Parallel.Prelude.Int + +import qualified Prelude as P + +sumNats :: Int -> Int +sumNats maxN + = sumP [: x | x <- enumFromToP 0 (maxN - 1) + , (x `mod` 3 == 0) || (x `mod` 5 == 0) :] + diff --git a/testsuite/tests/dph/sumnats/dph-sumnats.T b/testsuite/tests/dph/sumnats/dph-sumnats.T new file mode 100644 index 0000000000..f84757c5d7 --- /dev/null +++ b/testsuite/tests/dph/sumnats/dph-sumnats.T @@ -0,0 +1,10 @@ + +test ('dph-sumnats' + , [ reqlib('dph-par') + , reqlib('dph-prim-par') + , only_ways(['normal', 'threaded1', 'threaded2']) ] + , multimod_compile_and_run + , [ 'Main' + , '-Odph -fdph-par']) + + diff --git a/testsuite/tests/dph/sumnats/dph-sumnats.stdout b/testsuite/tests/dph/sumnats/dph-sumnats.stdout new file mode 100644 index 0000000000..8858be2164 --- /dev/null +++ b/testsuite/tests/dph/sumnats/dph-sumnats.stdout @@ -0,0 +1,3 @@ +233168 +233168 +233168 |