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.
Identify a cluster. Use
parallel.defaultClusterProfile
to indicate that you are using theProcesses
cluster; and useparcluster
to create the objectc
to represent this cluster. For more information, see Create a Cluster Object.parallel.defaultClusterProfile('Processes'); c = parcluster();
Create a job. Create job
j
on the cluster. (For more information, see Create a Job.)j = createJob(c)
Create three tasks within the job
j
. Each task evaluates thesum
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]});
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);
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]
Delete the job. When you have the results, you can permanently remove the job from the scheduler's storage location.
delete(j)
See Also
parallel.defaultClusterProfile
| parcluster
| createJob