MATLAB Usage
Using Matlab via CLI
Some options of interest:
- --nodesktop - skips firing up the desktop at startup (if java is running it can be fired up later)
- --nojvm - skip loading of Java, this means that no desktop can be started up
- --nosplash - skip trying to load the splash screen
matlab --nodesktop --nojvm --nosplash
Example Slurm Script
#!/bin/bash
## Two hashtags to create a comment
##
## NOTE
## - time limit not included here
## - parpool requires jvm
## SLURM REQUIRED SETTINGS
#SBATCH --partition=debug
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=44
## SLURM reads %x as the job name and %j as the job ID
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err
## Executes bash commands to run your job
## OPEN MATLAB AND RUN YOUR SCRIPT
##
/home/matlab/R2017a/bin/matlab -nodesktop -nodisplay -nosplash < /home/<username>/script.m
Memory Optimization Tricks
Things the user can do to prevent out of memory errors:
- Set variables to empty instead of clear between runs (eg x =[ ]) <- this might solve cumulative loss of memory
- Preallocate variables at the start (grab's contiguous memory blocks)
- Clear any global variables
- Run matlab with -nojvm (no java, if you're not using parallel processing)
- Vector variables as columns instead of rows
- Only load parts of things at a time using matfile.m (or write your code to work similarly)
Adding Matlab to your path
make sure your home directory has a ~/.bash_profile file and if not add one with the following:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
this will automatically load the .bashrc file on non-interactive logins (via ssh) while the .bashrc file is loaded on interactive logins (locally or via a GUI)
add the following to the bottom of your ~/.bashrc using your editor of choice (vi, nano, etc):
# User specific aliases and functions
export PATH=/home/matlab/current/bin:${PATH}
then run source ~/.bashrc to make it active immediately, or log out and back in.