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