The Matlab binaries are installed on many of the CSEM cluster machines. It is currently installed as /usr/bin/matlabR14 on relevant machines. However, since Matlab is commercial software, you need to purchase a license in order to use it. We have NOT installed any Matlab licenses on the cluster. Also, we have NOT installed Matlab on EVERY machine in the cluster. Each research group is able to control access to their own machines, so if a group requests that a machine NOT run Matlab jobs, then we will honor that request. This means that you must indicate to SGE whenever you want to run a Matlab job, otherwise the job may be started on the "wrong" machine and it will not find Matlab installed and thus it will crash. If you have Matlab running in your lab, it is possible to "point" your CSEM jobs at your current license server. Thus, when you run a job on the CSEM cluster, you will be using one of your already-purchased licenses. See below for more information on how to do this.
To obtain new licenses, you should contact the Duke Site License Group within OIT. For the basic Matlab suite, it is fairly reasonably priced. Yearly renewal costs are significantly cheaper than the first year's purchase. Note that you may need to buy additional "toolboxes" at additional cost, if your Matlab programs use special functionality. If you do need extra toolboxes, please email the list to hpc-support@duke.edu so that we can install the binaries/libraries that you need. At present, we request that you also set up a license server within your own department and then "point" your CSEM jobs at that server. Note that this will also allow you to run Matlab jobs on your lab machines and desktops.
One last thing to note is that since you must have a license available for Matlab to run, you may want to limit the number of CSEM jobs that your research group can launch. For example, if you have 20 licenses but you want to keep 5 available for desktop use at all times, then you should indicate that to CSEM. We can configure SGE (the queuing system) to only allow 15 Matlab jobs at a time.
There are two ways you can get Matlab to access a license manager, using the LM_LICENSE_FILE environment variable, or the '-c licensefile' command-line argument. In either case, you will need the license file from your lab's system administrator, and put it into a group-readable, but NOT world-readable, directory. Something like 'chmod o-rwx licensefile' should work. If anyone else can read the information in this file, they could steal licenses from your server. If you copy the file into 'matlabR14.lic', you can then edit your '.cshrc' to point at this file:
setenv LM_LICENSE_FILE /home/group/matlabR14.lic
If you use bash, the syntax is:
LM_LICENSE_FILE=/home/group/matlabR14.lic
export LM_LICENSE_FILE
Of course, in the above cases you would replace '/home/group' with the appropriate path to your Matlab license file. Alternately, when you run Matlab (see below for other options), you can use:
% matlabR14 -c /home/group/matlabR14.lic
Your lab's system administrator should also make sure that the network-port for the license manager is open on their routers and switches so that the license requests can come in. If they want to lock down that port to certain machines, they should contact CSEM for specific machine names that will be forwarding the license requests.
If you do not use Matlab often, you can also put this into the SGE queue script before you execute Matlab (instead of putting it in .cshrc).
Again, you should contact CSEM staff to configure SGE to limit the number of Matlab jobs that it will run simultaneously. If you only have 20 licenses, then we don't want SGE running 30 jobs at once. If this occurs, then the jobs that fail to get a valid license from the server will not run and an error message will be returned in the output ffile from SGE.
SECURITY WARNING: Matlab's license manager is not very secure, anyone who finds out your license-server and port number can check out YOUR licenses! You SHOULD NOT share this information with anyone outside of your lab, and you should make sure your license file is not world-readable.
If you have set up the license management properly, you can run Matlab with the qrsh command:
head2 % qrsh
stat-n03 % matlabR14 -nojvm -nodisplay
or:
head2 % qrsh
stat-n03 % matlabR14 -c /home/group/matlabR14.lic -nojvm -nodisplay
In the first line, on one of the head nodes, we are asking SGE to log us in to any remote machine that will run Matlab and to decrease the license count by one. We then get a prompt on some remote machine and we run Matlab. The '-nojvm' and '-nodisplay' options turn off all the graphics since they wil probably not work smoothly over the network anyway. MAKE SURE that you exit from Matlab and exit from the qrsh shell (your prompt should go back to something like 'head2 %'). All of the time that you are on the remote machine using qrsh, you are considered to be using a license, whether you are actually using Matlab or not!
Similar to the interactive use above, you can submit batch jobs to SGE using qsub. A simple script might look like:
#!/bin/tcsh
#
#$ -S /bin/tcsh -cwd
#$ -o matlab.out -j y
setenv LM_LICENSE_FILE /home/group/matlabR14.lic
matlabR14 -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 ('-o'), etc. Also in this script, we have put the license manager info directly into the queue submission (instead of .cshrc). We have also explicitly added the Matlab executable directory to the path (you could also do this in .cshrc).
One quirk worth noting is that Matlab is called with the '-r' option which tells it to immediately run a script instead of presenting an interactive prompt to the user. 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).
A simple example:
jbp@head2 [ 66 ] % more test_mtlb.m
% simple Matlab script
% do work here
A = eye(5,5);
x = (1:5)';
y = A*x;
% this outputs y to the screen
% ... where it is captured by SGE and sent to the -o file
y'
quit
Note that your Matlab script MUST call the 'quit' command at the end of it's processing or else it will run forever!