Main Content


Create communicating job on cluster


job = createCommunicatingJob(cluster)
job = createCommunicatingJob(...,'p1',v1,'p2',v2,...)
job = createCommunicatingJob(...,'Type','pool',...)
job = createCommunicatingJob(...,'Type','spmd',...)
job = createCommunicatingJob(...,'Profile','profileName',...)


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

job = createCommunicatingJob(...,'p1',v1,'p2',v2,...) creates a communicating job object with the specified property values. For a listing of the valid properties of the created object, see the parallel.Job object reference page. The property name must be a character vector, with the value being the appropriate type for that property. In most cases, the values specified in these property-value pairs override the values in the profile.

When you offload computations to workers, any files that are required for computations on the client must also be available on workers. By default, the client attempts to automatically detect and attach such files. To turn off automatic detection, set the AutoAttachFiles property to false. If automatic detection cannot find all the files, or if sending files from client to worker is slow, use the following properties.

  • 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 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 each worker's MATLAB® search path and avoid copying files unnecessarily from the client to workers.

If you specify AttachedFiles or AdditionalPaths, the values are combined with the values specified in the applicable profile. If an invalid property name or property value is specified, the object will not be created.

job = createCommunicatingJob(...,'Type','pool',...) creates a communicating job of type 'pool'. This is the default if 'Type' is not specified. A 'pool' job runs the specified task function with a parallel pool available to run the body of parfor loops or spmd blocks. Note that only one worker runs the task function, and the rest of the workers in the cluster form the parallel pool. So on a cluster of N workers for a 'pool' type job, only N-1 workers form the actual pool that performs the spmd and parfor code found within the task function.

job = createCommunicatingJob(...,'Type','spmd',...) creates a communicating job of type 'spmd', where the specified task function runs simultaneously on all workers, and lab* functions can be used for communication between workers.

job = createCommunicatingJob(...,'Profile','profileName',...) creates a communicating job object with the property values specified in the profile 'profileName'. If no profile is specified and the cluster object has a value specified in its 'Profile' property, the cluster’s profile is automatically applied.


Example 1. Pool Type Communicating Job

Consider the function 'myFunction' which uses a parfor loop:

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

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:

j.NumWorkersRange = [5 10];

Run the job.


Wait for the job to finish and retrieve its results:

out = fetchOutputs(j)

Delete the job from the cluster.

Introduced in R2012a