MATLAB Guide

From Storrs HPC Wiki
Revision as of 10:23, 25 July 2017 by Lwm14001 (talk | contribs) (Using MATLAB on the the cluster: 12 is wrong, most of our nodes have 24 cores now)
Jump to: navigation, search


MATLAB licensing

The HPC cluster uses the university site license for MATLAB, which includes an unlimited number of seats and all toolboxes. More information is available here: http://software.uconn.edu/matlab/.

Using MATLAB on the the cluster

All jobs on the the cluster must be submitted through the SLURM scheduler using sbatch. Please read the SLURM Guide for more details. The preferred way to run MATLAB jobs is using a .m file. Please note that if your job uses many cores or a lot of memory it is better to submit to reserve a whole compute node (24 cores) in exclusive mode

Loading MATLAB module

To load the MATLAB module:

$ module load matlab/2016a

You can view a list of all available MATLAB versions with:

$ module available matlab

Submitting .m files with slurm

Single Core job

To submit a job which uses a single core on a compute node where other jobs are running. Create a script called matlabSP.sh:

#!/bin/bash
#SBATCH --ntasks=1
#SBATCH --output=outputfile.txt
#SBATCH --error=outputfile.txt

matlab -singleCompThread -r TestCluster\;exit\;

NOTE: any ";" or " ' " after "-r" should be pre-appended by "\".

Then submit the script:

 sbatch matlabSP.sh

Multithread job

To submit a job which uses 24 computational threads on one node, create a submission script matlabMP.sh:

#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=24
#SBATCH --exclusive
#SBATCH --output=outputfile.txt
#SBATCH --error=outputfile.txt

matlab -r TestCluster\;exit\;

NOTE: any ";" or " ' " after "-r" should be pre-appended by "\".

Then submit the script by:

 sbatch matlabMP.sh

How to write script for matlabpool

To run a job with parfor, please rewrite TestCluster as:

num_proc=str2num(getenv('SLURM_NTASKS'));
matlabpool('local',num_proc)

parfor i=1:40
   ...
end
matlabpool close;
Notice: Please use "parpool" to replace "matlabpool" if you use matlab/2016a

Then, submit your script as:

sbatch matlabMP.sh

Interactive MATLAB use with SLURM

NOTE: *any* interruption to the network will cause your job to crash irrecoverably.

To run an interactive Matlab session with 24 cores, you will want to do the following:

$ module load matlab/2016a
$ fisbatch --ntasks=24 --nodes=1 --exclusive
FISBATCH -- the maximum time for the interactive screen is limited to 6 hours.
FISBATCH -- waiting for JOBID 20248 to start on cluster=cluster and partition=general
!
FISBATCH -- Connecting to head node (cn142)
[xxx00000@cn142 ~]$ matlab
... # here will be the interactive commands with matlab
[xxx00000@cn142 ~]$ exit
[screen is terminating]
Connection to cn42 closed.
FISBATCH -- exiting job

NOTE: please DO NOT FORGET to EXIT from the nodes so that the other users can use it.

[NetID@cn142 ~]$ matlab

NOTE: *any* interruption to the network will cause your job to crash irrecoverably.

To run an interactive Matlab session with GUI, you should "ssh -X" to the the cluster from a Linux machine or iOS matchine with X11 enabled. Or please follow the X Apps. Then, run the above commands.