How it works...

monad-par defines the Par monad which defines the following primitives:

  • new: Define a new empty IVar
  • get: Wait for having some value in IVar
  • put: Put some value into IVar
  • fork: Signal that the input Par action can be run in parallel
  • spawn: A function to run an action in parallel to produce an IVar

Internally, monad-par implements a way to balance these activities across threads by scheduling and balancing them. monad-par allows us to specify parallel tasks without getting into the nitty-gritty of actually scheduling tasks.

Also note that, in this recipe, we have used a threshold to run the task sequentially. This is to increase the granularity of the tasks. This speeds up more speedup when there is no threshold. As because ...

Get Haskell Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.