Difference between revisions of "Concurrency"

From HaskellWiki
Jump to navigation Jump to search
m (GHC:concurrency moved to GHC/Concurrency)
Line 28: Line 28:
 
* You'll need to get a version of GHC that supports SMP. Either download ghc from [http://www.haskell.org/ghc/docs/latest/html/building/sec-cvs.html CVS] or use darcs: <tt>darcs get --partial http://darcs.haskell.org/ghc</tt>. There are also [http://www.haskell.org/ghc/dist/current/dist nightly snapshot distributions] available.
 
* You'll need to get a version of GHC that supports SMP. Either download ghc from [http://www.haskell.org/ghc/docs/latest/html/building/sec-cvs.html CVS] or use darcs: <tt>darcs get --partial http://darcs.haskell.org/ghc</tt>. There are also [http://www.haskell.org/ghc/dist/current/dist nightly snapshot distributions] available.
 
 
* All code currently has to be built using the <tt>-smp</tt> switch, including the libraries. If you downloaded a binary snapshot, then you already have the required libraries. If you build GHC from source, you need to add<p>
+
* You need to link your program using the <tt>-threaded</tt> switch. (NOTE: previously it was necessary to compile all code, including libraries, with the <tt>-smp</tt> switch, this is no longer the case. The <tt>-smp</tt> flag is now a synonym for <tt>-threaded</tt>).
<pre>
 
GhcLibWays += s
 
</pre>
 
to the file <tt>mk/build.mk</tt> in the build tree before building.</p>
 
 
* Compile your program with <tt>-smp</tt>
 
   
 
* Run the program with <tt>+RTS -N2</tt> to use 2 threads, for example. You should use a <tt>-N</tt> value equal to the number of CPU cores on your machine (not including Hyper-threading cores).
 
* Run the program with <tt>+RTS -N2</tt> to use 2 threads, for example. You should use a <tt>-N</tt> value equal to the number of CPU cores on your machine (not including Hyper-threading cores).
Line 41: Line 35:
   
 
* Use <tt>+RTS -sstderr</tt> for timing stats.
 
* Use <tt>+RTS -sstderr</tt> for timing stats.
 
   
 
== Links to related work on parallel and distributed Haskell (many based on GHC) ==
 
== Links to related work on parallel and distributed Haskell (many based on GHC) ==

Revision as of 13:58, 9 March 2006

Concurrent programming in GHC

This page contains notes and information about how to write concurrent programs in GHC.

Please feel free to add stuff here (Edit page link at the bottom).

Starting points


Using concurrency in GHC

  • The GHC manual gives a few useful flags that control scheduling (not usually necessary) RTS options.


Multiprocessor GHC

As of version 6.5, GHC supports running programs in parallel on an SMP or multi-core machine. How to do it:

  • You need to link your program using the -threaded switch. (NOTE: previously it was necessary to compile all code, including libraries, with the -smp switch, this is no longer the case. The -smp flag is now a synonym for -threaded).
  • Run the program with +RTS -N2 to use 2 threads, for example. You should use a -N value equal to the number of CPU cores on your machine (not including Hyper-threading cores).
  • Concurrent threads (forkIO and forkOS) 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.

Links to related work on parallel and distributed Haskell (many based on GHC)