MATLAB
1. How to Access the Software
module load MISC module load matlab |
The NAG Toolbox for MATLABis tightly integrated into appropriate MATLABversions, so you do not need to load any additional modules.
2. Working with jobs from within the MATLAB Desktop
Getting_Started_With_Serial_And_Parallel_MATLAB
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).
3. Example Batch Scripts
#!/usr/local_rwth/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=1850M ### Change to the work directory, if not in submit directory #cd $HOME/workdirectory/where/the/m-file/is ### Load the required modules module load MISC module load matlab ### 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 use 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/local_rwth/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 MISC module load matlab ### 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 |
4. Additional Notes
MATLAB and tmp
Many hosts only have small SSDs as a harddisk. So if one needs more space, if big ( in the size of GBytes ) temporary files are produced, one 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 front ends 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 front ends / interactive usage: always start MATLAB with the '-singleCompThread' flag