MATLAB: 控制核心数量/线程数

4
假设我有一个程序要在拥有32个核心(64个线程)的Linux机器上运行,而我只能使用其中的10个核心(20个线程)。因此,在运行程序之前我想要指定这一点。
我搜索了谷歌并找到了 maxNumCompThreads,但是当我在MATLAB 2016a的core 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);

在具有2个核心和4个线程的计算机上,您可能会得到奇怪的结果,因为您不能使用更多/更少/ parpool(1)几乎没有意义,如果它只有1个核心,那么它不是并行池。不知道呢,只是假设。 - Ander Biguri
@AnderBiguri 非常有趣。我会看看是否有测试的方法。之后会回报。 - yurnero
@AnderBiguri 请看编辑。 parpool 在 Linux 机器上甚至都不能工作。 - yurnero
奇怪,它在Linux上应该可以工作。此外,我认为您需要能够针对每个核心提供许可证,但无法确认。 - Ander Biguri
1个回答

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时要小心,因为它是未记录的,并且容易在没有警告的情况下更改。请查看this postthis StackOverflow question以获取有关feature的更多信息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接