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





































