I wanted to write a program that operates on a really large array, and does a lot of random access read/write operations. I figured vector
is the most suitable way of doing it in Haskell, so I wrote a simple program to test its performance:
import Data.Int
import qualified Data.Vector.Unboxed.Mutable as UM
n = 1000000000
main = do
a <- UM.new n
UM.read a 42 :: IO Int32
However, when I ran it, it failed with segmentation fault
:
$ ghc -O2 test.hs
$ ./test
Segmentation fault (core dumped)
This machine has more than enough memory for the array. Here is the output of free -h
:
total used free shared buffers cached
Mem: 251G 150G 100G 672K 419M 141G
-/+ buffers/cache: 9.2G 242G
Swap: 255G 870M 255G
Was it because Haskell's vector
package cannot handle very large arrays? Can I modify my code so that it can work on large arrays without too much performance compromise?
Edit: My GHC version is 7.10.2.20150906, and my vector
version is 0.11.0.0. This is on a 64-bit linux machine, with
> maxBound :: Int
9223372036854775807
Overview. A segmentation fault (aka segfault) is a common condition that causes programs to crash; they are often associated with a file named core . Segfaults are caused by a program trying to read or write an illegal memory location.
It can be resolved by having a base condition to return from the recursive function. A pointer must point to valid memory before accessing it.
1) Segmentation Fault (also known as SIGSEGV and is usually signal 11) occur when the program tries to write/read outside the memory allocated for it or when writing memory which can only be read.In other words when the program tries to access the memory to which it doesn't have access to.
This is due to a bug in primitive that is apparently fixed in the recently-released primitive-0.6.1.0. I suggest you add a lower bound on primitive to your project accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With