Main Content

parfevalOnAll

所有工人在异步执行函数parallel pool

Description

F= parfevalOnAll(p,fcn,numout,in1,in2,...)requests the asynchronous execution of the functionfcnon all workers in the parallel poolp.parfevalOnAllevaluatesfcnon each worker with input argumentsin1,in2,..., and expectsnumoutoutput arguments.Fis aFutureobject, from which you can obtain the results when all workers have completed executingfcn.

example

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.

Note

UseparfevalOnAllinstead ofparfororspmdif you want to useclear. This preserves workspace transparency. SeeEnsure Transparency in parfor-Loops or spmd Statements.

Examples

collapse all

Unload amexfile before deleting temporary folders for distributing simulations, using theclearfunction. Becauseclearhas0output arguments, specify0in thenumoutinput argument ofparfevalOnAll.

parfevalOnAll(@clear,0,'mex');

Close all Simulink models on all workers:

p = gcp();% Get the current parallel poolf = 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);

Input Arguments

collapse all

Parallel pool of workers, specified as aparallel.Poolobject. You can create a parallel pool by using theparpoolfunction.

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 fromfcn.

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

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

Output Arguments

collapse all

Future object, returned as aparallel.FevalOnAllFuture, that represents the execution offcnon the parallel workers and holds their results. UsefetchOutputsto collect the results.

Extended Capabilities

Version History

Introduced in R2013b

expand all

Behavior changed in R2021b