### Using Matlab Interactively (GUI mode)

You can run Matlab with the srun command:

[abc123@login01 ~]$ srun --pty bash
[abc123@compute003 ~]$ module load matlab
[abc123@compute003 ~]$ matlab |

Using srun, we are asking Slurm to log us in to any remote machine that is currently unloaded. We then get a prompt on some remote machine and we can then run Matlab by loading the module. Depending on your network connection speed it could take about a minute for the Matlab GUI to pop up on your computer. If you need a faster GUI experience we also offer the

Shamu OnDemand Portal.

MAKE SURE that you quit from Matlab and exit from the srun shell (your prompt should go back to something like

**[abc123@login01 ~]$**. All of the time that you are on the remote machine using srun, Slurm will assume that you are making use of that entire node.

### Using Matlab Non-Interactively (Batch No GUI mode)

Similar to the interactive use above, you can submit batch jobs to Slurm using sbatch. The '

`-nojvm`

' and '

`-nodisplay`

' options turn off all the graphics. This is the preferred way of running a Matlab non-interactive job. A simple script might look like:

#!/bin/bash
#
#SBATCH --output matlab.txt
#SBATCH --job-name=test
#SBATCH --ntasks=1
#SBATCH --time=10:00
. /etc/profile.d/modules.sh
module load matlab
srun hostname
srun matlab -nojvm -nodisplay -r my_matlab_program |

One quirk worth noting is that in a Slurm script, Matlab needs to be called with the '`-r`

' option which tells it to immediately run an m-function instead of presenting an interactive prompt to the user - if you forget the '`-r`

', then your Matlab job will "run" and tie up resources for ever (since you don't have interactive access and cannot tell it to exit). Note that the script is in a file called "my_matlab_program.m" (with a ".m" extension), but the Matlab file is called with "my_matlab_program" (withOUT the ".m" extension).
Now submit the above job with sbatch (if you saved the file as myprogram.txt):

[abc123@login01 ~]$ sbatch myprogram.txt

It is EXTREMELY IMPORTANT that your Matlab script call the '`quit`

' command at the end of it's processing or else it will run forever!
--

AdminUser - 20 Jan 2017