I have Matlab R2012b for Ubuntu 64 bits. I have a Intel Core i3 CPU M 330 @ 2.13GHz × 4.
我有Matlab R2012b的Ubuntu 64位。我有一个英特尔酷睿i3 330 @ 2.13 ghz CPU米×4。
I want to use parfor to parallelize 4 loops at same time. Because Intel Core i3 has 2 Cores and 4 Threads I use this code:
我想用parfor同时并行化4个循环。因为Intel Core i3有2个内核和4个线程,所以我使用这段代码:
if matlabpool('size') == 0 % checking to see if my pool is already open
matlabpool(4)
else
matlabpool close
matlabpool(4)
end
And I obtain the following error:
我得到以下误差:
Error:
错误:
You requested a minimum of 4 workers, but the cluster "local" has the NumWorkers property set to allow a maximum of 2 workers. To run a communicating job on more workers than this (up to a maximum of 12 for the Local cluster), increase the value of the NumWorkers property for the cluster. The default value of NumWorkers for a Local cluster is the number of cores on the local machine.
您要求最少4个工人,但是集群“local”具有NumWorkers属性,允许最多2个工人。要在更多的工作人员上运行通信作业(本地集群最多为12个),增加集群的NumWorkers属性的值。对于本地集群,numworker的默认值是本地机器上的核数。
Why? The default value of NumWorkers in my machine is 2 but if I can do 4 loops at the same time, how do I get it?
为什么?NumWorkers在我的机器中的默认值是2但如果我能同时做4个循环,我怎么得到它?
2 个解决方案
#1
8
To increase the default NumWorkers
, open the Cluster Profile Manager (Parallel->Manage Cluster Profiles). Pick the local
profile, click edit, and increase NumWorkers
to the maximum possible value (in your case 4). Now it is possible to create a matlabpool
with more workers than physical cores on your machine.
要增加默认的numworker,打开集群概要管理器(Parallel->Manage Cluster概要)。选择localprofile,单击edit,并将numworker增加到最大可能的值(在您的例子4中),现在可以创建一个包含比机器上的物理内核更多的worker的matlabpool。
However, note that using more workers than cores might lead to decreased performance as compared to having the same number of workers as cores.
然而,请注意,与拥有与内核相同的工作人员数量相比,使用更多的工作人员可能会导致性能下降。
#2
8
To programmatically change the value of NumWorkers
from 2 to 4 of the local
cluster profile, you can use:
要以编程方式将NumWorkers的值从本地集群概要文件的2更改为4,您可以使用:
myCluster = parcluster('local');
myCluster.NumWorkers = 4; % 'Modified' property now TRUE
saveProfile(myCluster); % 'local' profile now updated,
% 'Modified' property now FALSE
#1
8
To increase the default NumWorkers
, open the Cluster Profile Manager (Parallel->Manage Cluster Profiles). Pick the local
profile, click edit, and increase NumWorkers
to the maximum possible value (in your case 4). Now it is possible to create a matlabpool
with more workers than physical cores on your machine.
要增加默认的numworker,打开集群概要管理器(Parallel->Manage Cluster概要)。选择localprofile,单击edit,并将numworker增加到最大可能的值(在您的例子4中),现在可以创建一个包含比机器上的物理内核更多的worker的matlabpool。
However, note that using more workers than cores might lead to decreased performance as compared to having the same number of workers as cores.
然而,请注意,与拥有与内核相同的工作人员数量相比,使用更多的工作人员可能会导致性能下降。
#2
8
To programmatically change the value of NumWorkers
from 2 to 4 of the local
cluster profile, you can use:
要以编程方式将NumWorkers的值从本地集群概要文件的2更改为4,您可以使用:
myCluster = parcluster('local');
myCluster.NumWorkers = 4; % 'Modified' property now TRUE
saveProfile(myCluster); % 'local' profile now updated,
% 'Modified' property now FALSE