0

Hi I'm using matlab parallel computing toolbox to do parallel computing. My laptop is 2 cores 4 threads, so I'm assuming the task could be connected to 4 works? However, when I type in the command "matlabpool open", only 2 workers are connected. Could anyone tell me how to specify the exact number of workers to be connected, so that I could distributed the task the the number of workers more than the number of cores to make the computation more efficiently? Thank you!

Ruby
  • 284
  • 1
  • 5
  • 18
  • 2
    You *can* use more than one worker per physical core, but you're likely see little to no effect. See [here](http://www.mathworks.com/products/matlab/choosing_hardware.html#_Hardware_Considerations) and [here](http://www.mathworks.com/matlabcentral/answers/80129-definitive-answer-for-hyperthreading-and-the-parallel-computing-toolbox-pct) for more. – horchler Aug 27 '15 at 19:23
  • 3
    possible duplicate of [Matlab: difference between Multithreading and Multicore](http://stackoverflow.com/questions/10459354/matlab-difference-between-multithreading-and-multicore) as well as [Matlabpool number of threads vs core](http://stackoverflow.com/questions/14468886/matlabpool-number-of-threads-vs-core). – horchler Aug 27 '15 at 19:25
  • @horchler I think the max number might even be version-dependent. I used to encounter a limit of 4, which is why I thought it would be related to the number of cores. R2012b has 12 as maximum for a local pool, and [R2014a allows more](http://stackoverflow.com/questions/25476287/maximum-number-of-workers-in-a-parallel-loop-local-cluster-with-matlab-r2014a) – Andras Deak -- Слава Україні Aug 27 '15 at 19:26
  • @horchler Addendum: it's a bit tricky. Asking for 16 cores gives me "`You requested a minimum of 16 workers, but only 12 workers are allowed with the Local cluster.`", but asking for 12 gives "`You requested a minimum of 12 workers, but the cluster "local" has the NumWorkers property set to allow a maximum of 4 workers`" – Andras Deak -- Слава Україні Aug 27 '15 at 19:34
  • 1
    @AndrasDeak Thank you! My matlab is R2013b. I tried more than 12 workers and it gave me the former error message. I checked the cluster profile, it says the maximum number of workers is 12. While on matlab R2014a, this upper limit goes to 512. I guess I just can't connect to more than 12 workers on the 2013 version.... – Ruby Aug 27 '15 at 19:58

1 Answers1

3

You can tell matlab to use a specific number of workers, but it won't let you use more than a maximum amount, which is probably the number of your physical cores version- and cluster-dependent. R2012b allows to use 12 workers in the local cluster, R2014a allows more than 12.

From help matlabpool:

...

matlabpool [poolSize]

...

matlabpool or matlabpool OPEN starts a worker pool using the default cluster profile with the pool size specified by that profile. You can also specify the pool size using matlabpool OPEN <poolSize>, but note that most clusters have a maximum number of processes that they can start.

% Start a worker pool using the local profile with 2 workers:
matlabpool local 2

Update:

I played around a bit. Asking for 16 workers on R2012b gives me the error

You requested a minimum of 16 workers, but only 12 workers are allowed with the Local cluster.

which means that it is impossible to have more workers with this version. However, if I call the local pool with 12 workers, I get the error

You requested a minimum of 12 workers, but the cluster "local" has the NumWorkers property set to allow a maximum of 4 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.

So, it's possible that you won't be able to use more than 12 workers, depending on your version. If you see the latter error, you can redefine your cluster to allow more cores. Duplicating the local pool:

mycluster=parcluster('local');
mycluster.NumWorkers=48;
matlabpool(mycluster,48);
...
matlabpool close;
Community
  • 1
  • 1
  • Thank you Andras! May I ask one more question: I used a server that seems to have 4 processors with 12 cores each processor. So there supposed to be 48 workers for parallel computing. But when I started matlabpool, only 12 workers are connected. Is it possible to distribute the task to all the 4 processors, so that 48 workers can be working simultaneously? Thanks! – Ruby Aug 27 '15 at 19:26
  • I edited my question after the comment of @horchler indicating that the number of cores is not the maximum. I suspect that if matlab won't allow you to manually use more than 12 cores (with an error telling you that the maximum is 12), then there's not much you can do. – Andras Deak -- Слава Україні Aug 27 '15 at 19:32