Alternative for matlabpool

2020-05-06 22:50发布

I am trying to use someone else's code and there is this line in it:

if (m<100) || (matlabpool('size')==0)

I am using MATLAB R2016a, so this command fails. What is the equivalent of matlabpool('size') in the new version?

I know that matlabpool is replaced by parpool. But what does matlabpool('size') do specifically? It doesn't actually create the parallel workers.

1条回答
We Are One
2楼-- · 2020-05-06 23:49

As per the change log:

matlabpool function removed The matlabpool function has been removed. Compatibility Considerations Calling matlabpool now generates an error. You should instead use parpool to create a parallel pool.

matlabpool('size') does exactly what you'd expect it to do: it gives you the size of the current pool, i.e. the amount of workers assigned to it. gcp (GetCurrentPool) does this for you. Its documentation's first example:

p = gcp('nocreate'); % If no pool, do not create new one.
if isempty(p)
    poolsize = 0;
else
    poolsize = p.NumWorkers
end
查看更多
登录 后发表回答