Main Content

Choose Batch Processing Function

Batch processing workflows allow you to offload work to a compute cluster and free up your MATLAB® client to carry out other tasks, or submit long running code for later execution. In a batch workflow, you can close the MATLAB client session while the job is processing and retrieve information from a batch job later or in a new client session.

Batch Parallel Job Types

Parallel Computing Toolbox™ packages the MATLAB code you want to execute offline into jobs and tasks. To find out more about how Parallel Computing Toolbox runs a job, see How Parallel Computing Software Runs a Job.

There are two types of jobs you can run in a batch workflow:

  • Independent Jobs – execute a task in isolation on a worker, with no communication between workers.

    Typically, if your code does not require a parallel pool, then you can use an independent job.

  • Communicating Jobs – one worker acts as the client and the other workers run the noninteractive pool. The workers can communicate with each other during the execution of their tasks.

    Typically, if your code calls functions that require a parallel pool such as parfor, parfeval, spmd, or distributed, then it is a communicating job.

Parallel Computing Toolbox provides the following functions to run your MATLAB code in a batch process:

Tip

For a simpler function to run communicating jobs, use the batch function instead of the createCommunicatingJob function.

The following diagram shows when to use the batch and createJob functions.

Diagram shows the types of jobs in batch processing, and the different parallel language constructs you can use within each job type. For independent jobs, you can use the batch or createJob function. For communicating jobs, use the batch function with a Pool name-value argument.

Select Batch Function

To decide which batch processing function is right for you, consult this table.

Example Applications Functions and ApproachExamples

You want to execute a MATLAB script in the background on a cluster.

Use the batch function. This is the simplest way to offload long-running jobs to execute in the background.

Run Script as Batch Job

You want to use a noninteractive pool on an onsite or cloud cluster to run code including one or more of:

Use the batch function with the Pool name-value argument.

Run Batch Parallel Jobs

Run Batch Job and Access Files from Workers

You have multiple independent MATLAB function calls to run in the background on a cluster. Each function does not require a parallel pool of workers.

Use the createJob function and add tasks with the createTask function.

You can create an independent task for each function call. When a task is complete, the worker moves on to the next task on the list without waiting for the other tasks to finish. You can also access intermediate results from the completed tasks.

Create and Run Job

See Also

| | |

Related Topics