4.12. Using SMP parallelism

GHC supports running Haskell programs in parallel on an SMP (symmetric multiprocessor).

There's a fine distinction between concurrency and parallelism: parallelism is all about making your program run faster by making use of multiple processors simultaneously. Concurrency, on the other hand, is a means of abstraction: it is a convenient way to structure a program that must respond to multiple asynchronous events.

However, the two terms are certainly related. By making use of multiple CPUs it is possible to run concurrent threads in parallel, and this is exactly what GHC's SMP parallelism support does. But it is also possible to obtain performance improvements with parallelism on programs that do not use concurrency. This section describes how to use GHC to compile and run parallel programs, in Section 7.15, “Parallel Haskell” we desribe the language features that affect parallelism.

4.12.1. Options to enable SMP parallelism In order to make use of multiple CPUs, your program must be linked with the -threaded option (see Section 4.10.7, “Options affecting linking”). Then, to run a program on multiple CPUs, use the RTS -N option: -N x Use x simultaneous threads when running the program. Normally x should be chosen to match the number of CPU cores on the machine. There is no means (currently) by which this value may vary after the program has started. For example, on a dual-core machine we would probably use +RTS -N2 -RTS . Whether hyperthreading cores should be counted or not is an open question; please feel free to experiment and let us know what results you find.