0
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

编译ghc -O2 -threaded test.hs

但是,当我执行可执行文件时./test +RTS -N1

结果是1.6777216e7

同时./test +RTS -N2或具有更多核心,

结果是正确的:2.0e7

我的代码有什么问题?

4

1 回答 1

3

您使用Float而不是Double. Float您的用例没有足够的有效数字 (~7):

λ> (1.6777216e7 :: 浮点数) + 1
1.6777216e7

切换到Double。如果您的所有值都是整数,请考虑Int(或Intxxfrom Data.Int) 或Word(from Data.Word)。

也可以看看:

于 2014-12-09T08:33:09.333 回答