Sie befinden sich im Service: RWTH High Performance Computing (Linux)

MATLAB

MATLAB

Kurzinformation

MATLAB is a programming and numeric computing platform used by millions of engineers and scientists to analyze data, develop algorithms, and create models.

MathWorks

Table of Contents

  1. How to access the software
  2. Working with jobs from within the MATLAB Desktop
  3. Example batch scripts
  4. Additional notes

Detailinformation

How to access the software

Load MATLAB directly:

module load MATLAB/2022b

Available MATLAB versions can be listed with module spider MATLAB. Specifying a version will list the needed modules: module spider MATLAB/2022b

The NAG Toolbox for MATLAB is tightly integrated into appropriate MATLAB versions, so you do not need to load any additional modules.

Working with jobs from within the MATLAB Desktop

Getting Started with Parallel Computing using MATLAB on the RWTH HPC Cluster

You can find further information in the workshop slides of our training "Scaling Parallel Computing with MATLAB to HPC at RWTH Aachen University" (s. Material section).

Example batch scripts

Serial Job:

#!/usr/bin/zsh

### Job name
#SBATCH --job-name=MATLAB_SERIAL

### File / path which STDOUT will be written to, %J is the job ID
#SBATCH --output=MATLAB_SERIAL.%J

### Request the time you need for execution. The full format is D-HH:MM:SS
### You must at least specify minutes or days and hours and may add or
### leave out any other parameters
#SBATCH --time=80

### Request the memory you need for your job. You can specify this
### in either MB (1024M) or GB (4G).
#SBATCH --mem-per-cpu=3900M

### Change to the work directory, if not in submit directory
#cd "$HOME/workdirectory/where/the/m-file/is"

### Load the required modules
module load MATLAB/2022b

### start non-interactive batch job
matlab -singleCompThread -nodisplay -nodesktop -nosplash -logfile job.${SLURM_JOB_ID}.txt <<EOF
run /path/to/the/dot-m-file.m;
quit();
EOF

Multiple Parallel Jobs Running At Same Time:

Matlab uses a shared directory in $HOME for temporary 'parpool' files, which prohibit multiple 'parpool' jobs from running at same time.

Thus change the location of this directory before starting yet another 'parpool'.

#!/usr/bin/zsh

### Job name
#SBATCH --job-name=MATLAB_MULTI

### File / path which STDOUT will be written to, the %J is the job id
#SBATCH --output=MATLAB_MULTI.%J

### Request the time you need for execution. The full format is D-HH:MM:SS
### You must at least specify minutes or days and hours and may add or
### leave out any other parameters
#SBATCH --time=80

### Request the memory you need for your job. You can specify this
### in either MB (1024M) or GB (4G).
#SBATCH --mem-per-cpu=3900M

### Request the number of compute slots you want to use
#SBATCH --nodes=1
#SBATCH --ntasks=12

### Change to the work directory, if not in submit directory
cd "$HOME/workdirectory/where/the/m-file/is"

### Load required modules
module load MATLAB/2022b

### open 'parpool' and run the 'dot-m-file.m' Matlab script in current directory
matlab -nodisplay -nodesktop -nosplash -logfile job.${SLURM_JOB_ID}.txt <<EOF
cl = parcluster('local')
tmpdirforpool = tempname
mkdir(tmpdirforpool)
cl.JobStorageLocation = tmpdirforpool
cl.NumWorkers = str2num(getenv('SLURM_NTASKS'))
parpool(cl,str2num(getenv('SLURM_NTASKS')))
cl; poolobj = gcp;
disp(['%-- parpool working with (' num2str(poolobj.NumWorkers) ') workers --%']);
disp(['%-- parpool working here (' poolobj.Cluster.JobStorageLocation ')  --%']);
% now run the 'dot-m-file.m' script
dot-m-file
delete(gcp)
quit();
EOF
### note that the file 'dot-m-file.m' called without '.m' above

Additional notes

  • MATLAB and tmp

    Many hosts only have small SSDs as a harddisk. So if you need more space, if big ( in the size of GBytes ) temporary files are produced, you may need to change the default "tmp" directory of MATLAB. One suitable space would be e.g. the personal $HPCWORK. Lustre is a fairly fast filesystem, optimized for large files.

    In the jobscript itself, one can then set another TMP for MATLAB, e.g. this way:

    OLDTMP=$TMP
    TMP=$HPCWORK/.tmp/matlab_${SLURM_JOB_NAME}.${SLURM_JOB_ID}
    mkdir -p $TMP
    export TMP
    
    # ...
    # matlab part of the script
    # ...
    
    rm -rf $TMP
    TMP=$OLDTMP
    
  • MATLAB on Frontends

    By default, MATLAB makes use of the multithreading capabilities of the computer on which it is running. In this case MATLAB tries to utilize all available CPUs on the current node. In shared environments like frontends this behavior may lead to major oversubscription of nodes. Frontend processes with excessive resource consumption may be ended (killed) by the administrators. To avoid overloading on frontends / interactive usage: always start MATLAB with the -singleCompThread flag

    zuletzt geändert am 23.01.2024

    Wie hat Ihnen dieser Inhalt geholfen?

    Creative Commons Lizenzvertrag
    Dieses Werk ist lizenziert unter einer Creative Commons Namensnennung - Weitergabe unter gleichen Bedingungen 3.0 Deutschland Lizenz