Main Content

pctRunOnAll

Run command on client and on all workers in parallel pool

    Description

    example

    pctRunOnAll command runs the specified command on all the workers in the parallel pool and on the client. The function also prints any command-line output in the client Command Window. The specified command runs in the workspace of the workers and does not return any variables. Use this function to perform any setup changes on all the workers in the parallel pool and the client.

    Note

    If you use pctRunOnAll to run commands that modify the MATLAB® search path in a mixed-platform environment, the commands can generate a warning on the client while executing properly on the workers. For example, if your workers are all running on a Linux® operating system and your client is running on a Microsoft® Windows® operating system, an addpath command with Linux-compatible paths warns on the Windows-based client.

    Examples

    collapse all

    Use the pctRunOnAll function to run commands on the client and all workers.

    Clear all loaded functions on the client and all workers.

    pctRunOnAll clear functions

    Change the working folder on the client and all workers to the project folder.

    pctRunOnAll cd /opt/projects/c1456

    Add folders to the paths of the client and all workers.

    pctRunOnAll addpath({"/usr/share/path1" "/usr/share/path2"})

    Use the system command to execute the system command hostname on the client and all the workers. Return the output in cmdout.

    pctRunOnAll [~,cmdout] = system("hostname")

    Input Arguments

    collapse all

    MATLAB command to run, specified as a MATLAB command with any necessary input and output arguments.

    Example: clear functions

    Limitations

    • pctRunOnAll does not support thread-based pools, such as those you create by calling parpool("Threads") and backgroundPool.

    Alternative Functionality

    Alternatively, to modify the MATLAB search path in a mixed-platform environment, use the parfevalOnAll function to run commands on only the workers.

    Version History

    Introduced in R2008a