Commit b0283840 authored by MarcelineVQ's avatar MarcelineVQ Committed by thomie

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
parent 2cc5b607
......@@ -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.
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment