liveBook · Manning

Parallelism

As explained in Learn Haskell by Example

Parallelism is the simultaneous execution of independent computations to reduce elapsed computation time.

Parallelism executes independent computations simultaneously to reduce elapsed time. In image processing, each pixel mapping can run independently because pure functions do not produce side effects or interfere with one another. section 13.4.1

A uniform pure function applied across an image is a practical target for parallelization. Haskell can add deterministic parallel execution without changing the underlying image-transformation algorithm. section 13.5

The practical workflow includes:

  • Identify the expensive mapping by measuring alternatives such as pixelation and box blur. section 13.4.1
  • Recognize the computation count: a 1,000-by-1,000 image produces one million pixel computations. section 13.4.1
  • Use evaluation strategies from Control.Parallel.Strategies, or create sparks with Eval and rpar. section 13.5
  • Avoid creating too many sparks; split work into larger chunks when the spark pool overflows. section 13.5

Parallel image filtering

A box-blur mapping gathers neighboring pixels, averages their color channels, and applies that computation to every image pixel. Because these mappings are independent, the expensive blur can be parallelized while preserving the image-processing algorithm. section 13.4 section 13.4.1

Listing 13.23 Example main module for testing
module Main (main) where

...
import Graphics.PNM
import System.Environment (getArgs)

main :: IO ()
main = do
  [filePath] <- getArgs
  Right rawImg <- readPnmFile filePath
  let Right pnmImg = validatePnm rawImg
      pnmImg' = mapImagePixels (boxBlur 8) pnmImg
  _ <- writeAsPng "test.png" pnmImg'
  return ()

A runnable image-processing program measures a box blur from input loading through PNG output, making the performance target concrete. section 13.4.1

How Learn Haskell by Example covers it

How deep it goes
Explains independence, measurement, sparks, strategies, and chunking, but does not detail a complete parallel implementation.
Examples
Demonstrates grayscale, pixelation, and box-blur mappings applied across PNM images before PNG output.
What it assumes
Assumes pure functions and image mappings, while introducing parallel execution through concrete pixel-processing performance work.
What you can do after
Apply parallel evaluation strategies to uniform pure mappings and diagnose ineffective spark granularity.
How it connects
Connects pure functions, image processing, evaluation strategies, sparks, Eval, rpar, and multicore CPUs.

Also explained in

Compare how 38 books explain parallelism →

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.