Reputation: 33
In MATLAB, when I use the numlabs
instruction in the Command Window after calling parpool(4)
, it is 1. But, when I use the same instruction in the parallel command window it is 4, Why?
>> parpool(4)
Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers.
ans =
Pool with properties:
Connected: true
NumWorkers: 4
Cluster: local
AttachedFiles: {}
IdleTimeout: 30 minute(s) (30 minutes remaining)
SpmdEnabled: true
>> numlabs
ans =
1
>> pmode start
Starting pmode using the 'local' profile ... connected to 4 workers.
numlabs 4 4 4 4
Upvotes: 1
Views: 376
Reputation: 18494
numlabs
returns the "total number of workers operating in parallel on current job". If you type the command after starting a pool, there obviously won't be any ongoing job. Also from the numlabs
documentation:
In an spmd block, numlabs on each worker returns the parallel pool size.
However, inside a parfor-loop, numlabs always returns a value of 1.
If you just want the number of workers, you can use gcp
(get current pool):
hp = gcp;
hp.NumWorkers
Upvotes: 3
Reputation: 13945
I think that is normal behavior, since numlabs
should return 1 when not used inside a spmd
block or during a parallel job. What you have done above is only open the parallel pool, but not asking it to do a parallel job.
I can't test right now, but if you call something like this:
spmd
some statement with numlabs
end
you will see printed in the Command Window that you are indeed using the 4 available workers.
Upvotes: 2