Main Content

createCommunicatingJob

Create communicating job on cluster

    Description

    example

    j = createCommunicatingJob(cluster) creates a communicating job object for the identified cluster.

    j = createCommunicatingJob(___,Name=Value) also specifies communicating job object properties using one or more name-value arguments.

    For a list of supported object properties, see parallel.Job. In most cases, the values you specify override the values in the cluster profile. If you specify AttachedFiles or AdditionalPaths, the software combines the values with the values in the applicable profile. If you specify an invalid property name or value, the software does not create an object.

    j = createCommunicatingJob(___,Type=jobType) specifies the communicating job type as pool or spmd. A pool job runs the specified task function with an available parallel pool. An spmd job runs the specified task function simultaneously on all workers, and you can use spmd* functions for communication between workers.

    j = createCommunicatingJob(___,Profile=profileName) creates a communicating job object with the property values corresponding to the profile profileName. If you do not specify a profile, the software applies the Profile property of the cluster object cluster.

    Examples

    collapse all

    This example shows how to create and submit a pool type communicating job.

    The supporting function myFunction listed at end this example uses a parfor-loop. The function requires a pool type communicating job to execute the statements in the parfor-loop.

    Create a communicating job object to evaluate myFunction on the default cluster.

    myCluster = parcluster;
    j = createCommunicatingJob(myCluster,"Type","pool"); 

    Add the task to the job, supplying an input argument.

    createTask(j, @myFunction, 1, {100});

    Set the number of workers required for parallel execution using the NumWorkersRange job property.

    j.NumWorkersRange = [5 10];

    Run the job.

    submit(j);

    Wait for the job to finish and retrieve its results:

    wait(j)
    out = fetchOutputs(j)
    out = 1×1 cell array
        {[2.5248e+03]}
    
    

    Delete the job from the cluster.

    delete(j);
    function result = myFunction(N)
        result = 0;
        parfor ii=1:N
            result = result + max(eig(rand(ii)));
        end
    end

    Input Arguments

    collapse all

    Cluster, specified as a parallel.Cluster object that represents cluster computing resources. To create the object, use the parcluster function.

    Example: parcluster;

    Data Types: parallel.Cluster

    Communicating job type, specified as one of these options:

    • "pool" — Run the specified task function with a parallel pool. The parallel pool executes the body of parallel functions such as parfor and spmd that are inside the task function. One worker from the parallel pool runs the task function. So, for a pool type job on a pool of N workers, only N—1 workers execute the parfor and spmd code in the task function.

    • "spmd" — Run the specified task function simultaneously on all workers. You can use communication functions such as spmdSend and spmdReceive to communicate between workers.

    Data Types: char | string

    Cluster profile, specified as a character vector or string scalar.

    Example: "Processes" applies the property values specified in the Processes profile to the job.

    Data Types: char | string

    Output Arguments

    collapse all

    Job, returned as a parallel.Job object.

    Data Types: parallel.Job

    Tips

    When you offload computations to workers, any files that the client needs for computations must also be available on workers. By default, the client attempts to detect and attach these files. To turn off automatic detection, set the AutoAttachFiles property to false. If the software cannot find all the files, or if sending files from client to worker is slow, use one of these options.

    • If the files are in a folder that is not accessible on the workers, set the AttachedFiles property. The cluster copies each file you specify from the client to the workers.

    • If the files are in a folder that is accessible on the workers, you can set the AdditionalPaths property instead. Use the AdditionalPaths property to add paths to the MATLAB® search path for each worker and avoid copying files unnecessarily from the client to the workers.

    Version History

    Introduced in R2012a