bwr*_*oga 4 parallel-processing haskell
当我运行此程序时-s:
module Main where
import Control.Parallel.Strategies
main :: IO ()
main = do let xs = take 1000 $ product . take 1000 . repeat <$> [1..]
x = product (xs `using` parList rseq)
putStrLn (show x)
Run Code Online (Sandbox Code Playgroud)
火花创建:
SPARKS:1000(993转换,0溢出,0哑,6 GC,1失败)
如果我换parList到parTraversable
x = product (xs `using` parTraversable rseq)
Run Code Online (Sandbox Code Playgroud)
没有产生火花:
SPARKS:0(0转换,0溢出,0哑,0 GC'd,0失败)
如果我rseq改为rdeepseq:
main = do let xs = (take 1000 $ product . take 1000 . repeat <$> [1..]) :: [Integer]
x = product (xs `using` parList rdeepseq)
putStrLn (show x)
Run Code Online (Sandbox Code Playgroud)
没有产生火花
SPARKS:0(0转换,0溢出,0哑,0 GC'd,0失败)
我使用parallel-3.2.1.1并在源代码parList中定义使用parTraversable!
parList :: Strategy a -> Strategy [a]
parList = parTraversable
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我可以重现你的行为(ghc-8.2.1,parallel-3.2.1.1).
后来,这Strategies.hs是一个RULES特殊情况的pragma parList rseq.我想这是一个错误,它有不同的行为parTraversable(我不太了解内部,以确定错误所在的位置).我建议在parallel问题跟踪器上提交一张票:https://github.com/haskell/parallel/issues
这是有问题的代码,从文件的第505行开始:
-- Non-compositional version of 'parList', evaluating list elements
-- to weak head normal form.
-- Not to be exported; used for optimisation.
-- | DEPRECATED: use @'parList' 'rseq'@ instead
parListWHNF :: Strategy [a]
parListWHNF xs = go xs `pseq` return xs
where -- go :: [a] -> [a]
go [] = []
go (y:ys) = y `par` go ys
-- The non-compositional 'parListWHNF' might be more efficient than its
-- more compositional counterpart; use RULES to do the specialisation.
{-# NOINLINE [1] parList #-}
{-# NOINLINE [1] rseq #-}
{-# RULES
"parList/rseq" parList rseq = parListWHNF
#-}
Run Code Online (Sandbox Code Playgroud)