如何从 MATLAB 查询物理核心数?
有谁知道如何从 MATLAB 查询物理核心的数量?我特别想获取物理核心而不是逻辑核心的数量(启用超线程时可能会有所不同)。
我需要该方法是跨平台的(Windows 和 Linux,不关心 Mac),但我很乐意根据 < 的输出使用带有 switch
语句的两个单独的方法。代码>计算机。
到目前为止,我已经尝试过:
java.lang.Runtime.getRuntime().availableProcessors
System.Environment.ProcessorCount
!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:
java.lang.Runtime.getRuntime().availableProcessors
System.Environment.ProcessorCount
!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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用未记录的命令
,如下所述:http://undocumentedmatlab.com/blog/undocumented -特征功能/
You need to use the undocumented command
as explained here: http://undocumentedmatlab.com/blog/undocumented-feature-function/
这会起作用
This will work
您可以使用函数
maxNumCompThreads
。然而它已被弃用。它仍然可以在 Matlab 2011a 上运行。You can use the function
maxNumCompThreads
. However it's deprecated. Still it works on Matlab 2011a.