Matlab
Matlab is an integrated system covering tools for symbolic and numeric computations, analyses and data visualizations, modeling and simulations of real processes.
Usage
OnDemand
The most straightforward and simplest way to run Matlab is through the OnDemand service, which allows users to access Matlab directly from their web browser. This option provides an intuitive and user-friendly interface, making it an excellent choice for most users.
Choose Matlab
button among the apllications
.
As a Jupyter Notebook in Kubernetes
Matlab can also be run from the JupyterHub. For detailed instructions on how to use Matlab with Jupyter Notebook, please refer Jupyter documentation.
Remote desktop
Using Remote desktop, Matlab can be also run from a module.
This option is recommended to advanced users or as a fallback option in case OnDemand and/or Kubernetes service are down.
Licences
Warning
Matlab 9.14 and newer
For versions 9.14 and newer, MetaCentrum offers a license valid for 200 instances of MATLAB and a wide set of its toolboxes.
PBS tracks these licenses as a "matlab"
resource, therefore unless you use older Matlab version, always submit the job as
Tip
New license cannot be used outside of MetaCentrum
Troubleshooting tools
List all licenses for Matlab and its available toolboxes:
List currently issued and available licences of Matlab core:
List currently issued (reserved) licenses of Matlab core as well as toolboxes:
Get type of license used in current instance of Matlab:
Matlab 9.13 and older
For versions 9.13 and older, MetaCentrum offers a variable amount of licenses for Matlab core and its respective toolboxes.
To find number of licenses:
Warning
Troubleshooting tools
List all licenses for Matlab and its available toolboxes:
List currently issued and available licences of Matlab core:
List currently issued (reserved) licenses of Matlab core as well as toolboxes:
Get type of license used in current instance of Matlab:
ZCU users
Users of ZČU (West Bohemian University, Plzeň) have their own license for 10k MATLAB instances. Therefore they should not apply for MetaCentrum PBS resource.
How do I find out who are ZCU users?
Bring your own license
If your home institution has its own Matlab license, we can incorporate it so that you can use them while running Matlab on MetaCentrum machines.
To consult this possibility, contact us at meta@cesnet.cz.
Troubleshooting tools
Get type of license used in current instance of Matlab:
Built-in documentation
From the MATLAB command window one can use the command help to get help with a a particular command, e.g.
in the desktop environment one can use also the command doc
Online documentation is available at MATLAB Product Documentation.
Tips and notes
Matlab as interactive job
Interactive regime brings no significant speed-up comparing to running MATLAB locally on your machine unless parallelism is used. Interactive regime is recommended for development of your code and its testing.
1. OnDemand interface
This is the most easy and straighforward way to run Matlab in graphical mode. Follow the OnDemand tutorial.
2. Interactive job with remote desktop
If you prefer to stay with command line or if, for some reason, you cannot use web browser, it is possible to run Matlab as interactive job and get the graphical output to your screen by configuring remote desktop (recommended) or X-Window. Follow the tutorials to learn how to setup the graphical connection.
After the graphical connection is set up, Matlab can be run from the provided menu or by typing the following code into a terminal window:
3. Interactive job without GUI
It is possible to run MATLAB 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, though they are not visible). The relevant keywords for this case are:
Matlab as batch job
If you do not need the graphical environment, it is is possible to run MATLAB in batch regime. Create batch script myjob.sh with the following contents:
Put all your MATLAB files (your *.mat and *.m files) to the directory $HOME/matlab/
and submit this shell script like
Batch jobs are useful especially if you want to run more jobs in parallel or if you do not want to block your local machine with running jobs.
If you are planning to run more then a few Matlab jobs simultaneously, please see Running multiple MATLAB jobs.
Turn off Java Virtual Machine (JVM)
MATLAB uses its own java virtual machine for the desktop environment. Many jobs can be sped-up by turning the JVM off (option matlab -nojvm
). Keep in mind, however, that some internal functions and toolboxes (e.g. Distributed Computing Toolbox) need Java.
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.
In case the Maple symbolic environment is needed, it must be required explicitly:
CPU usage
Depending on the structure of script and functions being called, Matlab may use more CPUs than granted by the scheduler. This may result in your job being killed by the scheduler.
Incorrect CPU usage can be prevented by resorting to one of the extremes:
1. Force Matlab to work on one CPU only by using --singleCompThread
option
Obvious disadvantage is no speedup due to parallelization. On poorly (or partly) parallelized codes, or if the 1-CPU-speed-only is not an issue, --singleCompThread
is often a good choice.
2. Reserve whole computational node by exclhost option
This requirement is done on the PBS level and essentially asks the PBS to grant whole computational node to your job only. Being so, even if Matlab code uses all’ available CPUs, your job won’t be killed.
On the other hand, exclhost
is a large requirement. If the grid is busy, jobs with exclhost may wait for a long time (even several days!) to run.
exclhost
may be effective in case you have a number of Matlab jobs which use parallelization only in some critical part. You can group them into one PBS job and run them all at once in background, e.g.
3. Find the optimal number of CPUs using cgroups
If you need some level of parallelizations, but don’t want to use exclhost
, you can limit number of available CPUs by using cgroups, which is Linux kernel tool. Only some machines are able to use cgroups.
Finding the optimal number (N) of CPUs can be tricky and sometimes reduced to trial-and-error approach, especially if your code calls external libraries. You can use top command to watch the CPU load.
Distributed and parallel jobs
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).
Parallel Matlab computations in MetaCentrum
To prepare an environment for parallel computations, it is necessary to initialize a parallel pool of so-called 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:
Notes
- the function automatically detects the number of cores assigned to a job - 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 on a single node (
qsub -l select=1:ncpus=N ...
) - to make parallel computations using this function, there are 1 Matlab license and 1 Distributed Computing Toolbox license and N-1 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
- an example of parallel computation using the MetaParPool function can be found in the
/software/matlab-meta_ext/examples
directory (fileexample-parallel.m
shows the Matlab input file itself while the filerun_parallel.sh
shows an example startup script).
Running multiple MATLAB jobs simultaneously
If there is a need to run multiple instances of Matlab simultaneously, users are strongly encouraged to run them on as few nodes as possible. Matlab takes one licence per user per node, regardless of number of Matlab instances running there. For example, you can run 64 instances of Matlab on one node while using only 1 licence.
An easy way to group Matlab instances offers parallel
command.
The parallel
command is particularly useful for distributing Matlab tasks across available CPUs effectively.
First, make sure you have loaded the Matlab and Parallel Computing Toolbox modules as shown in the myjob.sh
script:
Submit your job with a command like:
By adding place=pack
, you are instructing the job scheduler to try to allocate all the requested resources on a single server if possible. This will run multiple MATLAB instances concurrently, each executing myFunction()
and saving their output to separate files.
Last updated on