MATLAB: Parfor does not uns parallel pool when a parfeval process is still running

Parallel Computing Toolboxparfevalparfor

Dear all,
in my code I use parallel pool on a local machine and execute a longer function with 'parfeval'. In the main code I shortly later want to use 'parfor', but checking CPU work load, 'parfor' does not use any worker since 'parfeval' still uses one worker when executing 'parfor'.
Is this behaviour expected?
How to check, if there are still running processes at the parallel pool?
How to wait until all processes at the parallel pool are finished?
Thanks in advance
I am using Win10 64bit, Matlab R2020a, Parallel Computing Toolbox 7.2.

Best Answer

Yes, this behaviour is expected - the different parallel language features parfor, parfeval, and spmd do not share the pool. You can wait for all parfeval requests like so:
p = gcp('nocreate');
if ~isempty(p)
q = p.FevalQueue;
% First wait for any queued futures
wait(q.QueuedFutures);
% Then wait for any running futures
wait(q.RunningFutures);
end
(The calls to wait need to be in that order - in the other order, any queued futures will start running after the first wait).