Main Content

Program a Job on a Local Cluster

In some situations, you might need to define the individual tasks of a job, perhaps because they might evaluate different functions or have uniquely structured arguments. To program a job like this, the typical Parallel Computing Toolbox™ client session includes the steps shown in the following example.

This example illustrates the basic steps in creating and running a job that contains a few simple tasks. Each task evaluates the sum function for an input array.

  1. Identify a cluster. Use parallel.defaultClusterProfile to indicate that you are using the Processes cluster; and use parcluster to create the object c to represent this cluster. For more information, see Create a Cluster Object.

    parallel.defaultClusterProfile('Processes');
    c = parcluster();
  2. Create a job. Create job j on the cluster. (For more information, see Create a Job.)

    j = createJob(c)
  3. Create three tasks within the job j. Each task evaluates the sum of the array that is passed as an input argument. For more information, see Create Tasks.

    createTask(j, @sum, 1, {[1 1]});
    createTask(j, @sum, 1, {[2 2]});
    createTask(j, @sum, 1, {[3 3]});
  4. Submit the job to the queue for evaluation. The scheduler then distributes the job's tasks to MATLAB® workers that are available for evaluating. The Processes cluster might now start MATLAB worker sessions. For more information, see Submit a Job to the Cluster.

    submit(j);
  5. Wait for the job to complete, then get the results from all the tasks of the job. For more information, see Fetch the Job Results.

    wait(j)
    results = fetchOutputs(j)
    results = 
        [2]
        [4]
        [6]
  6. Delete the job. When you have the results, you can permanently remove the job from the scheduler's storage location.

    delete(j)

See Also

| |

Related Topics