Difference between revisions of "Template:GHC/Multicore"

From HaskellWiki
Jump to navigation Jump to search
(from GHC/Concurrency)
 
m (more relevant link)
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
* Compile your program using the <tt>-threaded</tt> switch.
 
* Compile your program using the <tt>-threaded</tt> switch.
   
* 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). 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 <tt>-N</tt> however, like so: <tt>+RTS -N</tt>).
+
* Run the program with <tt>+RTS -N2</tt> to use 2 threads, for example (RTS stands for runtime system; see the [http://www.haskell.org/ghc/docs/7.0.1/html/users_guide/using-smp.html#parallel-options GHC users' guide]). You should use a <tt>-N</tt> 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 <tt>-N</tt> however, like so: <tt>+RTS -N</tt>).
   
 
* Concurrent threads (<tt>forkIO</tt>) will run in parallel, and you can also use the <tt>par</tt> combinator and Strategies from the [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Parallel-Strategies.html Control.Parallel.Strategies] module to create parallelism.
 
* Concurrent threads (<tt>forkIO</tt>) will run in parallel, and you can also use the <tt>par</tt> combinator and Strategies from the [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Parallel-Strategies.html Control.Parallel.Strategies] module to create parallelism.

Latest revision as of 19:56, 4 August 2012

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.