From 3b5940fd32df31b56c1ab6891b0a8f338e796049 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Fri, 13 Mar 2009 11:46:46 +0000 Subject: [PATCH] Add "+RTS -N" to determine the -N value automatically (see #1741) --- docs/users_guide/using.xml | 16 +++++++++++++--- rts/RtsFlags.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/users_guide/using.xml b/docs/users_guide/using.xml index 20bb687..f769d28 100644 --- a/docs/users_guide/using.xml +++ b/docs/users_guide/using.xml @@ -1834,7 +1834,7 @@ f "2" = 2 - + RTS option Use x simultaneous threads when @@ -1846,9 +1846,19 @@ f "2" = 2 on a dual-core machine we would probably use +RTS -N2 -RTS. + Omitting x, + i.e. +RTS -N -RTS, lets the runtime + choose the value of x itself + based on how many processors are in your machine. + + 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. + Setting also has the effect of - setting (the number of OS threads to - use for garbage collection) to the same value. + enabling the parallel garbage collector (see + ). There is no means (currently) by which this value may vary after the program has started. diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c index 8690040..cbc2bb5 100644 --- a/rts/RtsFlags.c +++ b/rts/RtsFlags.c @@ -17,6 +17,14 @@ #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#ifdef HAVE_WINDOWS_H +#include +#endif + #include #include @@ -454,7 +462,8 @@ usage_text[] = { "", #endif /* DEBUG */ #if defined(THREADED_RTS) && !defined(NOSMP) -" -N Use OS threads (default: 1)", +" -N Use processors (default: 1)", +" -N Determine the number of processors to use automatically", " -q1 Use one OS thread for GC (turns off parallel GC)", " -qg Use parallel GC only for generations >= (default: 1)", " -qm Don't automatically migrate threads between CPUs", @@ -1138,7 +1147,23 @@ error = rtsTrue; #if defined(THREADED_RTS) && !defined(NOSMP) case 'N': THREADED_BUILD_ONLY( - if (rts_argv[arg][2] != '\0') { + if (rts_argv[arg][2] == '\0') { +#if defined(PROFILING) + RtsFlags.ParFlags.nNodes = 1; +#else +#if defined(mingw32_HOST_OS) + { + SYSTEM_INFO si; + GetSystemInfo(&si); + RtsFlags.ParFlags.nNodes = si.dwNumberOfProcessors; + } +#elif defined(HAVE_SYSCONF) + RtsFlags.ParFlags.nNodes = sysconf(_SC_NPROCESSORS_CONF); +#else + RtsFlags.ParFlags.nNodes = 1; +#endif +#endif + } else { RtsFlags.ParFlags.nNodes = strtol(rts_argv[arg]+2, (char **) NULL, 10); if (RtsFlags.ParFlags.nNodes <= 0) { -- 1.7.10.4