Using Matlab Interactively
You can run Matlab with the qlogin command:
[abc123@login-0-0 ~]$ qlogin
[abc123@compute-0-3 ~]$ module load matlab/2015a
[abc123@compute-0-3 ~]$ matlab -nodisplay
, we are asking SGE 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. The '
' and '
' options turn off all the graphics since they wil probably not work smoothly over the network anyway.
MAKE SURE that you quit from Matlab and exit from the
shell (your prompt should go back to something like [abc123@login-0-0 ~]$
. All of the time that you are on the remote machine using
, SGE will assume that you are making use of 1 CPU and may not schedule other jobs onto it.
This may be a preferred way to run interactive Matlab jobs since a low-priority interactive job could be squashed by someone else's high-priority job, leading to very slow response times and a frustrating interactive experience.
Using Matlab with SGE
Similar to the interactive use above, you can submit batch jobs to SGE using
. A simple script might look like:
#$ -S /bin/bash -cwd
#$ -o matlab.out -j y
#$ -l mem_free=1.0G
module load matlab/2015a
matlab -nojvm -nodisplay -r my_matlab_program
In the first few lines, we see the "usual" SGE options for what shell to use ('
-S'), where to put screen output ('
One quirk worth noting is that in an SGE script, Matlab needs to be called with the '
' option which tells it to immediately run an m-function instead of presenting an interactive prompt to the user - if you forget the '
', 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 executable is called with "my_matlab_program" (withOUT the ".m" extension).
Now submit the above job with qsub:
[abc123@login-0-0 ~]$ qsub myprogram.qsub
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!
Running Matlab in multicore mode
Many Matlab functions have been made "multicore aware". To take advantage of this feature on Shamu requires running Matlab with the "threaded" parallel environment and also telling it how many cores are available. First add the line
to your SGE script, where the "4" is the number of CPU cores you are requesting and launch Matlab with the command line
matlab -nodisplay -r "maxNumCompThreads=$NSLOTS;my_matlab_program;quit"
where "$NSLOTS" will be the number of cores you specified in the script.
- 20 Jan 2017