Best practice for compiling MATLAB code

It’s been some time since I’ve needed to use MATLAB non-interactively and am wondering what’s the best practice for compiling my code and submitting as batch jobs. Additionally, my center’s HPC has a limited number of shared MATLAB licenses, so ideally I would be setting up a MATLAB runtime environment to avoid abusing my “share”.

Is the deploytool still a recommended method? Are there any good tools, walkthroughs, steps I should follow?

Thanks!

I have never used deploytool. But for submitting MATLAB batch jobs, I have used job scripts like this on the cluster.

# !/bin/bash
#BSUB -n 1
#BSUB -W 01:00

bsub -R "matlab -nodisplay -singleCompThread -r <name_of_matlabscript>"

you may tune this script for a different job scheduler like SLURM or PBS. More details are available in this link (https://scicomp.ethz.ch/wiki/MATLAB). I do not have experience in compiling MATLAB programs, but the link provided above contains some information on compilation in the cluster.

The latest versions of Matlab can now be invoked noninteractively with the flag “-batch”. This is recommended over “-r” (or “<“) with “-nodisplay” because it:

  • Starts without the desktop
  • Does not display the splash screen
  • Disables changes to preferences
  • Disables toolbox caching
  • Logs text to stdout and stderr
  • Does not display modal dialog boxes
  • Exits automatically with exit code 0 if script executes successfully. Otherwise, MATLAB terminates with a non-zero exit code.

Example running program1.m:
matlab -batch “program1”