Submitting A Matlab Job

To provide a tutorial, we will work with two files, my_sum.m is a Matlab code that is purely used as a timed matrix operation kernel.  The second file, run_matlab.sh shows you how to run a Matlab job in SLURM.

The first file is a clone of the example given in Matlab’s timeit function, except that we have modified the size of the Matrices A and B to be 15K by 15K.  As given by the documentation, the example combines several mathematical functions: “matrix transposition, element-by-element multiplication, and summation of columns”:
my_sum.m

A = rand(15000,15000);
B = rand(15000,15000);
f = @() sum(A.'.*B, 1);
timeit(f)

 

Both discussed files need to be in the same directory, and the job is submitted via sbatch run_matlab.sh

run_matlab.sh

#!/bin/bash
#SBATCH --job-name=matlab
#SBATCH --time=1:00:00
#SBATCH --partition=shared
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=2
### Using more tasks because default memory is ~5GB per core
### 'shared' will share the node with other users
### 'parallel' use entire node (24,28,48, depends on node type)
### Try the script with --ntasks-per-node=1 and see what happens
#
#---------------------------------------------------------------------
# SLURM job script to run serial MATLAB
#---------------------------------------------------------------------
 
ml matlab
ml # confirm modules used
matlab -nodisplay -nojvm -nosplash -nodesktop -r "my_sum;"
echo "matlab exit code: $?"