...
You can specify other additional parameters along with your job.
>> % Specify a queue to use for MATLAB jobs
>> c.AdditionalProperties.QueueName = ‘shared’
>> % Specify e-mail address to receive notifications about your job
...
Users can also submit parallel workflows with batch. Let’s use the following example for a parallel job.
We will use the batch command again, but since we’re running a parallel job, we’ll also specify a MATLAB Pool.
>> % Get a handle to the cluster
>> c = parcluster;
>> % Submit a batch pool job using 4 workers for 16 simulations
>> j = c.batch(@parallel_example, 1, {}, ‘Pool’, 4);
>> % View current job status
>> j.State
>> % Fetch the results after a finished state is retrieved
>> j.fetchOutputs{:}
ans = 15.5328
The job ran in 15.53 sec. using 4 workers.
Note that these jobs will always request N+1 cores, since one worker is required to manage the batch job and pool of workers.
For example, a job that needs eight workers will consume nine CPU cores.
We’ll run the same simulation, but increase the Pool size. This time, to retrieve the results at a later time, we’ll keep track of the job ID.
NOTE: For some applications, there will be a diminishing return when allocating too many workers, as the overhead may exceed computation time.
>> % Get a handle to the cluster
>> c = parcluster;
>> % Submit a batch pool job using 8 workers for 16 simulations
>> j = c.batch(@parallel_example, 1, {}, ‘Pool’, 8);
>> % Get the job ID
>> id = j.ID
Id = 4
>> % Clear workspace, as though we quit MATLAB
>> clear j
Once we have a handle to the cluster, we’ll call the findJob method to search for the job with the specified job ID.
>> % Get a handle to the cluster
>> c = parcluster;
>> % Find the old job
>> j = c.findJob(‘ID’, 4);
>> % Retrieve the state of the job
>> j.State
ans
finished
>> % Fetch the results
>> j.fetchOutputs{:};
ans =
6.4488
>> % If necessary, retrieve output/error log file
>> c.getDebugLog(j)
The job now runs 6.4488 seconds using 8 workers. Run code with different number of workers to determine the ideal number to use.
Debugging
To learn More
...