windows 检测windows上的内核数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6389334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect the number of cores on windows
提问by Zach
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.
如果我在 linux 或 mac 上运行 R,我可以使用multicore:::detectCores()
. 但是,没有 Windows 版本的多核函数,所以我不能在 Windows 上使用这种技术。
How can I programmatically detect the number of cores on a windows machine, from within R?
如何从 R 中以编程方式检测 Windows 机器上的内核数?
回答by Zach
The parallel package now has a function to detect the number of cores: parallel:::detectCores()
.
并行包现在具有检测内核数的功能:parallel:::detectCores()
.
回答by Gavin Simpson
回答by selbie
If you actually need to distinguish between actual cores, chips, and logical processors, the API to call is GetLogicalProcessInformation
如果你真的需要区分实际的内核、芯片和逻辑处理器,调用的API是GetLogicalProcessInformation
GetSystemInfoif just want to know how many logical processors on a machine (with no differentiation for hyperthreading.).
GetSystemInfo如果只想知道一台机器上有多少个逻辑处理器(不区分超线程。)。
How you call this from "R" is beyond me. But I'd guess R has a facility for invoking code from native Windows DLLs.
你如何从“R”中称呼它超出了我的范围。但我猜想 R 具有从本机 Windows DLL 调用代码的功能。
回答by Adrian McCarthy
GetSystemInfowill give you a structure that has the number of "processors", which corresponds to the total number of cores.
GetSystemInfo将为您提供一个具有“处理器”数量的结构,该数量对应于内核总数。
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.
理论上,它会与另一个答案中推荐的环境变量相同的值,但用户可以篡改(或删除)环境变量。根据您的意图,这可能是错误或功能。