MATLAB: Does SPMD always use all cores

coresparallel computingparforspmd

So far as I know, parfor will not use all available cores if Matlab considers the task as not sufficiently heavy.
But does SPMD always use all available cores even if the task is small? It seems to me YES as far as I have tried.
I am working on the shared memory system. Due to the memory restriction, I cannot increase the size of each sub-task in order to increase the computational load. If SPMD can use all the cores regardless of the computational load, then it will be probably more suitable in my case, as SPMD will then not waste the computational ability of the hardwares. But if I finally resort to SPMD, then I will have to make a certain amount of changes to my code.
Any opinions are appreciated. Thank you.

Best Answer

spmd blocks by default use all the workers in your parallel pool. You can make an spmd block use fewer workers by specifying the optional argument, like so
parpool('local', 4);
spmd(2)
assert(numlabs == 2);
end
Related Question