Parallel Computing using MATLAB on Roar

This document provides the steps to configure MATLAB to submit jobs to a cluster, retrieve results, and debug errors.

After logging into the cluster, configure MATLAB to run parallel jobs on your cluster by calling the shell script , which requires the name of the Allocation to use. This only needs to be called once per version of MATLAB.

$ module use /gpfs/group/RISE/sw7/modules
$ module load matlab/R2020b
$ <allocation-name&>

Jobs will now default to the cluster rather than submit to the local machine.

NOTE: If you would like to run the pool of workers on the same machine running MATLAB, simply run the following command and skip the remaining sections of this document.

>> % Get a handle to the local resources
>> c = parcluster(‘local’);

Prior to submitting the job, we can specify various parameters to pass to our jobs, such as queue, e-mail, walltime, etc. Only Allocation is required.

>> % Get a handle to the cluster
>> c = parcluster;
>> % Specify an account to use for MATLAB jobs
>> c.AdditionalProperties.Allocation = ‘allocation-name’;


>> % Specify e-mail address to receive notifications about your job
>> c.AdditionalProperties.EmailAddress =’’;
>> % Request Feature
>> c.AdditionalProperties.Feature = ‘a-feature’;
>> % Specify number of GPUs
>> c.AdditionalProperties.GpusPerNode = 1;

> % Specify memory to use for MATLAB jobs, per core (MB)
>> c.AdditionalProperties.MemUsage = ‘4000’;
>> % Specify the walltime (e.g. 5 hours)
>> c.AdditionalProperties.WallTime = ’05:00:00′;

Save changes after modifying AdditionalProperties for the above changes to persist between MATLAB sessions.

>> c.saveProfile

To see the values of the current configuration options, display AdditionalProperties.

>> % To view current properties
>> c.AdditionalProperties

Unset a value when no longer needed.

>> % Turn off email notifications
>> c.AdditionalProperties.EmailAddress = ‘ ‘;
>> c.saveProfile

To run an interactive pool job on the cluster, continue to use parpool as you’ve done before.

>> % Get a handle to the cluster
>> c = parcluster;
>> % Open a pool of 64 workers on the cluster
>> p = c.parpool(64);

Rather than running local on the local machine, the pool can now run across multiple nodes on the cluster.

>> % Run a parfor over 1000 iterations
>> parfor idx = 1:1000
a(idx) = …

Once we’re done with the pool, delete it.

> % Delete the pool
>> p.delete


To learn more about the MATLAB Parallel Computing Toolbox, check out these resources: