[Haskell-cafe] Why should we write "a `par` b `pseq` (f a b)" instead of "a `par` b `par` (f a b)"?

Johannes Waldmann waldmann at imn.htwk-leipzig.de
Sun Jan 20 14:34:54 CET 2013

Petr P <petr.mvd <at> gmail.com> writes:

> Is there any reason to use
>   a `par` b `pseq` (a + b)
> instead of
>   a `par` b `par` (a + b)

(better ask this on parallel-haskell?)

> It seems to me that the second variant would work as well: 
> The main thread would block on one of the sparked computations,

I think the main thread would not block at all.
Instead, it would start to evaluate  a  (or  b) right away, 
since (+) is strict, thus duplicating the work of
a spark, and causing the spark to fizzle.

Why does it work in   a `par` b `pseq` a+b ?
I am not even sure - there might be a race condition:
assume that evaluation (to WHNF) of  b (and of  a)  takes a long time,
but  b  (in the main thread) finishes shortly 
before  a  does (in the spark), 
then the spark still fizzles and its work was in vain?


More information about the Haskell-Cafe mailing list