Ticket #2192: parallel.hs

File parallel.hs, 0.6 KB (added by ivant, 5 years ago)

program that shows the problem

Line 
1module Main where
2
3import Control.Parallel
4import Control.Parallel.Strategies
5
6import System.Random
7
8n = 500000
9maxSparks = 8
10
11qs [] _ = []
12qs [x] _ = [x]
13qs (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
20main = do
21  rs <- mapM (\_ -> randomRIO (0, n)) [1..n] :: IO [Int]
22  print $ length $! qs rs maxSparks
23