CCF (Core Computational Facility) @ UQ run by ITS / SMP


[Home] [why HPC?] [UQ Resources] [getafix] [dogmatix] [asterix] [ghost] [contacts/help]
howto: [data] [Slurm] [OpenMP/MKL] [Nvidia GPU] [Intel Phi] [MPI] [matlab] [mathematica] [FAQ]

Howto - Run Matlab Calculations

GUI Matlab quickstart

Once logged in, start the interactive job as above adding arguments --x11 --pty to the srun command. In order to use interactive jobs with the GUI on getafix you will need to have ssh keys setup, for further details see SLURM queue. As an example, the following command starts a new Matlab session with 1 cpu and 12 GB of RAM. A time limit (in D-HH:MM) is added, this is not necesary but is a good idea for interactive jobs.

srun --cpus-per-task=1 --time=0-2:00 --mem=12G --x11 --pty matlab where the time is in D-HH:MM

Matlab code

To run Matlab calculations, you first need to put your Matlab comands into a file with a .m extension. You can then submit the job to sbatch with a script:

#SBATCH --job-name matlab-example
#SBATCH --time=02:00:00
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --mem=16G

srun matlab -nodisplay -nojvm -nosplash -r 'filename'

Note

Code with parameters

If your calculation requires input values, you can code it as a function and supply the values in the call to Matlab:

srun matlab -nodisplay -nojvm -nosplash -r 'filename(param1,param2,...)'

Compiled Matlab code

Alternatively, you can compile your code with the Matlab compiler and run it as a binary executable. To compile the .m file:

module load matlab
mcc -m filename

Then submit your job to the slurm queue with a script:

#!/bin/bash
#SBATCH --job-name matlab-example
#SBATCH --time=02:00:00
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --mem=8G

module load matlab
srun ./filename param1 param2 ...

Multithreaded computations

To run a matlab jobs using multiple threads submit the job to sbatch with a script like:

#SBATCH --job-name matlab-example
#SBATCH --time=02:00:00
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=8
#SBATCH --mem=32G

srun matlab -nodisplay -nojvm -nosplash -r 'filename'

Using Keras importer

In order to use the Keras (Tensorflow) network importer you will need to add the Matlab-Keras support package. On getafix, the support package can be added by adding the folder containing the support package to the path, in Matlab run

addpath('/usr/local/MATLAB/R2018b/toolbox/nnet/supportpackages/keras_importer')

To use an existing network, simply load the network using the importer and call the predict function. The size of the network inputs will depend on the network you are loading.

net = importKerasNetwork('./path/to/network.h5');

% Evaluate the network at 20 points (assuming 3-dof network)
ndof = 3;
npts = 20;
x = rand(ndof, npts);
force = double(predict(net, reshape(x, [1, ndof, 1, npts]))).';

This page last updated 16th December 2019. [Contacts/help]