Matlabpool线程数与内核数 [英] Matlabpool number of threads vs core

查看:270
本文介绍了Matlabpool线程数与内核数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台笔记本电脑在Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz上运行Ubuntu.根据上述处理器的Intel网站(位于

I have a laptop running Ubuntu on Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz. According to Intel website for the above processor (located here), this processor has two cores and can run 4 threads at a time in parallel (because although it has 2 physical cores it has 4 logical cores).

当我启动matlabpool时,它以local配置开始,并说它已连接到2个实验室.我想这意味着它可以并行运行2个线程.是否不知道CPU实际上可以并行运行4个线程?

When I start matlabpool it starts with local configuration and says it has connected to 2 labs. I suppose this means that it can run 2 threads in parallel. Does it not know that the CPU can actually run 4 threads in parallel?

推荐答案

根据我的经验,matlabpoollocal配置默认情况下使用计算机拥有的物理核心数量,而不是逻辑数量核心.因此,在您的计算机上,matlabpool仅连接到两个实验室.

In my experience, the local configuration of matlabpool uses, by default, the number of physical cores a machine possesses, rather than the number of logical cores. Hence on your machine, matlabpool only connects to two labs.

但是,这只是一个设置,可以用以下命令覆盖:

However, this is just a setting and can be overwritten with the following command:

matlabpool poolsize n

其中n是1到12之间的整数,表示您希望Matlab使用的实验室数量.

where n is an integer between 1 and 12 denoting the number of labs you want Matlab to use.

现在,有了@RodyOldenhuis在评论中提供的快速课程,我们可以更好地回答这一点.

Now we get to the interesting bit that I'm a bit better equipped to answer thanks to a quick lesson from @RodyOldenhuis in the comments.

超线程意味着给定的物理内核可以同时运行两个线程.当然,它们实际上不能同时处理.这个想法更像是这样:如果线程之一在将任务分配给核心方面效率低下,那么核心可能会表现出一些停机时间".第二个线程可以利用此停机时间"完成一些工作.

Hyper-threading implies a given physical core can have two threads run through it at the same time. Of course, they can't literally be processed simultaneously. The idea goes more like this: If one of the threads is inefficient in allocating tasks to the core, then the core may exhibit some "down-time". A second thread can take advantage of this "down-time" to get some work done.

以我的经验,Matlab在将线程分配给内核方面通常很高效,因此,如果有一个Matlab线程(即一个实验室)运行,则内核可能只有很少的停机时间",因此会有非常多的停机时间.超线程的优势不大.我的桌面是一个Core-i7,具有4个物理核心但有8个逻辑核心.但是,我注意到在运行4个实验与8个实验的parfor循环之间几乎没有什么区别.实际上,由于初始化额外的实验室会产生启动费用,因此8个实验室的速度通常会变慢.

In my experience, Matlab is often efficient in its allocation of threads to cores, therefore with one Matlab thread (ie one lab) running through it, a core may have very little "down-time" and hence there will be very little advantage to hyper-threading. My desktop is a core-i7 with 4 physical cores but 8 logical cores. However, I notice very little difference between running a parfor loop with 4 labs versus 8 labs. In fact, 8 labs is often slower due to the start-up costs associated with initializing the extra labs.

当然,这可能会因其他外部因素而变得复杂,例如您可能同时在Matlab上运行的其他程序.

Of course, this is probably all complicated by other external factors such as what other programs you might be running simultaneously to Matlab too.

总而言之,我的怀疑是,即使您可以强制Matlab初始化4个实验室(甚至12个实验室),您也不会在2个实验室中看到太多提速,因为Matlab通常在分配方面相当高效任务交给处理器.

In summary, my suspicion is that even though you could force Matlab to initialize 4 labs (or even 12 labs), you won't see much of a speed-up over 2 labs, since Matlab is generally fairly efficient at allocating tasks to the processor.

这篇关于Matlabpool线程数与内核数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆