Ticket #2171 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

Parallel program crashes

Reported by: fed Owned by:
Priority: lowest Milestone: 6.8.3
Component: Runtime System Version: 6.8.2
Keywords: parallel, crash, race condition Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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

Attachments

primes.exe.zip Download (227.9 KB) - added by fed 5 years ago.
generated executable

Change History

  Changed 5 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.8.3

I can't reproduce this with the 6.8.2 Windows installer on XP x86, nor the head on Linux/amd64. Can anyone else reproduce it?

Changed 5 years ago by fed

generated executable

  Changed 5 years ago by fed

It's rather strange because I can reproduce the problem again and again and I have seen a lot of "Segmentation fault/access violation in generated code" outputs.

Probably exactly the same type of dual core processor is required – AMD Athlon x2.

I am attaching generated exe-file just in case.

  Changed 5 years ago by igloo

Ah, OK - I only have single-processor machines.

  Changed 5 years ago by judah

I can reproduce this on my iMac (2.4 GHz Intel Core 2 Duo). I get a Bus error about half of the times that I run the program.

  Changed 5 years ago by igloo

  • os changed from Windows to Multiple
  • architecture changed from x86 to Multiple

Thanks judah! And that also means it's not a Windows-only problem, which is useful info.

  Changed 5 years ago by simonmar

  • component changed from Compiler to Runtime System

Another data point: I just ran this 5 times on my dual-proc Intel Core laptop with zero failures.

  Changed 5 years ago by guest

Reproduced on a dual Opteron system running Fedora 8 x86_64. I get a Segmentation fault about every 3rd run.

- chris (chris at chr-breitkopf.de)

in reply to: ↑ description   Changed 5 years ago by MarcWeber

Replying to 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] ->

Error: Failed to load processor a
No macro or processor named 'a' found

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 }}}

I can reproduce this error as well (NixOS Linux, DualCore?, x86_64) ghc 6.8.2

  Changed 5 years ago by simonmar

Can someone who can reproduce this bug please try the fix from #2192 (now pushed to HEAD)?

  Changed 5 years ago by igloo

  • priority changed from normal to lowest

(waiting for response)

  Changed 5 years ago by judah

That patch fixes it for me in HEAD.

  Changed 5 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Thanks judah; that patch is already merged, so I'll close this ticket.

  Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple

  Changed 5 years ago by simonmar

  • os changed from Multiple to Unknown/Multiple
Note: See TracTickets for help on using tickets.