Topics Map > User Guides
Topics Map > Platform R
Platform R: Running Matlab
Platform R provides Matlab in a container found in /mnt/scratch/shared/containers. The current version is platformr-matlab-2024b.sif
Matlab License
Matlab is licensed software and running it will consume one license token either interactively or as a batch job. There are a lot of license tokens on the Platform R Slurm cluster (10,000), but it is still best practice to make sure the Slurm scheduler knows about license use so it will not accidentally run so many matlab jobs that it oversubscribes license tokens.
Use -L matlab or --licenses=matlab to use one token. To use more, add the number you need with a colon separator, such as -L matlab:3 for three tokens.
Running Matlab Interactively
This will start an interactive Matlab session in the terminal. The Matlab GUI is not available in Platform R.
srun -L matlab --singularity-container=/mnt/scratch/shared/containers/platformr-matlab-2024b.sif --pty matlab
Running Matlab Batch Jobs
For the example, create this simple Matlab file, hello.m:
% hello.m
disp("Hello, World!");
result = 2 + 2;
disp("Result: " + string(result));
And create this batch script, submit.sh: Note the -r "run('hello.m')" command line argument. That's the most straightforward way to have Matlab run a file of Matlab code from the command line.
#!/bin/bash
#SBATCH --job-name=matlab-test
#SBATCH --licenses=matlab
#SBATCH --cpus-per-task=1
#SBATCH --memory=16G
#SBATCH --output=hello.out
srun \
--singularity-container=/mnt/scratch/shared/containers/platformr-matlab-2024b.sif \
matlab -r "run('hello.m')"Then run: sbatch submit.sh
Parallel Computing Toolbox
The Platform R Matlab container includes the Parallel Computing Toolbox.
To give Matlab more CPUs to work with, change the value of the --cpus-per-task setting. For example, if you set --cpus-per-task=32 Matlab will see 32 CPU cores. If in Matlab you run parpool() it will set up what Matlab calls a ProcessPool with 32 CPU cores.
You can pass the number of CPUs as an argument to parpool. That is not necessary, but might be useful as documentation. Matlab will give an error if you ask for more CPUs than you specify to slurm, such as using parpool(32) when the slurm resource option is only --cpus-per-task=16.

