如何从 MATLAB 查询物理核心数?

发布于 2024-12-18 16:53:24 字数 629 浏览 2 评论 0原文

有谁知道如何从 MATLAB 查询物理核心的数量?我特别想获取物理核心而不是逻辑核心的数量(启用超线程时可能会有所不同)。

我需要该方法是跨平台的(Windows 和 Linux,不关心 Mac),但我很乐意根据 < 的输出使用带有 switch 语句的两个单独的方法。代码>计算机。

到目前为止,我已经尝试过:

  1. java.lang.Runtime.getRuntime().availableProcessors
  2. System.Environment.ProcessorCount
  3. !wmic cpu get NumberOfCores!wmic cpu 获取 NumberOfLogicalProcessors

1 是跨平台的,但返回逻辑处理器的数量而不是物理处理器的数量。

2 仅适用于 Windows,并且还返回逻辑处理器而不是物理处理器。

3 提供了物理和逻辑处理器,但也仅限于 Windows,虽然我可以从 DOS 命令窗口成功使用它,但由于某种原因,当从 MATLAB 运行时,它似乎永远挂起。

Does anyone know of a way to query the number of physical cores from MATLAB? I would specifically like to get the number of physical rather than logical cores (which can differ when hyperthreading is enabled).

I need the method to be cross-platform (Windows and Linux, don't care about Mac), but I'd be happy to use two separate methods with a switch statement based on the output of computer.

So far I've tried:

  1. java.lang.Runtime.getRuntime().availableProcessors
  2. System.Environment.ProcessorCount
  3. !wmic cpu get NumberOfCores and !wmic cpu get NumberOfLogicalProcessors.

1 is cross-platform, but returns the number of logical rather than physical processors.

2 is Windows only, and also returns logical rather than physical processors.

3 gives both physical and logical processors, but is also Windows only, and although I can use it successfully from the DOS command window, for some reason it seems to hang for an eternity when run from MATLAB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

樱桃奶球 2024-12-25 16:53:24

您需要使用未记录的命令

feature('numcores')

,如下所述:http://undocumentedmatlab.com/blog/undocumented -特征功能/

You need to use the undocumented command

feature('numcores')

as explained here: http://undocumentedmatlab.com/blog/undocumented-feature-function/

无戏配角 2024-12-25 16:53:24

这会起作用

getenv('NUMBER_OF_PROCESSORS')

This will work

getenv('NUMBER_OF_PROCESSORS')
默嘫て 2024-12-25 16:53:24

您可以使用函数maxNumCompThreads。然而它已被弃用。它仍然可以在 Matlab 2011a 上运行。

maxNumCompThreads
Warning: maxNumCompThreads will be removed in a future release. Please remove any
instances of this function from your code. 
> In maxNumCompThreads at 27

ans =

     4

You can use the function maxNumCompThreads. However it's deprecated. Still it works on Matlab 2011a.

maxNumCompThreads
Warning: maxNumCompThreads will be removed in a future release. Please remove any
instances of this function from your code. 
> In maxNumCompThreads at 27

ans =

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