From 6ba49a2db7549b7a14f1aafa4f57934098dd8240 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Tue, 10 Oct 2006 15:58:34 +0000 Subject: [PATCH] Improve documentation of concurrent and parallel Haskell; push to branch --- docs/users_guide/parallel.xml | 121 +++++++++++++++++++++++++++++++++-------- 1 file changed, 97 insertions(+), 24 deletions(-) diff --git a/docs/users_guide/parallel.xml b/docs/users_guide/parallel.xml index 1f29d2c..fc7ca94 100644 --- a/docs/users_guide/parallel.xml +++ b/docs/users_guide/parallel.xml @@ -1,40 +1,113 @@ - Parallel Haskell + Concurrent and Parallel Haskell parallelism - 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. + + - 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 schedule the running Haskell threads among the available OS threads, running as many in parallel as you specified with the RTS option. - + 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). + + Annotating pure code for parallelism - 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 to use the par combinator, which is closely related to (and often used with) seq. Both of these are available from Control.Parallel: -- 1.7.10.4