Matlab
Obsah
Description
MATLAB is an integrated system covering tools for symbolic and numeric computations, analyses and data visualizations, modeling and simulations of real processes etc. Next to MATLAB and Simulink there are other supplementary toolboxes available (see also section Licenses below).
Availability
On all machines one can load the currently available MATLAB version
using SW modules.
Currently it is MATLAB version 8.7 (module matlab
), however, the older versions  8.6, 8.5, 8.4, 8.3, 8.2, 8.1, 8.0 and 7.14 (modules matlabVERSION
, e.g. matlab8.2
)  are also available.
Usage
Loading SW module matlab and running MATLAB:
$ module add matlab
$ matlab
In the following text $MATLABROOT means the directory /software/matlab8.3.
Command line parameters are described here.
Notice: This application use or needs GUI – graphical interface. To use the application in graphical mode see Remote desktop or XWindow.
Starting the Matlab with Maple symbolic environment
Since the Maple's symbolic environment is not fully compatible with the Matlab's symbolic environment, the Matlab symbolic environment is used by default when starting the Matlab within MetaCentrum environment.
To start Matlab having Maple symbolic environment enabled, it is necessary to provide the system with an explicit requirement for it (using the following sequence of commands):
$ module add matlab
$ matlabsymmaple # the options of this command are the same as for the original 'matlab' command
# an alternative  the 'matlabsymmatlab' command  explicitly requires the Matlab symbolic environment
Let us refer you to the following video for further information about using the Maple's symbolic environment within Matlab.
Documentation
From the MATLAB command window one can use the command help to get help with a a particular command, e.g.
>> help rand
in the desktop environment one can use also the command doc
>> doc rand
Documentation in PDF and HTML format is available in the directory $MATLABROOT/help.
Online documentation is available at the address MATLAB Product Documentation.
Licences
There exists a permanent licence type "College" (for operating systems UNIX and MS Windows) that is available to all the national grid infrastructure MetaCentrum users as well as to all students and employees of
 Masaryk university in Brno,
 ZČU in Plzeň and
 ČVUT in Praha.
MATLAB can be installed freely on every computer at these universities and once running it takes licences from a pool of available licences. These licences are currently maintained by three licence servers: at ZČU in Plzeň, at ÚVT UK in Praha and at ÚVT MU in Brno.
Names and number of licences:
 MATLAB 450
 SIMULINK 150




Together with the permanent licence a complete maintenance (including new version updates of all mentioned products) is also available and it is annually renewed.
A list of licenses can be obtained by
$ /software/matlab8.7/etc/lmstat s skiritf.ics.muni.cz a  grep "in use"
Licences and scheduler
You need to tell the Batch system that the job will require a licence. That is necessary to run the job in the time there are available licences. Each Matlab package have it's own resource available. So if you need to use for example heavily used Statistics_Toolbox you need to submit your qsub command like this:
qsub ... l matlab=1 l matlab_Statistics_Toolbox=1 ...
Supported platforms
Current version supports the following operating systems: Solaris, HPUX, Linux, MacOSX and MS Windows, older versions are available also on: Digital Unix (Tru64), Irix and AIX.
Program administrator
MATLAB Homepage
Tips
 If asking for one CPU only, use matlab command line parameter singleCompThread.
 MATLAB uses its own java virtual machine for the desktop environment. It is possible to turn the JVM off (run matlab nojvm) to speed up many jobs. WARNING: some internal functions and toolboxes (for example Ditributed Computing Toolbox) need java.
Detailed HOWTO
In the following text we explain how to run an interactive/batch single/parallel MATLAB job in MetaCentre environment.
Interactive job
For an interactive work, Matlab can be run either on frontends or computing nodes (however, use the frontends just for a trivial nondemanding computations or data preparation/analysis). To get a computing node for an interactive work read How to compute/Interactive jobs first.
Once the interactive job starts, one may start and use Matlab both in text as well as graphical mode. To prepare the graphical environment, follow the instructions available at remote desktop page. Then, the Matlab can be run from the provided menu or by typing the following code into a terminal window:
$ module add matlab
$ matlab
Alternatively, it is possible to run MATLAB just in the text regime only, when the graphical mode is not necessary (you may even create figures, work with them, save them to a disk, they are only invisible):
$ matlab nosplash nodisplay nodesktop
Interactive regime does not bring any significant speedup comparing to running MATLAB locally on your machine unless parallelism is used. Interactive regime may be used to development of your code, testing its execution (strongly recommended) and after the development you may run it in a batch.
Batch job
It is possible to run MATLAB without the desktop environment in the batch regime. Use arguments nodisplay and r. Create a shell script myjob1.sh with the following contents:
#!/bin/bash
# set PATH to find MATLAB
module add matlab
# go to my working directory
cd $HOME/matlab/
# run MATLAB
matlab nosplash nodesktop nodisplay r "myFunction()"
# or in a different way:
#matlab nosplash nodesktop nodisplay < myFunction.m > output.txt
Put all your MATLAB files (your *.mat and *.m files) to the directory $HOME/matlab/ . Submit this shell script like
qsub l select=1:ncpus=10:mem=1gb l matlab=1 myjob1.sh
Batch jobs are useful especially if you want to run more jobs in parallel or if you do not want to block your machine with running jobs. Read more information about Batch system (scheduler).
Distributed and parallel jobs in MATLAB
MATLAB now supports distributed and parallel jobs on multiprocessor machines using the Parallel Computing Toolbox (the name of the licence is Distrib_Computing_Toolbox) and on clusters using the MATLAB Distributed Computing Server (name of the licence is MATLAB_Distrib_Comp_Engine).
 Note: Since MATLAB version R2010b there is also an extended support for PBS and TORQUE schedulers that allows to easily run parallel/distributed jobs directly from the MATLAB environment  see more at Distributed computations using Torque.
Parallel Matlab computations in MetaCentrum
To prepare an environment for parallel computations, it is necessary to initialize a parallel pool of socalled workers using the function parpool
(called matlabpool
in previous versions). This standard initialization requires to specify an amount of workers to initialize; moreover, thanks to shared filesystems, it may also result in a collision when trying to initialize several pools simultaneously.
 To make the initialization of parallel pool easier as well as to cope with the collision problems, we have prepared a function
MetaParPool
:
MetaParPool('open'); % initializes parallel pool (returns the number of initialized workers)
...
x = MetaParPool('size'); % allows to discover the size of parallel pool (returns the number of workers)
% may be called as MetaParPool('info'); as well
...
% a computation using parfor, spmd and other Matlab functions
...
MetaParPool('close'); % closing the parallel pool
 Notes:
 the function automatically detects the number of cores assigned to a job (max. 12)  the size of parallel pool is always automatically set based on resources assigned to a job
 it is necessary to ask for N computing cores (max. 12) on a single node (
qsub l nodes=1:ppn=N ...
)
 it is necessary to ask for N computing cores (max. 12) on a single node (
 to make parallel computations using this function, there are 1 Matlab license and 1 Distributed Computing Toolbox license necessary
 a reservation can be thus performed via
l matlab=1,matlab_Distrib_Computing_Toolbox=1
 see #Tips
 a reservation can be thus performed via
 an example of parallel computation using the
MetaParPool
function can be found in the/software/matlabmeta_ext/examples
directory (fileexampleparallel.m
shows the Matlab input file itself while the filerun_parallel.sh
shows an example startup script).  more information about parallel computing in Matlab can be found on producer's webpage
 the function automatically detects the number of cores assigned to a job (max. 12)  the size of parallel pool is always automatically set based on resources assigned to a job
Distributed Matlab computations in MetaCentrum
Distributed computations in Matlab are commonly performed via parametrization of the internal scheduler (of type torque)  once a computation is ready, the internal scheduler starts new common PBS jobs, which perform the required functionality after their startup (see more information at Distributed computations using Torque). However, such behaviour may not be comfortable  the master process (preparing the distributed computation) may wait for an undefined time to finish the created PBS jobs; also, the parametrization of the internal scheduler as well as nodes' specification may also not be convenient.
 To make the preparation of the distributed pool easier, we have prepared a function
MetaGridPool
:
js = MetaGridPool('open'); % initializes distributed pool (returns the internal scheduler for preparation of the computation)
...
x = MetaGridPool('size'); % returns the size of the initialized pool (number of workers)
MetaGridPool('info'); % shows detailed information about the initialized pool
...
% distributed computation (functions createJob, createTask, wait, etc.)
...
MetaGridPool('close'); % closes the distributed pool
 Notes:
 the function automatically detects the number of nodes and cores assigned to a job  the size of the pool is always set based on resources really reserved for a job (the number of workers is decreased by 1  a single core is reserved for the master process)
 it is necessary to ask for X computing nodes and Y computing cores (
qsub l nodes=X:ppn=Y ...
)
 it is necessary to ask for X computing nodes and Y computing cores (
 to perform distributed computations, there are 1 Matlab license, 1 Distributed Computing Toolbox license and N1 MATLAB Distributed Computing Engine licenses necessary (N denotes the number of requested cores)
 a reservation can be thus performed via
l matlab=1,matlab_Distrib_Computing_Toolbox=1,matlab_MATLAB_Distrib_Comp_Engine=7
 see more at #Tips
 a reservation can be thus performed via
 an example of distributed computation using the
MetaGridPool
function can be found in the/software/matlabmeta_ext/examples
directory (fileexampledistributed.m
shows the Matlab input file itself while the filerun_distributed.sh
shows an example startup script).  more information about distributed computing in Matlab can be found on producer's webpage
 the function automatically detects the number of nodes and cores assigned to a job  the size of the pool is always set based on resources really reserved for a job (the number of workers is decreased by 1  a single core is reserved for the master process)