[commit: ghc] master: Add -Nmax<n> RTS feature (#10728) (b028384)

git at git.haskell.org git at git.haskell.org
Sat Dec 19 10:13:14 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/b02838405b00bcdeebb44da0a7a9562cd7fda66b/ghc

>---------------------------------------------------------------

commit b02838405b00bcdeebb44da0a7a9562cd7fda66b
Author: MarcelineVQ <matthewnhyatt at gmail.com>
Date:   Sat Dec 19 11:10:54 2015 +0100

    Add -Nmax<n> RTS feature (#10728)
    
    Added maximum core use based on processors
    -Nmax<x> chooses the minimum of processor count or x
    Added documentation.
    
    Reviewed By: simonmar, thomie
    
    Differential Revision: https://phabricator.haskell.org/D1650


>---------------------------------------------------------------

b02838405b00bcdeebb44da0a7a9562cd7fda66b
 docs/users_guide/using-concurrent.rst |  8 +++++++-
 rts/RtsFlags.c                        | 17 +++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/docs/users_guide/using-concurrent.rst b/docs/users_guide/using-concurrent.rst
index c00a294..2621afc 100644
--- a/docs/users_guide/using-concurrent.rst
+++ b/docs/users_guide/using-concurrent.rst
@@ -107,11 +107,14 @@ RTS options for SMP parallelism
 
 There are two ways to run a program on multiple processors: call
 ``Control.Concurrent.setNumCapabilities`` from your program, or use the
-RTS ``-N`` option.
+RTS ``-N`` options.
 
 ``-N⟨x⟩``
+``-Nmax⟨x⟩``
+
     .. index::
        single: -N⟨x⟩; RTS option
+       single: -Nmax(x); RTS option
 
     Use ⟨x⟩ simultaneous threads when running the program.
 
@@ -133,6 +136,9 @@ RTS ``-N`` option.
     value of ⟨x⟩ itself based on how many processors are in your
     machine.
 
+    With Nmax⟨x⟩, i.e. ``+RTS -Nmax3 -RTS``, the runtime will choose at
+    most (x), also limited by the number of processors on the system.
+
     Be careful when using all the processors in your machine: if some of
     your processors are in use by other programs, this can actually harm
     performance rather than improve it.
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index 9457279..bd60591 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -391,8 +391,9 @@ usage_text[] = {
 "",
 #endif /* DEBUG */
 #if defined(THREADED_RTS) && !defined(NOSMP)
-"  -N[<n>]   Use <n> processors (default: 1, -N alone determines",
-"            the number of processors to use automatically)",
+"  -N[<n>]    Use <n> processors (default: 1, -N alone determines",
+"             the number of processors to use automatically)",
+"  -Nmax[<n>] Use up to n processors automatically",
 "  -qg[<n>]  Use parallel GC only for generations >= <n>",
 "            (default: 0, -qg alone turns off parallel GC)",
 "  -qb[<n>]  Use load-balancing in the parallel GC only for generations >= <n>",
@@ -1041,13 +1042,21 @@ error = rtsTrue;
                 } else {
                     int nNodes;
                     OPTION_SAFE; /* but see extra checks below... */
-                    nNodes = strtol(rts_argv[arg]+2, (char **) NULL, 10);
+
+                    // <=n feature request ticket #10728
+                    if (strncmp("max", &rts_argv[arg][2], 3) == 0) {
+                      int proc = (int)getNumberOfProcessors();
+                      nNodes = strtol(rts_argv[arg]+5, (char **) NULL, 10);
+                      if (nNodes > proc) { nNodes = proc; }
+                    } else {
+                      nNodes = strtol(rts_argv[arg]+2, (char **) NULL, 10);
+                    }
                     if (nNodes <= 0) {
                       errorBelch("bad value for -N");
                       error = rtsTrue;
                     }
                     if (rtsOptsEnabled == RtsOptsSafeOnly &&
-                        nNodes > (int)getNumberOfProcessors()) {
+                      nNodes > (int)getNumberOfProcessors()) {
                       errorRtsOptsDisabled("Using large values for -N is not allowed by default. %s");
                       stg_exit(EXIT_FAILURE);
                     }



More information about the ghc-commits mailing list