From HaskellWiki
Jump to navigation Jump to search

Note: you may want to read Parallelism vs. Concurrency, as the terms have historically been conflated.

This page contains notes and information about how to write parallel programs in Haskell.

For practicality, the content is GHC-centric at the moment, although this may change as Haskell evolves.


GHC provides multi-scale support for parallel programming, from very fine-grained, small "sparks" to nested data parallelism and strategies.

Getting started

Speed up your code by making it run on multicore:

Start with Control.Parallel (par, pseq)
Learn more about parallelism, then try using Strategies

GHC parallelism specifics

You get access to parallelism operations by importing the library Control.Parallel.

Since 2004, GHC supports running programs in parallel on an SMP or multi-core machine. How to do it:

  • Compile your program using the -threaded switch.
  • Run the program with +RTS -N2 to use 2 threads, for example (RTS stands for runtime system; see the GHC users' guide). You should use a -N value equal to the number of CPU cores on your machine (not including Hyper-threading cores). As of GHC v6.12, you can leave off the number of cores and all available cores will be used (you still need to pass -N however, like so: +RTS -N).
  • Concurrent threads (forkIO) will run in parallel, and you can also use the par combinator and Strategies from the Control.Parallel.Strategies module to create parallelism.
  • Use +RTS -sstderr for timing stats.
  • To debug parallel program performance, use ThreadScope.

Support for low-level parallelism features of modern processors continues to be added. As of version 7.8, GHC includes the ability to emit SIMD instructions, and also has a rudimentary ability to use atomic memory operations.




  • ThreadScope - parallel programs not getting faster? Use the ThreadScope debugger and watch those sparks fly.
  • Various libraries, including those for parallelism.


Alternative approaches

See also