liveBook · Manning

Parallel package

As explained in Learn Haskell by Example

The parallel package is a Haskell library providing parallel evaluation primitives and evaluation strategies.

The parallel package provides Haskell primitives for parallel evaluation. Its Eval monad and runEval control computations, while sparks let the runtime schedule work across execution contexts. section 13.4.3

Use the package through several related mechanisms:

  • Create a spark with rpar; because it returns without waiting, the spark may fizzle if its value is demanded too soon. section 13.4.3
  • Force a value with rseq, then apply strategies such as evalList, using, or withStrategy to parallelize data structures. section 13.4.3

Parallel mapping

map (^ 100) [1 .. 1000] `using` evalList rpar applies a strategy to each list element. The same strategy can be written with withStrategy.

How Learn Haskell by Example covers it

How deep it goes
Explains sparks, HECs, work stealing, Eval, and strategies, while deferring spark lifecycle details to the runtime.
Examples
Demonstrates parallel exponentiation over lists and chunked pixel mapping over vectors.
What you can do after
Build parallel list and vector computations with Eval, Strategies, rpar, rseq, and chunked evaluation.
How it connects
Connects Eval, sparks, evaluation strategies, strict evaluation, vectors, and work stealing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.