I have an i7-M620 processor that have 2 physical cores and 2 threads (multi-threaded CPU) per core (a total of 4 threads). When I use the MATLAB Parallel Computing Toolbox,
I got around this (with my core i5 with 2 cores and 4 threads) by editing the "local" configuration for the parallel computing stuff:
Parallel->Manage Cluster Profiles
Validate
the local
profile before changing anything.edit
and change the NumWorkers
variable to suit your needs.Then you can start matlabpool
like this:
matlabpool local
Note I have never gotten a speedup using parfor
. Matlab's overhead has always outweighed the benefits. What I'm saying is: benchmark your code first, then decide if parfor
(or other parallel stuff) works for you or not.
For a parallel configuration, this is the error thrown when requesting more workers than the default:
The default value of
NumWorkers
for a local cluster is the number of cores on the local machine. To run a communicating job on more workers than this , increase the value of the NumWorkers property for the cluster.
You can remedy that by modifying the 'local'
profile cluster properties, that effectively control the default number. From PCT R2013a documentation:
myCluster = parcluster('local');
myCluster.NumWorkers = 4; % 'Modified' property now TRUE
saveProfile(myCluster); % 'local' profile now updated,
% 'Modified' property now FALSE
Then matlabpool open
will give you the (default) num. of workers, while matlabpool(n)
will give you n
workers, up to the above set maximum/default (n<=4
). You can check the number of currently open workers by:
matlabpool('size')
or from the indicator icon at the lower-right corner of your desktop, e.g. .
My desktop station has one i7-2600 CPU, and the OS is the newest Linux Mint. I have tested parallel computing of MATLAB 2012b, which by default the NumWorker is 4 (the core number of i7-2600), I modified the local cluster profile to be 8 of the value of NumWorker, then I did the comparison with the workers setting to be 4 and 8 (just as @rubenvb posted).
The results show that in the serial mode, the time consuming is about 429 sec, while in the parallel mode (with matlabpool open 4) the time consuming is about 254 sec and 218 sec for 8 workers, i.e. boosted by 40.79% and 49.18%, respectively.
And I further investigated my code carefully, and found that inside the parallel body, MATLAB vectorization optimization is also implemented, i.e. extra CPU resource is required for such kind of boosting, thus for the NumWorkers of 8 case (i.e. hyper-thread enabled), it do not have enough idle CPU resource to boost vectorization, in some degree it is CPU resource competition, which reduce the parallel efficiency. This is also the reason that when NumWorkers of 4 almost with the equal boosting efficiency.
The conclusion is that parallel computation in MATLAB is quit helpful and simply to implement but should be used carefully, this is all my personal opinion.