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

#PBS -N Matlab
#PBS -m be 
#PBS -k oe

/usr/local/bin/matlab -nodesktop << EOF       #starts Matlab
a = 10;                                       #Matlab commands
b = 20;
c = 30;
d = sqrt((a + b + c)/pi);
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:

#PBS -N Matlab
#PBS -m be 
#PBS -j oe
echo "a is $a, b is $b, c is $c";

matlab -nodesktop << EOF       #starts Matlab
d = sqrt(($a + $b + $c/pi));
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 
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.

Regardless of the number of commands in your swarm command file, you should always specify 'matlab=1' and never a larger number. Swarm will automatically request one Matlab license for each submitted job.

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 (R)>
         Copyright 1984-2013 The MathWorks, Inc.
           R2013a ( 64-bit (glnxa64)
                    February 15, 2013
>> ....
>> exit

p574% exit

qsub: job 801552.biobos completed

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 24
Bioinformatics Toolbox matlab-bio 2
Matlab Compiler matlab-compiler 1
Curve Fitting Toolbox matlab-curve 3
Global Optimization Toolbox - 1
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
Signal Processing Toolbox matlab-signal 6
SimBiology Toolbox - 1
Statistics Toolbox matlab-stat 10
Symbolic Math Toolbox matlab-symb 2
Wavelet Toolbox matlab-wave 2
Psychtoolbox (Sciware only) -

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:

#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, 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-curve=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-2013 The MathWorks, Inc.
                     R2013a ( 64-bit (glnxa64)
                              February 15, 2013

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

     qsub: job 2011.biobos completed
     biowulf $ 


------------------------------------------------------------------------------------- MATLAB Version: (R2013a) MATLAB License Number: 35 Operating System: Linux 2.6.32-504.3.3.el6.x86_64 #1 SMP Fri Dec 12 16:05:43 EST 2014 x86_64 Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode ------------------------------------------------------------------------------------- MATLAB Version 8.1 (R2013a) Simulink Version 8.1 (R2013a) Bioinformatics Toolbox Version 4.3 (R2013a) Curve Fitting Toolbox Version 3.3.1 (R2013a) Global Optimization Toolbox Version 3.2.3 (R2013a) Image Processing Toolbox Version 8.2 (R2013a) MATLAB Compiler Version 4.18.1 (R2013a) MATLAB Distributed Computing Server Version 6.2 (R2013a) Neural Network Toolbox Version 8.0.1 (R2013a) Optimization Toolbox Version 6.3 (R2013a) Parallel Computing Toolbox Version 6.2 (R2013a) Partial Differential Equation Toolbox Version 1.2 (R2013a) Signal Processing Toolbox Version 6.19 (R2013a) SimBiology Version 4.3 (R2013a) Statistical Parametric Mapping Version 5236 (SPM8) Statistics Toolbox Version 8.2 (R2013a) Symbolic Math Toolbox Version 5.10 (R2013a) System Identification Toolbox Version 8.2 (R2013a) Wavelet Toolbox Version 4.11 (R2013a)
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