假设我有一个程序要在具有32个核心(64个线程)的linux机器上运行,其中我只允许使用10个核心(20个线程)。所以我想在运行程序之前指定它。
我用Google搜索并找到了maxNumCompThreads
但是当我在使用MATLAB 2016a,核心i5( 2核,4个线程)的计算机上进行测试时,它似乎无法正常工作。也就是说,当我执行以下任何操作时,我得到feature('numCores')
的相同输出
maxNumCompThreads(1)
maxNumCompThreads(2)
maxNumCompThreads(4)
maxNumCompThreads('Automatic')
然后我尝试parpool
(每次我用delete(gcp('nocreate'))
关闭当前的parpool会话时)。运行parpool(4)
时遇到错误(我想我理解为什么:parpool
接受内核数量并自动启用超线程,测试机器只有2个物理内核)。所以我使用parpool(1)
和parpool(2)
进行了测试。同样,feature('numCores')
的输出不更改。
问题:那么对于上述第一段所述情况的工作来说,什么是正确的工具? feature('numCores')
是否是正确的监控工具,以确定相应的规范是否有效?
我上面提到的feature('numCores')
输出相同的是:
MATLAB detected: 2 physical cores.
MATLAB detected: 4 logical cores.
MATLAB was assigned: 4 logical cores by the OS.
MATLAB is using: 2 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
编辑:当我在linux机器上运行parpool(10)
时出现以下错误
Starting parallel pool (parpool) using the 'local' profile ... Error using parpo ol (line 103)
Couldn't interpret output from psname.sh: ""
Error in parpool_test_2016_10_03 (line 3)
parpool(10);
答案 0 :(得分:0)
不,这不是正确的监控工具。请改为feature('numthreads')
:
>> feature('numcores')
MATLAB detected: 4 physical cores.
MATLAB detected: 8 logical cores.
MATLAB was assigned: 8 logical cores by the OS.
MATLAB is using: 4 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
ans =
4
>> feature('numthreads')
ans =
4
>> maxNumCompThreads(1)
ans =
4
>> feature('numcores')
MATLAB detected: 4 physical cores.
MATLAB detected: 8 logical cores.
MATLAB was assigned: 8 logical cores by the OS.
MATLAB is using: 4 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
ans =
4
>> feature('numthreads')
ans =
1
一般情况下,请谨慎使用feature
,因为它没有文档记录,并且在没有警告的情况下容易更改。有关feature
的详细信息,请查看this post和this StackOverflow question。