开发者

Detect the number of cores on windows

开发者 https://www.devze.com 2023-03-13 22:15 出处:网络
If I am running R on linux or on a mac, I can detect the numbe开发者_高级运维r of available cores using multicore:::detectCores().However, there\'s no windows version of the multicore functions, so I

If I am running R on linux or on a mac, I can detect the numbe开发者_高级运维r 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?


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


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.


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.


GetSystemInfo will give you a structure that has the number of "processors", which corresponds to the total number of cores.

In theory, it will be the same value as the environment variable recommended in another answer, but the user can tamper with (or delete) the environment variable. That can be a bug or a feature depending on your intent.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号