How to use MATLAB on Lewis

We have licenses for the following:
MATLAB
Bioinformatics Toolbox
Statistics Toolbox
Image Processing Toolbox
Signal Processing Toolbox
Distributed Computing Toolbox
Distributed Computing Engine
Directions for use of any of these tools may be found at the MathWorks website by entering, e.g., Bioinformatics Toolbox, in the search box.

Since Lewis was designed for parallel programming the Distributed Computing Toolbox and Engine are discussed further here as they facilitate parallel execution of MATLAB jobs.   Use the Distributed Computing Toolbox to solve problems comprising either several independent units of work (MATLAB calls these "parallel applications") or a single large computation (MATLAB calls these "distributed applications") by harnessing multiple processors on Lewis.   Jobs created using components from any of the above toolboxes may be executed in parallel.   Furthermore, the Distributed Computing Engine and Toolbox support parallelization of programs made using MATLAB toolboxes not listed here.   So code developed elsewhere should be able to run in parallel on Lewis.  

Non-graphical use of MATLAB for single cpu jobs:

The MATLAB script should be submitted to the LSF scheduler using the bsub command which calls a script with the job requirements specified.  In order to prevent LSF from running more MATLAB jobs than there are licenses available (10 at present), a MATLAB license resource usage and monitoring scheme has been implemented in LSF.   This is indicated by argument to the -R flag in the "myjob" script below which calls a MATLAB script called onecpu.m.   For more about scripts for job submission to LSF please go here.
[userid@lewis]$ cat myjob
#BSUB -J myjob
#BSUB -n 1
#BSUB -R "rusage[matlab=1:duration=1]"
#BSUB -oo myjob.o%J
#BSUB -eo myjob.e%J
matlab -nodisplay -r onecpu
Please note the use of the -nodisplay option since this is not an interactive job.   This script could be launched as follows:
[userid@lewis]$ bsub < myjob
The onecpu.m MATLAB script would contain MATLAB commands.   The following is a simple example:
[userid@lewis]$ cat onecpu.m
A = fix(100*rand(5,6))
B = fix(100*rand(6,3))
C = A * B

Non-graphical use of MATLAB for distributed jobs:

The number of jobs that can be submitted is limited by the LSF scheduler about which more can be learned here. The number of MATLAB jobs that can be run at one time will be limited by the number of MATLAB licenses.   Any remaining MATLAB jobs will eventually run, providing the total number does not exceed the limit set by LFS.   The following MATLAB script will submit 3 jobs to Lewis via the LSF scheduler.  
[userid@lewis]$ cat distscript.m
sched = findResource('scheduler', 'configuration', 'lsf')
set(sched,'configuration','lsf')
job = createJob(sched);
createTask(job, @sum, 1, {[1 1]});
createTask(job, @sum, 1, {[2 2]});
createTask(job, @sum, 1, {[3 3]});
submit(job)
waitForState(job, 'finished')
results = getAllOutputArguments(job)
% destroy(job)
The first two lines show the proper way to set up a scheduler in our environment.  The last line (destroy(job)) is commented out to allow debugging. 

The script should be submitted to LSF using the bsub command and the script shown above (myjob) with the program name changed from onecpu to distscript.   The number of processors requested (-n) in myjob is still set to 1 even though more cpus are asked for.   The file distscript.m asks for 3 jobs ("createTask()" is called three times) determining the number of cpus for use by MATLAB.   Users not needing graphics should submit their MATLAB jobs using the -nodisplay option.  

For more information about writing scripts for submitting programs to LSF on Lewis go here.

Graphical use of MATLAB:

Windows
Users of a MicroSoft operating system must have an Xwindowing system for the MATLAB window to display.  The Cygwin Xserver may be used for this and directions for downloading and installing it may be found here.
For non-parallel graphical usage:
Once you have a window open type the command gocomp.   This will take you to a node on Lewis designated for interactive sessions.   To invoke MATLAB do not use lsrun.   Just type "matlab" and a MATLAB session will start.   For brief help type one of these: help, help general, helpwin, helpdesk, or demo.   Exit MATLAB by typing either "exit" or "quit".  
For parallel graphical usage:
Execution of programs constructed using the Distributed Computing Toolbox can be launched from the head node, so do not use the gocomp command in this case.
Linux
From your linux machine you need X11 forwarding. The following commands should get you there.
xhost +
ssh -X lewis.rnet.missouri.edu
gocomp
matlab