MATLAB: How to determine number of workers

MATLABparallel computing

Let's say I have a parfor loop that contains N iterations (parfor ind = 1:N), which contains N independent calculations that I need. In this case, how can I determine the number of workers I shall call in the batch command [batch(@job, 'pool', M)]?
(1) Is it desirable to always have M = N? (2) What happens if M < N? Am I correct that in this case the remote cluster will run the first M jobs in parallel, and then go to the next M jobs, etc?
Thanks!

Best Answer

The number of workers in your batch parallel pool should not exceed the number of loop iterations, i.e. it is not useful to make M > N. However, if you have more loop iterations than workers, each worker will simply process multiple iterations. (This is exactly the same behaviour as when you create an interactive parallel pool using parpool(M)).