Verify that parallel functions can use a parallel pool
returns a logical
value indicating if parallel functions can create and use a parallel pool.
tf = canUseParallelPool()
The function returns logical
Parallel Computing Toolbox™ is installed and licensed for use, a default parallel pool is configured and
supported, and automatic creation of parallel pools is enabled. Otherwise, the function
false). This function does not
create a parallel pool.
canUseParallelPool to check if parallel functions such as
parfor (Parallel Computing Toolbox) and
parfeval (Parallel Computing Toolbox) can use a parallel pool. This enables you to avoid executing code
that requires a parallel pool if one is not available.
Even if this function returns true, you can still receive an error when you try to create a parallel pool if your parallel cluster is not properly configured or cannot be contacted.
Verify that you can use a parallel pool before executing code that runs in parallel. If a pool is not available, run the code in serial.
N=100; if canUseParallelPool f(1:N) = parallel.FevalFuture; for i = 1:N f(i) = parfeval(@rank,1,magic(i)); end results = fetchOutputs(f); else results = zeros(1,N); for i = 1:N results(i) = rank(magic(i)); end end
canUseParallelPool returns true, then
parfeval creates a parallel pool and the code runs in parallel.
Otherwise, the code runs in a normal