Main Content

parfevalOnAll

Run function on all workers in background

    Description

    F = parfevalOnAll(backgroundPool,fcn,numFcnOut,X1,...,Xm) schedules the function fcn to run on all workers in the background. You can run other code while MATLAB® is running the function fcn. For more information about workers and the background, see Background Workers.

    Note

    The backgroundPool has multiple workers only if you have Parallel Computing Toolbox™.

    When you use backgroundPool to run code in the background, you do not need to use parfevalOnAll to set up environment variables.

    To run a function on all workers in a parallel pool, see parfevalOnAll (Parallel Computing Toolbox).

    MATLAB asynchronously evaluates the function fcn on each worker with X1,X2,…,Xm input arguments and returns numFcnOut output arguments.

    MATLAB returns the Future object F before the function fcn finishes running on all of the background workers. You can use fetchOutputs to retrieve the results from the future. To stop running the function fcn, use the cancel function. For more information about futures, see Future.

    F = parfevalOnAll(fcn,numFcnOut,X1,...,Xm) schedules the function fcn to be run.

    MATLAB returns the Future object F before the function fcn finishes running.

    Use this syntax in code designed for use with Parallel Computing Toolbox.

    • If you do not have Parallel Computing Toolbox, you do not use any parallel resources. The function runs in serial.

    • If you have Parallel Computing Toolbox, parfevalOnAll automatically uses parallel resources.

    Input Arguments

    collapse all

    Function to run, specified as a function handle.

    Example: fcn = @magic

    Number of output arguments requested from function fcn, specified as an nonnegative integer scalar.

    numFcnOut is the number of output arguments you request when you run fcn(X1,...,Xm).

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

    Input arguments, specified as a comma-separated list of variables or expressions.

    Output Arguments

    collapse all

    Output Future, returned as a parallel.Future object.

    Extended Capabilities

    See Also

    (Parallel Computing Toolbox) | | | | | | |