MATLAB: Parallel pool sizing for a parfor loop

parallel computingparfor

I run a parfor loop on an 8 cores workstation.
This loop is parfor i = 1:10 and the work in each iteration is substantial.
MATLAB automatically creates 8 workers.
Assuming that each iteration takes about the same time to complete, is this highly inefficient? I'm thinking that the 8 cores finish at about the same time, and then only 2 are assigned to the remaining 2 iterations.
Then again, I don't really understand the idea of parallel pools. How would I optimise the size?

Best Answer

Based on my own personal experience, the choice of the parpool size can be optimized only through experimentation. I have found that too many workers can be as counter-productive as too few, even when the selected pool size doesn't exceed the number of physical cores. There is an optimal middle ground that only experimentation allowed me to find.
Granted, this was a few years and a few MATLAB versions ago, and may have been a platform-dependent thing anyway... To be honest, I'm a bit surprised to hear that people still use parfor, given the time needed to launch a parpool. I use gpuArray all the time, but starting a parpool takes as long as most of the jobs I would like to accelerate.