检测windows上的核心数

发布于 2024-11-16 03:01:56 字数 171 浏览 6 评论 0原文

如果我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

人间☆小暴躁 2024-11-23 03:01:56

并行包现在有一个检测核心数量的函数:parallel:::detectCores()

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

緦唸λ蓇 2024-11-23 03:01:56

线程 有许多建议,包括:

Sys.getenv('NUMBER_OF_PROCESSORS')

另请注意 Ripley 教授在该帖子中的帖子,其中谈到了这样做的困难。

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.

悲欢浪云 2024-11-23 03:01:56

如果您确实需要区分实际的内核、芯片和逻辑处理器,则要调用的 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.

辞取 2024-11-23 03:01:56

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文