我不明白为什么这个程序使用repa:在使用repa时使用Identity monad和mmultP有什么问题?
import Data.Array.Repa
import Data.Array.Repa.Algorithms.Matrix
import Data.Functor.Identity
go = runIdentity $ do
let mat = fromListUnboxed (ix2 2 2) [1..4]
let ins = fromListUnboxed (ix2 2 1) [1, 1]
mmultP mat ins
是给我以下警告:
Data.Array.Repa: Performing nested parallel computation sequentially.
You've probably called the 'compute' or 'copy' function while another
instance was already running. This can happen if the second version
was suspended due to lazy evaluation. Use 'deepSeqArray' to ensure
that each array is fully evaluated before you 'compute' the next one.
我没有嵌套计算,我没叫compute
或copy
,一切我用来做计算是在同一个monad中。这是否与懒惰评估有关?如果是这样,在使用Identity monad时如何使并行计算发生(保持整体计算纯粹)?
仅供参考,用runST
代替runIdentity
可以使其工作,但在任何情况下都不会使用特定monad的功能。
的源代码里面看,我看'mmultP'调用'computeP',它调用'unsafePerformIO'。我对此并不是很有经验,但是'unsafePerformIO'和'Identity'单子之间可能存在不兼容(也许'身份'的行为与懒惰)? – madjar
@madjar我不知道。我不知道如何。 – rityzmon