Instructions for using MATLAB software
MATLAB is programming platform for analysing and designing systems, primary for numeric computing. Supports matrix manipulations, data plotting, implementation of algorithms, development of user interfaces, etc. Programs written in MATLAB, can use libraries written in C, C++, Java and Fortran. Developed by MathWorks, read more.
License
MATLAB is a licensed software, HPC Vega offers Standard Concurrent license, which is intended to be used by multiple users simultaneously.
- MATLAB Distrib Comp Engine (Total of 4000 licenses issued)
- MATLAB (Total of 200 license issued)
Academic users can freely use MATLAB on HPC Vega, commercial users have to bring their own license. For more information ask support@sling.si.
Alternative: use your own licence
An alternative option for using your own license is supported. If you want to use your own licence, you have to export environment variable for license file.
export MLM_LICENSE_FILE=/path/to/file/license.dat
Various MATLAB versions are available on HPC Vega, through modules.
module load matlab
MATLAB user interfaces
For the graphical user interface (GUI), X11 forwarding must be enabled on the client site, otherwise an interactive command line session will begin.
The easiest way to check this is echo $DISPLAY, if value is not specified, the forwarding does not work.
Graphical user interface (GUI)
matlab -display Xdisplay
To start interactive session, first you need to request an interactive allocation from Slurm.
salloc --job-name=matlab-int \
--time=00:30:00 \
--partition=cpu \
--nodes=1 \
--ntasks=1 \
--cpus-per-task=8 \
--x11
Launch tasks on allocated resources:
srun --pty bash
Load module:
module load matlab
Run the script with graphical components (for example plots):
matlab -nodesktop -nosplash -r "run('matlabtest.m');"
Command line interface (CLI) only:
matlab -nodisplay
For additional information about MATLAB commands, load module from your shell and check the help section.
matlab -h
Example of a Slurm job
The following example shows a task that will be run on 1 node and 8 cores. The job requires 4 GB RAM per core and will be carried out for 5 minutes on cpu partition.
Content of inputfile matlabtest.m:
function matlabtest
disp('Hello from MATLAB!')
end
Content of SBATCH script:
#!/bin/bash
#SBATCH --job-name=matlab-test
#SBATCH --time=00:05:00
#SBATCH --partition=cpu
#SBATCH --nodes=1
#SBATCH --mem=4G
#SBATCH --cpus-per-task=8
module load matlab
matlab -batch matlabtest
Input file, e.g. shell or sbatch script must be exclude .m, output will be written inside slurm-<jobid>.log.
Example of a Singularity job
Content of SBATCH script:
#!/bin/bash
#SBATCH --mem-per-cpu=512M
#SBATCH --job-name=matlab-test
#SBATCH --time=00:05:00
#SBATCH --partition=cpu
#SBATCH --nodes=1
#SBATCH --mem=4G
#SBATCH --cpus-per-task=8
singularity exec /ceph/hpc/software/containers/singularity/images/matlab-<version>.sif matlab -batch matlabscript
There are additional resources for users wanting to learn more about parallel programming with MATLAB.
Example of sending with ARC
Firstly you will need ARC Client and a .xrsl file in which you state which resources you need to start the job, and contains two additional input files.
&
(count = 8)
(countpernode = 1)
(jobname = matlab-test)
(inputfiles =
("matlabscript.sh" "")
("matlabscript.m" "")
)
(executable = matlabscript.sh)
(outputfiles = ("example.out" ""))
(stdout=example.log)
(join=yes)
(gmlog=log)
(memory=8000)
(walltime="5 minutes")
Example of matlabscript.sh:
#!/bin/bash
#Setup environment
. /ceph/hpc/software/cvmfs_env.sh
#Load module
module --ignore-cache load matlab
#Execute script
matlab -batch matlabscript
For input script examples e.g. matlabscript.m, check the official documentation.
Documentation
- MATLAB user documentation: https://www.mathworks.com/help/matlab/
- MATLAB Basic Funtions Reference: https://www.mathworks.com/content/dam/mathworks/fact-sheet/matlab-basic-functions-reference.pdf
- MATLAB examples: https://www.mathworks.com/help/examples.html