I have a Core i7
CPU and 4 real cores
. Can I have more than 4 workers
for my computation or the number of workers are always equal to the cores number?
Thanks.
You will be able to have 8 workers, because the 4 cores have hyper threading, giving you 8 logical cores. But, because there are only 4 physical cores, 8 workers shouldn't be much faster than 4 workers in theory. However, I did find that 6 and 8 workers were faster than 4 on my i7.
To do this try
matlabpool open 8;
parfor I = 1:N
#your code
end
EDIT: in R2014a matlabpool
is being replaced with parpool
, so use this instead:
parpool('local', 8);
parfor I = 1:N
#your code
end
to open 8 cores on your local machine.
Note: you only need to run the matlabpool
command once, when Matlab starts up. Then you can run many scripts with parfor loops in them without opening the workers again, they will stay open until you close them or close Matlab.
This should open 8 workers on your local system.
If you get an error about the number of available workers then you need to change a setting: Parallel menu -> Manage Configurations. Right-click on the "local" line. In the scheduler tab, set the "Number of workers available to scheduler" to 8.
Finally, you can only have one pool of workers open at a time, use this:
poolobj = gcp('nocreate');
delete(poolobj);
to close an open pool. Then you can try and open another pool with more workers.