I have a for loop, that generates a 1 by n array, and then saves that array as a mat file called "Batch_Test_N (For Loop Iteration Number)". If I were to run this in batch with a parallel pool of 2, is each mat file generated 2 times, or is each loop run once? For example, does worker 1 run through the entire for loop, and then worker 2 also runs through the entire for loop, or does worker 1 only do iteration 1,3,...9, and worker 2 does the rest?
for i=1:10
filename=['Batch_Test_',num2str(i)];
Array=ones(1,i);
save(filename,'Array')
end
job=batch('Script_Name','Pool',2)
@David already gave the correct answer in a comment, this answer is just to expand a little on that.
When you run batch('<script>', 'Pool', N)
, it's basically as if you ran
parpool(N);
<script>
in MATLAB - in other words, your script gets executed with an open parallel pool of size N. Note therefore that batch(..., 'Pool', N)
uses N+1
workers on the cluster.
Therefore, as @David correctly points out - to get parallelism on the cluster, your script needs to contain parallel language constructs such as parfor
, spmd
, or parfeval
.This is described in the doc: https://uk.mathworks.com/help/parallel-computing/run-a-batch-job.html#bu62o45