Execute function asynchronously on all workers in parallel pool
requests the asynchronous execution of the function
F = parfevalOnAll(
fcn on all workers in
the parallel pool
fcn on each worker with input arguments
in2,..., and expects
numout output arguments.
F is a
from which you can obtain the results when all workers have completed executing
requests asynchronous execution on all workers in the current parallel pool. If no pool
exists, it starts a new parallel pool, unless your parallel preferences disable automatic
creation of pools.
F = parfevalOnAll(
parfevalOnAll instead of
spmd if you want to use
clear. This preserves workspace transparency. See Ensure Transparency in parfor-Loops or spmd Statements.
Run Functions on All Workers
mex file before deleting temporary folders for
distributing simulations, using the
clear function. Because
0 output arguments, specify
0 in the
numout input argument of
Close all Simulink models on all workers:
p = gcp(); % Get the current parallel pool f = parfevalOnAll(p,@bdclose,0,'all'); % You might want to wait for completion and check for success even if you do not request output arguments. % To do this, call fetchOutputs on the future and check for errors from the workers. fetchOutputs(f);
p — Parallel pool
Parallel pool of workers, specified as a
parallel.Pool object. You
can create a parallel pool by using the
fcn — Function to execute
Function to execute on the workers, specified as a function handle.
fcn = @sum
numout — Number of output arguments
Number of output arguments that are expected from
in1,in2,... — Function arguments
comma-separated list of variables or expressions
Function arguments to pass to
fcn, specified as a
comma-separated list of variables or expressions.
F — Future
Future object, returned as a
represents the execution of
fcn on the parallel workers and holds
their results. Use
fetchOutputs to collect the results.
Automatic Parallel Support
Accelerate code by automatically running computation in parallel using Parallel Computing Toolbox™.
Usage notes and limitations:
parfevalOnAll(fcn,n,X1,...,Xm)has automatic parallel support if you have Parallel Computing Toolbox™.
For more information, see Run MATLAB Functions with Automatic Parallel Support.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version HistoryIntroduced in R2013b
parfevalOnAll can now run in serial with no pool
Starting in R2021b, you can now run
parfevalOnAll in serial with no pool. This behavior allows you to share
parallel code that you write with users who do not have Parallel Computing Toolbox.
When you use the syntax
parfevalOnAll(fcn,n,X1,...,Xm), MATLAB® tries to use an open parallel pool if you have Parallel Computing Toolbox. If a parallel pool is not open, MATLAB will create one if automatic pool creation is enabled.
If parallel pool creation is disabled or if you do not have Parallel Computing Toolbox, the function is evaluated in serial. In previous releases, MATLAB threw an error instead.