MATLAB¶
From the MathWorks website https://uk.mathworks.com/products/matlab.html
MATLAB combines a desktop environment tuned for iterative analysis and design processes with a programming language that expresses matrix and array mathematics directly. It includes the Live Editor for creating scripts that combine code, output, and formatted text in an executable notebook.
Running MATLAB on CSD3¶
Running MATLAB will require you to load the matlab
module which will load the latest version of MATLAB installed on CSD3. The MATLAB script below, with filename example.m
, contains a function which requires an argument. This functions stores a value in a mat file named with the value of the given argument.
function example(name)
x=2;
save([name '.mat'],'x');
end
The slurm submit script which calls the above MATLAB function is shown below:
#!/bin/bash
#SBATCH -A MYACCOUNT-CHANGEME
#SBATCH -p icelake # Can change this to a different partition
#SBATCH -N 1
#SBATCH -n 1 # MATLAB r2024b minimum requirements are 2 CPUs and 8 GB RAM. This is for anything requiring MATLAB java virtual machine (JVM). This example turns off JVM as not required for anything.
#SBATCH -t 00:10:00
#SBATCH -J matlab-example
#SBATCH -o matlab_example.out
#SBATCH -e matlab_example.err
module purge
module load rhel8/global matlab/r2024a
# Using -nojvm to turn off MATLAB JVM and its long, associated overhead.
# Use with care, as JVM is used in several toolboxes like the parallel toolbox
matlab -nodisplay -nojvm -r "example('output_file'); quit"
The slurm submit script can be submitted to the queue with sbatch
from the same directory as the example.m
MATLAB script file. This will run on one node using one core up to a limit of 1 minute. To run on more cores the -n
option should be adjusted and the timelimit can be changed with -t
.
NOTE that the quit
command in the slurm submit script is required to quit MATLAB after the completion of the example MATLAB function.