User`s guide

6 Programming Overview
6-10
Create Simple Independent Jobs
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 local cluster; and use parcluster to create the object c to represent
this cluster. (For more information, see “Create a Cluster Object”.)
parallel.defaultClusterProfile('local');
c = parcluster();
2
Create a job. Create job j on the cluster. (For more information, see “Create a Job”
on page 7-4.)
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” on page
7-5.)
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 local cluster might
now start MATLAB worker sessions. (For more information, see “Submit a Job to the
Cluster” on page 7-5.)
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’s Results” on page 7-6.)
wait(j)
results = fetchOutputs(j)