Repository navigation
parTraversable not creating any sparks #17
Description
Activity
It looks like GHC's
PrelRules.sparkRule, which rewrites applications ofspark#to expressions already in head normal-form, is firing here, rewriting the sparks out of existence. In the case of theMapexample the expression looks like this prior to the rule firing,GHC.Prim.spark# @ (Control.Parallel.Strategies.Lift Integer) @ GHC.Prim.RealWorld (Control.Parallel.Strategies.Lift @ Integer ipv1_s6xJ) eta_B1where
eta_B1 :: State# RealWorldIt looks like
Liftis a sort of identity functor but sadly it carries no documentation so it's not entirely clear what purpose it serves.Something must have gone wrong in order to get to the point where
spark#is applied toLift x.partTraversableistraverse rparWith, whererparWith s a = do l <- rpar r; return (case l of Lift x -> x) where r = case s a of Eval f -> case f realWorld# of (# _, a' #) -> Lift a' data Lift a = Lift aSo for
rparto be applied directly to theLift a, we must have lifted out the evaluation early. Perhaps strictness is wrong somewhere?Seems like I faced same issue trying examples from "Parallel and Concurrent Programming in Haskell" by Simon Marlow:
(Just (fib 35), Just (fib 36))usingparPair rdeepseq rdeepseq
or even
(fib 35, fib 36)usingparPair rdeepseq rdeepseq
runs with 0 sparks created, on one coreWhile with
(fib 35, fib 36)usingevalPair (rparWith (rseq . force))
sparks created, 2 cores running with -N2Same with
parListfib taken from book:
fib :: Integer -> Integer
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)- added 3 commits that reference this issue
on Jun 1, 2018 @glutamate this ticket explains what we saw in Feb/March I think.
When I run this program with -s:
Sparks are created:
If I change parList to parTraversable
no sparks are created:
If I change rseq to rdeepseq:
No sparks are created
If I use parTraversable over a Map:
No sparks are created
using
rdeepseqresults in the same behavior.My cabal file has the following ghc options:
-O1 -threaded -rtsopts -with-rtsopts=-N4I am using the stack resolver
nightly-2017-10-06which hasparallel-3.2.1.1andghc-8.2.1I originally asked about this on stackoverflow and the behavior was confirmed by another user.