[Haskell-cafe] missing rseq?
Yuras Shumovich
shumovichy at gmail.com
Wed Mar 11 14:07:12 UTC 2015
On Wed, 2015-03-11 at 08:26 +0100, Kees Bleijenberg wrote:
> In the book Parallel and Concurrent Programming in Haskell
> http://chimera.labs.oreilly.com/books/1230000000929/ch02.html#sec_par-eval-s
> udoku2 a list of sudokus is solved in parallel.
>
> In version 2 (sudoku2.hs) the program splits the list of sudokus in 2
> seperate lists and solves these lists in parallel.
>
> In version3 (sudoku3.hs) parMap is used.
>
> What I don't understand is why in sudoku2 the program has to wait until the
> parallel computations are finished with rseqs while in sudoku3.hs there is
> no rseq (not in the main program nor in parMap)? Why can't program
> sudoku3.hs terminate before all parallel calculations are finished as in
> Example 2-1. rpar/rpar?
I believe `rseq` is omitted in `sudoku3` for a reason.
In `sudoku2` we spawn two relatively heavy sparks, and the results of
them are immediately consumed. So if we don't wait for the sparks, the
main thread will start evaluating one of the thunks. Most likely the
thunk will be evaluated twice -- by the main thread and the spark. That
is called `fizzled` spark.
In `sudoku3` we have a lot of light sparks. When we spawn the last
spark, the first one most like is already evaluated (aka `converted`),
and its result can be immediately consumed by `length`.
Thanks,
Yuras
--
Haskell Exists
http://blog.haskell-exists.com/yuras
More information about the Haskell-Cafe
mailing list