id summary reporter owner description type status priority milestone component version resolution keywords cc os architecture failure testcase blockedby blocking related differential wikipage
2171 Parallel program crashes fed "I wrote a parallel program for computing prime numbers (see code below).
Compiled it using
ghc -threaded --make primes.hs
Then run
primes 200000 200010 +RTS -N2 -sstderr
In 80% of runs the program crashes with segmentation fault message. My operating system is Windows XP SP2. One time I saw a typical Windows red cross dialog box with access violation report as a result of the run.
But few times the program finished with correct result.
{{{
module Main where
import System.Environment
import Control.Parallel.Strategies
import Data.Maybe
chunkSize = 1000
threads = 2
maybePrimes :: [Maybe Integer]
maybePrimes = Just 2 : Just 3 : Just 5 : [ if isPrime x then (Just x) else Nothing | x <- candidates 7 11 ]
where
candidates a1 a2 = a1 : a2 : candidates (a1+6) (a2+6)
isPrime x = all ((0 /=) . (x `mod`)) $ takeWhile ((x>=).(^2)) primes
splitOnSubLists :: Int -> [a] -> [[a]]
splitOnSubLists n xs =
let
(begin, end) = splitAt n xs
in
begin : splitOnSubLists n end
maybePrimes2 :: [Maybe Integer]
maybePrimes2 = concat $ parBuffer (threads-1) rnf
$ splitOnSubLists chunkSize maybePrimes
primes :: [Integer]
primes = catMaybes maybePrimes2
main = do
args <- getArgs
(first, last) <- case args of
[] -> return (10, 19)
(x:[]) -> return (f, f+9) where f = read x
(x:y:_) -> return (read x, read y)
let p = drop (first-1) $ take last $ zip [1..] primes in
mapM (\(x,y) -> putStrLn (show x ++ "" -> "" ++ show y)) p
}}}
" bug closed lowest 6.8.3 Runtime System 6.8.2 fixed parallel, crash, race condition Unknown/Multiple Unknown/Multiple None/Unknown