[R] Information on the number of CPU's

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Sep 9 21:57:23 CEST 2008

On Tue, 9 Sep 2008, tolga.i.uzuner at jpmorgan.com wrote:

> Dear R Users,
> I am on Windows XP SP2 platform, using R version 2.7.2 . I was wondering
> if there is a way to find out, within R, the number of CPU's on my machine
> ? I would use this information to set the number of nodes in a cluster,
> depending on the machine. Sys.info() and .Platform do not carry this
> information.

Correct, since

a) R does not make use of more than 1.

b) It is really not portable, and not even well-defined.  (How many CPUs 
has a hyperthreaded dual Xeon?  Some say 2, some say 4.  Do you want 
CPUs or cores?  If this is a virtualized OS, is the physical number or the 
logical number?)

In the case of Windows, how depends on the Windows version.  The w32api 
(XP or later) call GetNativeSystemInfo will tell you the number of CPUs, 
for some (unstated) definition of 'CPU'.  Later versions have 
GetLogicalProcessorInformation, which can give the number of cores.

> Thanks in advance,
> Tolga Uzuner

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list