| 1 | module Main where |
|---|
| 2 | |
|---|
| 3 | import Control.Parallel |
|---|
| 4 | import Control.Parallel.Strategies |
|---|
| 5 | |
|---|
| 6 | import System.Random |
|---|
| 7 | |
|---|
| 8 | n = 500000 |
|---|
| 9 | maxSparks = 8 |
|---|
| 10 | |
|---|
| 11 | qs [] _ = [] |
|---|
| 12 | qs [x] _ = [x] |
|---|
| 13 | qs (x:xs) n | n > 0 = (losort `using` rnf) `par` (hisort `using` rnf) `par` |
|---|
| 14 | (losort ++ (x:hisort)) |
|---|
| 15 | | n == 0 = losort ++ (x:hisort) |
|---|
| 16 | where |
|---|
| 17 | losort = qs [ y | y <- xs, y < x ] ((n-1) `max` 0) |
|---|
| 18 | hisort = qs [ y | y <- xs, y >= x ] ((n-1) `max` 0) |
|---|
| 19 | |
|---|
| 20 | main = do |
|---|
| 21 | rs <- mapM (\_ -> randomRIO (0, n)) [1..n] :: IO [Int] |
|---|
| 22 | print $ length $! qs rs maxSparks |
|---|
| 23 | |
|---|