import Data.Array.Repa
import Data.Vector.Unboxed hiding(zipWith)
import Prelude hiding(zipWith,replicate)
dotp :: Array U DIM1 Float -> Array U DIM1 Float -> IO Float
dotp x y = sumAllP $ zipWith (*) x y
x = fromUnboxed (Z:.20000000) $ replicate 20000000 1
y = fromUnboxed (Z:.20000000) $ replicate 20000000 1
main = (dotp x y) >>= print
Compiled with ghc -O2 -threaded test.hs
However, when I execute the executable with ./test +RTS -N1
the result is 1.6777216e7
while ./test +RTS -N2
or with more cores,
the result is correct : 2.0e7
What is wrong with my code?
You use
Float
instead ofDouble
.Float
doesn't have enough significant digits (~7) for your use case:Switch to
Double
. If all your values are integral, considerInt
(orIntxx
fromData.Int
) orWord
(fromData.Word
).See also: