Detect the number of cores on windows

余生长醉 提交于 2019-12-03 02:14:43

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!