Biowulf at the NIH
RSS Feed
Matlab on Biowulf

Matlab logo Matlab integrates mathematical computing, visualization, and a powerful language to provide a flexible environment for technical computing. The open architecture makes it easy to use MATLAB and its companion products to explore data, create algorithms, and create custom tools that provide early insights and competitive advantages.

Matlab Timeout
When your interactive MATLAB session has been idle for 4 hours or more you will find MATLAB still open on your desktop. However, you will see the following message displayed in the Command Window:

"Your MATLAB session has timed out. All license keys have been returned."

This does not mean your MATLAB session has closed or exited. It just means the licenses in use have been returned to the license server. To resume a timed-out MATLAB session, just start using MATLAB again. If a license key is available, MATLAB checks it out automatically. Likewise, as you use the toolboxes and other products that you had checked out, MATLAB obtains license keys for these products as well. If a license key is not available, MATLAB periodically attempts to check out a license, issuing warning messages. After 10 warnings, if a license key is still not available, MATLAB will save the workspace and exit.

Submitting a single Matlab job
To submit Matlab scripts to the batch queue, first create a batch script file (a csh or bash file) that contains any desired PBS options and the commands to run Matlab non-interactively.

NOTE: The scripts on this page are very simple and are used ONLY as examples on how to submit jobs to the Biowulf cluster. Of course, users will typically submit much more compute-intensive jobs.

Sample file matlab.script

#!/bin/bash
#
#PBS -N Matlab
#PBS -m be 
#PBS -k oe
 
date

/usr/local/bin/matlab -nodesktop << EOF       #starts Matlab
a = 10;                                       #Matlab commands
b = 20;
c = 30;
d = sqrt((a + b + c)/pi);
exit
EOF                                            #end of Matlab commands

Submit the script using the qsub command, e.g.
qsub -l nodes=1,matlab=1 /full/pathname/matlab.script

This qsub command requests one Matlab license ('matlab=1'), so the job will remain in the queue until a license is available. You will receive email when the job is executed and when it ends, because of the line PBS -m be in the script.

Passing parameters to a Matlab batch job

You can set up a batch script and pass parameters to the job at the time of submission. For example:

#!/bin/bash
#
#PBS -N Matlab
#PBS -m be 
#PBS -j oe
 
date
echo "a is $a, b is $b, c is $c";

matlab -nodesktop << EOF       #starts Matlab
d = sqrt(($a + $b + $c/pi));
d
exit
EOF                                            #end of Matlab commands
In the script above, the values of a, b and c are expected to be passed to the script at the time of submission, in the qsub command. Submit this job with:
qsub -v a=10,b=20,c=30 -l nodes=1 matlab.bat

The output from this Matlab process will go into the standard output for the job, a file called Matlab.o###### (where ##### is the job number) in the current working directory. Click here to see the output.

Submitting a swarm of Matlab jobs

The swarm program is a convenient way to submit large numbers of jobs. You create a swarm command file containing a single line for each independent job. The swarm program will then package up the commands into batch jobs and submit them to the batch system. See the swarm page for more information.

Create a swarm command file, named matlab_swarm_jobs for instance, with each line containing a single executable script.

Sample Matlab swarm command file:

/usr/local/bin/matlab -nodesktop < /data/user/run1.m
/usr/local/bin/matlab -nodesktop < /data/user/run2.m
/usr/local/bin/matlab -nodesktop < /data/user/run3.m
[...]
where each .m file contains a sequence of Matlab commands.

Submit this swarm command file matlab_swarm_jobs to the batch system with the command:

swarm -R matlab=1 -f matlab_swarm_jobs 
or
swarm -R matlab=1,matlab-bio=1 -f matlab_swarm_jobs 

depending on which Matlab licenses (resources) are required. More information about Matlab resources is in the next section.

Note that an unlimited number of jobs can be submitted to the queue, but the number that will actually run simultaneously depends on the per-user Matlab license limit, and the number of available licenses. The batch system will restrict the number of Matlab licenses that are allocated to an individual user. This limit is subject to change depending on the number of licenses and usage.

Matlab resources (licenses)

Current Matlab License status

The PBS Batch system on the Biowulf cluster keeps track of the Matlab licenses via the Matlab "resources". Jobs requiring a Matlab license will be started or remain in the queue depending on the availability of Matlab licenses. All Matlab jobs must therefore specify the appropriate resource when the job is submitted. For example,

qsub -l nodes=1:g4,matlab=1 my_job_script
tells PBS that one Matlab license is required ('matlab=1'), as well as a node with 4Mb memory ('g4').

Similarly, a job that requires the Bioinformatics toolbox should be submitted as:

qsub -l nodes=1,matlab=1,matlab-bio=1 my_job_script
(Note that both a Matlab license and Bioinformatics Toolbox license is required).

If using Matlab interactively, the same resources must be specified:
(user input in bold)

biowulf% qsub -I -l nodes=1,matlab=1
qsub: waiting for job 801552.biobos to start
qsub: job 801552.biobos ready

p574% matlab
                                       < M A T L A B >
                           Copyright 1984-2004 The MathWorks, Inc.
                                  Version 7.0.0.19901 (R14)
                                         May 06, 2004
>> ....
>> exit

p574% exit
logout

qsub: job 801552.biobos completed

biowulf%
It is VERY IMPORTANT to exit the interactive shell as well as Matlab, otherwise the batch system will not release the resource.

Total and free licenses, the resource name, and the per-user license limit can be seen by typing 'licenses' at the Biowulf prompt or by checking this webpage. The available toolboxes and corresponding resource names are also listed in the following table:

Toolbox Resource # licenses
Matlab matlab 23
Bioinformatics Toolbox matlab-bio 2
Matlab Compiler matlab-compiler 1
Curve Fitting Toolbox matlab-curve 3
Identification Toolbox matlab-ident 2
Image Processing Toolbox matlab-image 4
Neural Network Toolbox matlab-neural 2
Optimization Toolbox matlab-opt 4
Partial Differential Equation (PDE) Toolbox matlab-pde 2
SIMULINK -
Signal Processing Toolbox matlab-signal 6
SimBiology Toolbox - 1
Statistics Toolbox matlab-stat 7
Symbolic Math Toolbox matlab-symb 2
Wavelet Toolbox matlab-wave 2
MBE/PGE -
EEGLAB -
SPM -

A '-' indicates that the toolbox is not licensed, and therefore no resource needs to be specified. Note that an unlimited number of jobs can be submitted to the queue, but they will run depending on the number of available licenses and the per-user license limit.

Matlab Compiler
The number of simultaneous Matlab jobs on the Biowulf cluster is limited by the number of Matlab licenses. An alternative is to compile your Matlab program using the Matlab compiler. Compiled programs do not require a Matlab license to run, so you can run a large number of simultaneous jobs. See Matlab compiler on Helix for details on how to use the compiler.

Since there is only one compiler license, and compilation can take a while, it may happen that the compiler license is not accessible at the time you want to compile. One way to avoid this problem is to submit your compilation as a batch job. The batch script would look something like this:

#!/bin/bash
#
#PBS -N Matlab
#PBS -m be 
#PBS -k oe

cd /data/user/myprogs
mcc -m matlab_file

This script would be submitted with:

qsub -l nodes=1,matlab-compiler=1 batchscript

The job will remain in the queue until a Matlab compiler license is available. You can check the status of the job with qstat -f jobnumber: while the job is still waiting for a license, the output from this command will report:

    comment = Insufficient amount of server resource matlab-compiler

Run the Matlab GUI interactively
If you simply log in to Biowulf and give the matlab command, matlab will run on the main Biowulf login node. This is highly discouraged because the login node has only 2 processors and is not intended for running computational applications. Instead, to run matlab interactively, you should allocate a node for interactive use and run on that node, as described in the example below.

To run the MATLAB graphics interface, an X windows connection to Biowulf is required. Open an Xwindows connection to biowulf.nih.gov, and check that it is working by typing 'xclock' at the Biowulf prompt. Now allocate an interactive node with the '-V' flag to transfer all your environment variables to the computational node. Example:

     biowulf% qsub -I -l nodes=1,matlab=1 -V
     qsub: waiting for job 423061.biobos to start
     qsub: job 423061.biobos ready

     [username@p955 ~]$ matlab&
HINT: If you receive an error message that contains "Failure to Launch Desktop Class", cd to $HOME/.matlab and remove the directory R14 and try again.

You must use Xwindows software to connect to Biowulf if you want to use the Matlab GUI. For batch jobs, or for non-GUI interactive jobs, Xwindows is not required. <>

Run Matlab interactively without the GUI

It is also possible to run Matlab interactively on the command-line, without the GUI. This would typically be useful only for debugging. Again, this should be done by allocating an interactive node. Example:

     biowulf% qsub -I -l nodes=1,matlab=1,matlab-spline=1
     qsub: waiting for job 2011.biobos to start
     qsub: job 2011.biobos ready

     p139$ matlab
      
                          < M A T L A B (R) >
                  Copyright 1984-2008 The MathWorks, Inc.
                       Version 7.7.0.471 (R2008b)
                           September 17, 2008


  To get started, type one of these: helpwin, helpdesk, or demo.
  For product information, visit www.mathworks.com.
           
     >> quit
     [username@p139 ~]$ exit
     logout

     qsub: job 2011.biobos completed
     biowulf $ 

Versions

------------------------------------------------------------------------------------- MATLAB Version 7.7.0.471 (R2008b) MATLAB License Number: 35 Operating System: Linux 2.6.18-92.el5 #1 SMP Tue Jun 10 18:51:06 EDT 2008 x86_64 Java VM Version: Java 1.6.0_04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode ------------------------------------------------------------------------------------- MATLAB Version 7.7 (R2008b) Simulink Version 7.2 (R2008b) Bioinformatics Toolbox Version 3.2 (R2008b) Curve Fitting Toolbox Version 1.2.2 (R2008b) Image Processing Toolbox Version 6.2 (R2008b) Neural Network Toolbox Version 6.0.1 (R2008b) Optimization Toolbox Version 4.1 (R2008b) Partial Differential Equation Toolbox Version 1.0.13 (R2008b) Signal Processing Toolbox Version 6.10 (R2008b) SimBiology Version 2.4 (R2008b) Spline Toolbox Version 3.3.5 (R2008b) Statistics Toolbox Version 7.0 (R2008b) Symbolic Math Toolbox Version 5.1 (R2008b) System Identification Toolbox Version 7.2.1 (R2008b) Wavelet Toolbox Version 4.3 (R2008b)
Documentation
Run Matlab in Batch mode on Unix Machines
Matlab's Search Results on Batch
Batch Queuing System on Biowulf
Matlab Help
Matlab FAQ
The Mathworks Homepage