Choose Batch Processing Function - MATLAB & Simulink (original) (raw)
Main Content
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. When you offload work to a remote compute cluster, 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.
To develop and test your code, you can offload work to a local cluster on your client machine. If you close your MATLAB session, any batch jobs using the local cluster also stop immediately.
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 thebatch
function instead of thecreateCommunicatingJob
function.
The following diagram shows when to use the batch
andcreateJob
functions.
Select Batch Function
To decide which batch processing function is right for you, consult this table.
Example Applications | Functions and Approach | Examples |
---|---|---|
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: a parfor-loopa parfeval callan spmd blockdistributed arraysa function with theUseParallel option. | Use the batch function with the Pool name-value argument. | Run Batch Parallel JobsRun 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
batch | createJob | createCommunicatingJob | createTask