Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect the number of cores on windows

If I am running R on linux or on a mac, I can detect the number of available cores using multicore:::detectCores(). However, there's no windows version of the multicore functions, so I can't use this technique on windows.

How can I programmatically detect the number of cores on a windows machine, from within R?

like image 562
Zach Avatar asked Jun 17 '11 17:06

Zach


3 Answers

The parallel package now has a function to detect the number of cores: parallel:::detectCores().

like image 125
Zach Avatar answered Oct 15 '22 02:10

Zach


This thread has a number of suggestions, including:

Sys.getenv('NUMBER_OF_PROCESSORS')

Note also the posting in that thread by Prof. Ripley which talks to the difficulties of doing this.

like image 13
Gavin Simpson Avatar answered Oct 15 '22 03:10

Gavin Simpson


If you actually need to distinguish between actual cores, chips, and logical processors, the API to call is GetLogicalProcessInformation

GetSystemInfo if just want to know how many logical processors on a machine (with no differentiation for hyperthreading.).

How you call this from "R" is beyond me. But I'd guess R has a facility for invoking code from native Windows DLLs.

like image 3
selbie Avatar answered Oct 15 '22 02:10

selbie