There are a number of ways in which Matlab can use multiple processors.  You can run Matlab using additional workers running either on the same node or other compute nodes.  The toolboxes are:

Set up Parallel Matlab

Prior to using parallel matlab you have to set up your matalb environment to match slurm settings on ADA.  This sets the default queue (compute-16-64), one core pre task, and a parpool of 12.

  • start an interactive session
  • module add matlab/2020a
  • start matlab
  • click on parallel
  • click on create and manage clusters 
  • select import
  • select /gpfs/software/ada/matlab/R2020a/SlurmProfile1.mlsettings

You can test the config by highlighting the SLURM config and clicking "Validate" (on the menu above).  Matlab will report that a number of workers have been open (and can take some time to open workers and return to a Matlab prompt

Note the validation takes a few minutes to complete, but is useful for troubleshooting if you have issues - if when validating the test stage status doesn't return four succeeded green ticks, please email Once imported, the configuration will be available for you on future sessions.

Parallel Computing Toolbox

The Parallel Computing Toolbox allows you to use matlabpool up to the maximum number of slots on a node (16, 24 or 28 depending on the node) on a single node. 

The Parallel Computing Toolbox opens up a number of workers on the same node, so it is important you request the appropriate number of slots.  For example, if you are going to open 8 workers, then you should request 9 slots (1 for the master Matlab session, and 8 for the workers).  You also need to set the memory required and a time limit for the job to run:

  • interactive session :  

srun -n 9 -p interactive -J interactive --time=12:00:00 --mem=36G --pty bash


  • batch job :

# Mail events (NONE, BEGIN, END, FAIL, ALL)#SBATCH --mail-type=END,FAIL   
# Where to send mail#SBATCH --mail-user=<username>    
#SBATCH -p compute-16-64             # Select compute queue with 16 cores and 64Gb RAM
#SBATCH --ntasks=9    #Set number of slots required

#SBATCH --ntasks-per-node=16  # maximum slots available on the node
#SBATCH -t 36:00:00             # Set time limit to 36 hours
#SBATCH --job-name=matlab-test_job      # Set job name
#SBATCH -o matlab-test-%j.out               # Write job output to MatJob-(job_number).out
#SBATCH -e matlab-test-%j.err               # Write job error to MatJob-(job_number).err
#set up environment
module add matlab/2020a
#run the application
matlab -nodisplay -nojvm -nodesktop -nosplash -r my_matlab_m_file

Example of Parpool in the Parallel Computing Toolbox

Example Matlab code for a function that estimates pi by simulating 1 billion dart throws and is a good example of how parallel Matlab can result in faster processing.

This example can be copied from /gpfs/software/ada/matlab/samplescripts/MonteCarloPI.m

The key line is the parfor loop. As a parfor loop it is set up to run in parallel, rather than running as a standard sequential for loop. 

Matlab Editor


Matlab Parallel Server

The Matlab Parallel Server allows you to open 'workers' up on other nodes through the SLURM queueing system by using matlabpool.

Usage is basically the same as with the Parallel Computing Toolbox, though instead of using the default local configuration for matlabpool, this time a specific SLURM configuration is used which submits jobs to the queue.  Because there is a master Matlab session and workers are managed by SLURM, unlike the Parallel Computing Toolbox, you do not need to request additional slots.


>> parpool ('SlurmProfile1',28)
Starting parallel pool (parpool)  using the 'SlurmProfile1' profile ... connected to 24 workers.

By default LSF configuration parallel jobs are submitted to the compute-16-64 queue.

To close the parallel pool enter the following command: delete(gcp('nocreate'))

Matlab Documentation

There are many ways of using parallel resources within Matlab.  Please refer to the Matlab Documentation.