module avail matlabTo use the default version, enter
module load matlab
Do not use MATLAB on a login node. To use MATLAB interactively for test and debug, either use an interactive session or use the HPC-VCL node. To confirm that the session is not on a login node, type
Here is an example batch script. For more information on submitting batch scripts, see the documentation on running jobs.
To run MATLAB in batch mode using a MATLAB script called script.m, create a text file called submit.csh containing:
#!/bin/tcsh #BSUB -W 20 #BSUB -n 1 #BSUB -o out.%J #BSUB -e err.%J ##BSUB -x #Use exclusive only if necessary, uncomment if job spawns additional threads module load matlab matlab -nodisplay -nosplash -nodesktop -singleCompThread -r "run('script.m');exit;"
The job can be submitted as
bsub < submit.csh
The script submit.csh requests 1 core for a maximum of 20 minutes. Check the documentation on running jobs to customize the batch script.
module load matlab matlab
An interactive session on a compute node may be used for short debugging or in order to prepare a production batch script. Interactive sessions must be kept to a minimum and only used when necessary. Nodes left idle or underutilized by long running interactive sessions may be terminated.
The following requests an interactive session with 1 core for 10 minutes and then opens MATLAB in non-display mode.
bsub -Is -n 1 -W 10 -x tcsh module load matlab matlab -nodisplay -nosplash -nodesktop -singleCompThreadTo exit MATLAB, type
exit. To exit the interactive session, type
Using MATLAB in shared memory means that the program functions on one node; there is no communication across nodes.
By default, parallel MATLAB functions create as many tasks as there are physical cores available. To avoid overloading the node, the user must either limit the number of cores by changing the default behavior in the MATLAB script (maxNumCompThreads(N)) or adjust the bsub script to ensure the reservation of an entire node.One possibility is to specify the minimum number of processors needed and reserve the entire node using -x. The following reserves a node with at least 8 cores, specifies that all cores be on one node, and reserves the whole node. If a node with more cores happens to be reserved, e.g. a node with 12 cores, then MATLAB will use all 12 cores. The -x ensures that LSF does not assign additional jobs to the node.
#BSUB -n 8 #BSUB -R span[hosts=1] #BSUB -xAnother method is to be more precise in specifying the resources. The following reserves 8 cores and specifies an 8 core node, which is a node with two quad core processors:
#BSUB -n 8 #BSUB -R span[hosts=1] #BSUB -R select[qc]
See the example below on how to specify the number of processes to be used as an argument to a MATLAB function.
#!/bin/tcsh #BSUB -n 1 #BSUB -W 10 #BSUB -q gpu #BSUB -R "select[m2070]" #BSUB -gpu "num=1:mode=shared:mps=no" #BSUB -o m2070_out.%J #BSUB -e m2070_err.%J module load matlab/R2017b matlab -nodisplay -nosplash -nodesktop -singleCompThread -r "run('gpu.m');exit;"or
#!/bin/tcsh #BSUB -n 1 #BSUB -W 10 #BSUB -q gpu #BSUB -R "select[rtx2080]" #BSUB -gpu "num=1:mode=shared:mps=yes" #BSUB -o rtx2080_out.%J #BSUB -e rtx2080_err.%J module load matlab/R2019b matlab -nodisplay -nosplash -nodesktop -singleCompThread -r "run('gpu.m');exit;"Note that the older GPUs (M2070, M2070Q, M2090) do not support NVIDIA's mps (mps=no), while the newer GPU nodes (RTX 2080, GTX 1080, P100, K20m) do support mps(mps=yes).
bsub < rand.csh. There were no errors.
bsub < int_fun.csh.
bsub < gpu_m2070.csh. There were no errors.
MATLAB Parallel Server is available for users that need to run MATLAB jobs that require more processors than are available on a single node. Please contact us for more details about this.
rm -R ~/.matlab
Last modified: March 23 2022 13:17:15.