[Improve documentation of concurrent and parallel Haskell; push to branch
simonpj@microsoft.com**20061010155834] {
hunk ./docs/users_guide/parallel.xml 3
-
Parallel Haskell
+ Concurrent and Parallel Haskell
hunk ./docs/users_guide/parallel.xml 7
- There are two implementations of Parallel Haskell: SMP paralellism
- SMP
- which is built-in to GHC (see ) and
- supports running Parallel Haskell programs on a single multiprocessor
- machine, and
- Glasgow Parallel HaskellGlasgow Parallel Haskell
- (GPH) which supports running Parallel Haskell
- programs on both clusters of machines or single multiprocessors. GPH is
- developed and distributed
- separately from GHC (see The
- GPH Page).
-
- Ordinary single-threaded Haskell programs will not benefit from
- enabling SMP parallelism alone. You must expose parallelism to the
- compiler in one of the following two ways.
-
-
- Running Concurrent Haskell programs in parallel
+ GHC implements some major extensions to Haskell to support
+ concurrent and parallel programming. Let us first etablish terminology:
+
+ Parallelism means running
+ a Haskell program on multiple processors, with the goal of improving
+ performance. Ideally, this should be done invisibly, and with no
+ semantic changes.
+
+ Concurrency means implementing
+ a program by using multiple I/O-performing threads. While a
+ concurrent Haskell program can run on a
+ parallel machine, the primary goal of using concurrency is not to gain
+ performance, but rather because that is the simplest and most
+ direct way to write the program. Since the threads perform I/O,
+ the semantics of the program is necessarily non-deterministic.
+
+
+ GHC supports both concurrency and parallelism.
+
+
+
+ Concurrent Haskell
+
+ Concurrent Haskell is the name given to GHC's concurrency extension.
+ It is enabled by default, so no special flags are required.
+ The
+ Concurrent Haskell paper is still an excellent
+ resource, as is Tackling
+ the awkward squad.
+
+ To the programmer, Concurrent Haskell introduces no new language constructs;
+ rather, it appears simply as a library,
+ Control.Concurrent. The functions exported by this
+ library include:
+
+Forking and killing threads.
+Sleeping.
+Synchronised mutable variables, called MVars
+Support for bound threads; see the paper Extending
+the FFI with concurrency.
+
+
+
+
+ Software Transactional Memory
+
+ GHC now supports a new way to coordinate the activities of Concurrent
+ Haskell threads, called Software Transactional Memory (STM). The
+ STM
+ papers are an excellent introduction to what STM is, and how to use
+ it.
+
+ The main library you need to use STM is
+ Control.Concurrent.STM. The main features supported are these:
+
+Atomic blocks.
+Transactional variables.
+Operations for composing transactions:
+retry, and orElse.
+Data invariants.
+
+All these features are described in the papers mentioned earlier.
+
+
hunk ./docs/users_guide/parallel.xml 78
- The first possibility is to use concurrent threads to structure your
- program, and make sure
- that you spread computation amongst the threads. The runtime will
+Parallel Haskell
+
+ GHC includes support for running Haskell programs in parallel
+ on symmetric, shared-memory multi-processor
+ (SMP)SMP.
+ By default GHC runs your program on one processor; if you
+ want it to run in parallel you must link your program
+ with the , and run it with the RTS
+ option; see ).
+ The runtime will
hunk ./docs/users_guide/parallel.xml 91
-
hunk ./docs/users_guide/parallel.xml 92
+ GHC only supports parallelism on a shared-memory multiprocessor.
+ Glasgow Parallel HaskellGlasgow Parallel Haskell
+ (GPH) supports running Parallel Haskell
+ programs on both clusters of machines, and single multiprocessors. GPH is
+ developed and distributed
+ separately from GHC (see The
+ GPH Page). However, the current version of GPH is based on a much older
+ version of GHC (4.06).
+
+
hunk ./docs/users_guide/parallel.xml 105
- The simplest mechanism for extracting parallelism from pure code is
+ Ordinary single-threaded Haskell programs will not benefit from
+ enabling SMP parallelism alone: you must expose parallelism to the
+ compiler.
+
+ One way to do so is forking threads using Concurrent Haskell (), but the simplest mechanism for extracting parallelism from pure code is
}