Difference between revisions of "MATLAB Guide"
Line 148: | Line 148: | ||
The parallel pool on the cluster gives errors currently if parpool() or matlabpool is used, this can be fixed by running the Matlab 2017b module. | The parallel pool on the cluster gives errors currently if parpool() or matlabpool is used, this can be fixed by running the Matlab 2017b module. | ||
− | The pool can be called with: delete(gcp('nocreate')) | + | The pool can be called with: delete(gcp('nocreate')) "this removes previous parallel interactive sessions" |
− | p=gcp | + | p=gcp "this assigns the gcp or current parallel pool instead of using p=parpool()" |
[[Category:Software]] | [[Category:Software]] |
Revision as of 10:10, 18 October 2018
Contents
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 to run a matlab file TestCluster.m. 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.
Extra Notes
When opening a parallel pool, you may receive a warning. This warning is fine to ignore, as this warning is currently a bug in the older versions of Matlab and is fixed on newer versions of Matlab.
The parallel pools help set the number of workers from the Slurm allocation, so that Matlab spawns them in the local Matlab profile as well.
To make sure Matlab runs only one instance per the job submission, the matlab -r matlabfilename\;exit\; command is used in the slurm script
The parallel pool on the cluster gives errors currently if parpool() or matlabpool is used, this can be fixed by running the Matlab 2017b module.
The pool can be called with: delete(gcp('nocreate')) "this removes previous parallel interactive sessions" p=gcp "this assigns the gcp or current parallel pool instead of using p=parpool()"