检测windows上的核心数
如果我在 Linux 或 Mac 上运行 R,我可以使用 multicore:::detectCores()
检测可用内核的数量。但是,没有 Windows 版本的多核功能,因此我无法在 Windows 上使用此技术。
如何从 R 中以编程方式检测 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
并行包现在有一个检测核心数量的函数:
parallel:::detectCores()
。The parallel package now has a function to detect the number of cores:
parallel:::detectCores()
.此线程 有许多建议,包括:
另请注意 Ripley 教授在该帖子中的帖子,其中谈到了这样做的困难。
This thread has a number of suggestions, including:
Note also the posting in that thread by Prof. Ripley which talks to the difficulties of doing this.
如果您确实需要区分实际的内核、芯片和逻辑处理器,则要调用的 API 为 获取逻辑进程信息
GetSystemInfo 如果只是想知道有多少个逻辑处理器一台机器(对于超线程没有区别。)。
我无法理解你如何从“R”中称呼它。但我猜想 R 具有从本机 Windows DLL 调用代码的功能。
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 将为您提供一个结构,有“处理器”的数量,它对应于核心的总数。
理论上,它将与另一个答案中推荐的环境变量的值相同,但用户可以篡改(或删除)环境变量。这可能是一个错误或一个功能,具体取决于您的意图。
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.