@@ -5,15 +5,71 @@ module Main where
55import Data.List.Split ( splitOn )
66import System.Environment ( getArgs )
77import Control.Monad ( unless )
8+ import Control.DeepSeq ( NFData )
89
910import qualified Array as A
11+ import Linear.Common
12+
13+ import ForeignFunctionImports as FFI
1014import qualified Vector as V
1115import Input
1216import qualified Measure as M
1317import Sort
1418import Utils
1519import qualified Microbench as MB
1620
21+ import qualified Insertion as I
22+ import qualified QuickSort as Q
23+ import qualified DpsMergeSort4 as DMS
24+ import qualified DpsMergeSort4Par as DMSP
25+ import qualified PiecewiseFallbackSort as PFS
26+ import qualified PiecewiseFallbackSortPar as PFSP
27+ import qualified Data.Vector.Algorithms.Insertion as ISDVS
28+ import qualified Data.Vector.Algorithms.Merge as MSDVS
29+ import qualified Data.Vector.Algorithms.Intro as QSDVS
30+
31+ --
32+ -- Table of sorting functions
33+ --
34+
35+ sortFn :: (Show a , A. HasPrimOrd a , NFData a ) => SortAlgo -> ParOrSeq -> (A. Array a -. A. Array a )
36+ sortFn bench parorseq = case (bench,parorseq) of
37+ (Insertionsort , Seq ) -> I. isort_top'
38+ (Quicksort , Seq ) -> Q. quickSort'
39+ (Mergesort , Seq ) -> DMS. msort
40+ (Mergesort , Par ) -> DMSP. msort
41+ (Optsort , Seq ) -> PFS. pfsort
42+ (Optsort , Par ) -> PFSP. pfsort
43+ oth -> error $ " sortFn: unknown configuration: " ++ show oth
44+ {-# INLINABLE sortFn #-}
45+
46+ vectorSortFn :: SortAlgo -> ParOrSeq -> VecSort
47+ vectorSortFn bench parorseq = case (bench,parorseq) of
48+ (Insertionsort , Seq ) -> ISDVS. sort
49+ (Mergesort , Seq ) -> MSDVS. sort
50+ (Quicksort , Seq ) -> QSDVS. sort
51+ oth -> error $ " sortFn: unknown configuration: " ++ show oth
52+ {-# INLINABLE vectorSortFn #-}
53+
54+ sortFnC :: SortAlgo -> FFI. SortFn
55+ sortFnC alg = case alg of
56+ Insertionsort -> FFI. c_insertionsort
57+ Mergesort -> FFI. c_mergesort
58+ Quicksort -> FFI. c_quicksort
59+ _ -> error " sortFnC: Csort not implemented!"
60+ {-# INLINABLE sortFnC #-}
61+
62+ sortFnCxx :: SortAlgo -> FFI. SortFnCxx
63+ sortFnCxx alg = case alg of
64+ Insertionsort -> FFI. cxx_int_insertionsort
65+ Mergesort -> FFI. cxx_int_mergesort
66+ Quicksort -> FFI. cxx_int_quicksort
67+ _ -> error " sortFnCxx: Csort not implemented!"
68+ {-# INLINABLE sortFnCxx #-}
69+
70+ --
71+ -- Select which benchmark to run
72+ --
1773
1874-- dobench :: Benchmark -> ParOrSeq -> Maybe Int -> IO ()
1975dobench :: Benchmark -> ParOrSeq -> Maybe Int -> Int -> IO ()
@@ -102,13 +158,13 @@ dobench bench parorseq mb_size iters = do
102158 pure (A. size arr, A. size res0, tmed0, tall0)
103159 CSort alg -> do
104160 arr <- getInputAsList alg mb_size
105- (res0, tmed0, tall0) <- M. benchAndRunCSorts alg arr iters
161+ (res0, tmed0, tall0) <- M. benchAndRunCSorts (sortFnC alg) arr iters
106162 unless (isSorted (res0)) (error $ show bench ++ " : result not sorted." )
107163 putStrLn " Sorted: OK"
108164 pure (length arr, length res0, tmed0, tall0)
109165 CxxSort alg -> do
110166 arr <- getInputAsList alg mb_size
111- (res0, tmed0, tall0) <- M. benchAndRunCxxSorts alg arr iters
167+ (res0, tmed0, tall0) <- M. benchAndRunCxxSorts (sortFnCxx alg) arr iters
112168 unless (isSorted (res0)) (error $ show bench ++ " : result not sorted." )
113169 putStrLn " Sorted: OK"
114170 pure (length arr, length res0, tmed0, tall0)
0 commit comments