Execute function asynchronously on all workers in parallel pool


F = parfevalOnAll(p,fcn,numout,in1,in2,...) requests the asynchronous execution of the function fcn on all workers in the parallel pool p. parfevalOnAll evaluates fcn on each worker with input arguments in1,in2,..., and expects numout output arguments. F is a parallel.FevalOnAllFuture object, from which you can obtain the results when all workers have completed executing fcn.


F = parfevalOnAll(fcn,numout,in1,in2,...) 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.


Use parfevalOnAll instead of parfor or spmd if you want to use clear. This preserves workspace transparency. See Ensure Transparency in parfor-Loops or spmd Statements.


collapse all

Unload a mex file before deleting temporary folders for distributing simulations, using the clear function. Because clear has 0 output arguments, specify 0 in the numout input argument of parfevalOnAll.


Close all Simulink models on all workers:

p = gcp(); % Get the current parallel pool
f = parfevalOnAll(p,@bdclose,0,'all');
% No output arguments, but you might want to wait for completion

Input Arguments

collapse all

Parallel pool of workers, specified as a parallel.Pool object. You can create a parallel pool by using the parpool function.

Data Types: parallel.Pool

Function to execute on the workers, specified as a function handle.

Example: fcn = @sum

Data Types: function_handle

Number of output arguments that are expected from fcn.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Function arguments to pass to fcn, specified as a comma-separated list of variables or expressions.

Output Arguments

collapse all

Future object, returned as a parallel.FevalOnAllFuture, that represents the execution of fcn on the parallel workers and holds their results. Use fetchOutputs to collect the results.

Introduced in R2013b