Matlab

UQ has a license for all Matlab products for all staff and students, both on-campus and personal computers.

The UQ MATLAB Campus License portal page is here: https://www.mathworks.com/academia/tah-portal/the-university-of-queensland-30623128.html

To create a MathWorks account linked to the UQ license, visit https://www.mathworks.com/mwaccount/register (this will let you install Matlab on your personal computer)

The UQ Campus license also gives access to all self paced online training courses at https://matlabacademy.mathworks.com/

Everyone at UQ gets access to MATLAB Online https://matlab.mathworks.com/ (this version of MATLAB that runs in your web browser)

Matlab on Getafix

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. 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 </p>

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: @@

  1. 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

  • Save your file with a .m extension but call it without the .m when you run Matlab
  • Matlab can use a lot memory so if your job stalls or fails, try again with more memory.

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: @@

  1. !/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: @@

  1. 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]))).';
@@
Page last modified on November 19, 2021, at 09:37 AM
Powered by PmWiki