User`s guide

Introduction to Parallel Solutions
1-9
batch runs your code on a local worker or a cluster worker, but does not require a
parallel pool.
You can use batch to run either scripts or functions. For more details, see the batch
reference page.
Run a Batch Parallel Loop
You can combine the abilities to offload a job and run a parallel loop. In the previous two
examples, you modified a for-loop to make a parfor-loop, and you submitted a script
with a for-loop as a batch job. This example combines the two to create a batch parfor-
loop.
1
Open your script in the MATLAB Editor:
edit mywave
2
Modify the script so that the for statement is a parfor statement:
parfor i = 1:1024
A(i) = sin(i*2*pi/1024);
end
3
Save the file and close the Editor.
4
Run the script in MATLAB with the batch command as before, but indicate that the
script should use a parallel pool for the loop:
job = batch('mywave','Pool',3)
This command specifies that three workers (in addition to the one running the batch
script) are to evaluate the loop iterations. Therefore, this example uses a total of four
local workers, including the one worker running the batch script. Altogether, there
are five MATLAB sessions involved, as shown in the following diagram.