Parallelism
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.
Overview[edit]
GHC provides multi-scale support for parallel programming, from very fine-grained, small "sparks" to nested data parallelism and strategies.
Getting started[edit]
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[edit]
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.
Community[edit]
- Ask questions on Haskell Cafe
- See what parallel-haskell researchers and developers are working on
- Get the latest from the Parallel GHC Project
- Follow @parallelhaskell on Twitter
- StackOverflow on Haskell parallelism
News[edit]
- 2012-04-20 Parallel Haskell Digest 9
- 2012-03-02 Parallel Haskell Digest 8
- 2011-12-24 Parallel Haskell Digest 7
- 2011-11-21 Job Opportunity at Parallel Scientific
Tools[edit]
- ThreadScope - parallel programs not getting faster? Use the ThreadScope debugger and watch those sparks fly.
- Various libraries, including those for parallelism.
Documentation[edit]
- Glossary
- Learning to use parallelism in Haskell
- Current research
- Parallel ... Programming in Haskell (online book)