MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java™.
Before using Matlab, you should check if required environment variables are properly set. If they are not, set them following these steps:
Export Matlab variables on your user profile (you can define it on your .basrc profile):
When setting environment vatiables in .bashrc, a new login event is required to have them processed. Logout, login again and check if envirionment variables are correclty set. The output shoud be as follows:
ijimenez@login:~$ which matlab
ijimenez@login:~$ echo $MATLAB_JAVA
ijimenez@login:~$ echo $OLDPWD
Once done, connect to a node with 'qrsh' command. You'll be redirected to a free computing node where you will run Matlab:
Warning: Permanently added '[node08]:55494,[192.168.7.108]:55494' (ECDSA) to the list of known hosts.
Linux node08 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Running interactive Matlab sessions
Following is the easiest way of running Matlab in the cluster. This method should be only used to testing previously, outside-developed code purposes. Developing code directly on the cluster is not recommended and shoul be avoided as a general rule.
From the node, you can choose to run Matlab with or without graphical support (default is to have GUI). Execute Matlab GUI console using 'matlab &' command on your shell:
Your graphical pannel looks like this:
On the left panel you'll see your $HOME files. You can run an script from matlab gui or drag and drop example.m script to Command Window.
Run command is executed automatically:
If oyu don't need graphical Matlab support you can call Matlab with the -nosplash -nodesktop modifiers:
ijimenez@node06:~$ matlab -nosplash -nodesktop
< M A T L A B (R) >
Copyright 1984-2013 The MathWorks, Inc.
R2013b (220.127.116.111) 64-bit (glnxa64)
August 13, 2013
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
ans = 2 >>
Fig 1. Matlab runtime modifiers
|-help||Help||Shows Matlab help|
|-e||Display environment variables||Display ALL environment variables. If the status return is not 0, some corrective actions may be needed. Matlab is not run.|
|-n||Display diagnostics||Display environment variables, libraries, arguments and other diagnostic information to the standard output. Matlab is not run|
|-arch||Architecture request||Start Matlab assuming processor architecture arch.|
|-nodisplay||Disable X||Do not display any X command. Matlab's JVM is started|
|-nojvm||Disable Matlab JVM||Do not start Matlab's JAva virtual machine. Any Matlab extension depending on JVM will not run|
|-r <file.m>||Run file inmediately||Start Matlab and run file.m inmediately after|
|-logfile file.log||Send output to file||Make a copy of all output to file.log. This include crash reports.|
To send Matlab jobs in the background, a combination of Matlab modifiers and SGE options will be used. In the next steps we'll cover how to send a Matlab job to a SGE queue:
1. Write your matlab source in a file with .m extension, the next is named as 'example.m'
x = [1 2 3 4];
fprintf('Example number = %i\n', x)
2. Write a submit job script named as 'matlab-job.sh'. Place it wherever on your home directory, and specify here the desired options.
#$ -N MatlabJob
#$ -o matlab.$JOB_ID.out
#$ -e matlab.$JOB_ID.err
/soft/MATLAB/R2013b/bin/matlab -nojvm -nodisplay -r "example;quit;"
Fig 2. Parameters used in matlab-job.sh
|-N <job_name>||Job Name Definition||The name of the job. The name should follow the "name" definition in sge_types(1). Invalid job names will be denied at submit time.|
|-cwd||Current working directory||Use current working directory.|
|-o <file_name>||Output file path||Standard output to file path identified by JOB_ID.|
|-e <file_name>||Error file path||Error output to file path identified by JOB_ID.|
|-r <comand1;commandN>||Command run||Execute comands separated by ';'. Note that file extension is not defined.|
|-nojvm||JVM disabled||Does not start the JVM software and uses current window. Graphics will not work without the JVM.|
|-nodisplay||Display disabled||Also starts the JVM and does not start the desktop in addition it also ignores Commands and the DISPLAY environment variable in LINUX.|
|-r||Run inmediately||Start Matlab and run file.m inmediately after|
3. Submit your matlab job:
uhpc@login:~$ qsub matlab-job.sh
Your job 153873 ("MatlabJob") has been submitted
4. Monitor the job status:
job-ID prior name user state submit/start at queue slots ja-task-ID
153873 0.00000 MatlabJob uhpc qw 12/20/2013 16:41:34 1
5. When the job is finished, the output files are created in your Current Working Directory:
-rw-r--r-- 1 uhpc info_users 0 Dec 20 16:16 matlab.153873.err
-rw-r--r-- 1 uhpc info_users 403 Dec 20 16:16 matlab.153873.out
6. The standard output results of Matlab, file with stderr is empty(job without errors):