Commit 8b69714d authored by rl@cse.unsw.edu.au's avatar rl@cse.unsw.edu.au
Browse files

Use the benchmark framework for QSort

parent 2547ef83
module Main where
import QSortSeq
import QSortSeq
import Control.Exception (evaluate)
import System.Console.GetOpt
import Data.Array.Parallel.Unlifted
import Bench.Benchmark
import Bench.Options
algs = [("seq", qsort)]
generateVector :: Int -> IO (Point (UArr Double))
generateVector n =
do
evaluate vec
return $ ("N = " ++ show n) `mkPoint` vec
where
vec = toU [1..fromInteger (toInteger n)]
main = ndpMain "QSort"
"[OPTION] ... SIZES ..."
run [Option ['a'] ["algo"] (ReqArg const "ALGORITHM")
"use the specified algorithm"]
"seq"
run opts alg sizes =
case lookup alg algs of
Nothing -> failWith ["Unknown algorithm"]
Just f -> case map read sizes of
[] -> failWith ["No sizes specified"]
szs -> do
benchmark opts f (map generateVector szs) show
return ()
main = do
print qsortTest
\ No newline at end of file
......@@ -7,6 +7,7 @@ where
import Data.Array.Parallel.Unlifted
{-
qsortTest =
-- (qsortList ([1..200000])) !!199999
lengthSU $ qsortLifted $ toSU ([[1..200000]]::[[Double]])
......@@ -20,7 +21,11 @@ qsort xsarr
pivot = xsarr !: (xsLen `div` 2)
smallerEq = filterU (<= pivot) xsarr
greater = filterU (> pivot) xsarr
-}
qsort :: UArr Double -> Int
{-# NOINLINE qsort #-}
qsort = lengthSU . qsortLifted . singletonSU
qsortLifted:: SUArr Double -> SUArr Double
qsortLifted xssArr = splitApplySU flags qsortLifted' id xssArr
......@@ -113,4 +118,4 @@ qsortList xs = (qsortList smaller) ++ equal ++ (qsortList greater)
p = xs !! (length xs `div` 2)
smaller = [x | x <- xs, x < p]
equal = [x | x <- xs, x == p]
greater = [x | x <- xs, x > p]
\ No newline at end of file
greater = [x | x <- xs, x > p]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment