liveBook · Manning

Rseq

As explained in Learn Haskell by Example

rseq is an evaluation strategy that evaluates a value to weak head normal form sequentially.

rseq is an evaluation strategy that evaluates a value sequentially to weak head normal form. In chunked parallel work, it evaluates each chunk rather than creating another spark. section 13.4.3

Use rseq when parallel work already creates the sparks:

  • Combine it with parListChunk so each spark performs a larger unit of work. section 13.4.3
  • Avoid replacing it with rpar in this situation, because rpar would spark another spark and add useless work. section 13.4.3
  • Tune chunk sizes and verify performance with benchmarking, since spark management and garbage collection can reduce speedups. section 13.4.3
Listing 13.25 A module for chunked parallel execution of the Vector type
module Data.Vector.Strategies (parVectorChunk) where

import Control.Parallel.Strategies     #1
import qualified Data.Vector as V      #1

parVectorChunk :: Int -> Strategy (V.Vector a)
parVectorChunk size =
  fmap V.fromList . parListChunk size rseq . V.toList  #2

A Vector strategy converts the Vector to a list, applies parListChunk with rseq, and converts the result back. section 13.4.3

How Learn Haskell by Example covers it

How deep it goes
Defines weak-head-normal-form evaluation and explains its role in chunking, but does not describe runtime internals.
Examples
Uses chunked Vector processing for parallel image mapping and box-blur performance testing.
What it assumes
Assumes familiarity with Haskell strategies, sparks, lists, and Vectors.
What you can do after
Apply rseq in chunked parallel strategies and benchmark chunk sizes for practical performance gains.
How it connects
Connects Strategy, sparks, parallel evaluation, parListChunk, and Vector chunking.

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.