8
Comment:

9338
Explain different available versions and highlight matching compiler version with runtime

Deletions are marked like this.  Additions are marked like this. 
Line 1:  Line 1: 
Matlab  #rev 20200902 davidsch #rev 20180828 davidsch <<TableOfContents(3)>> = Matlab = Matlab is a highlevel language and interactive environment for numerical computation, visualization, and programming. == Start Matlab == * Start it on Linux (example for GNOME desktop): Type "terminal" in the search field, then click the Terminal icon. Then, type in the opened terminal window, "matlab" (Enter). * Start it on Windows: Start menu  Matlab  Matlab. You may also use the search function, entering "matlab" in the search field. === Available versions === Matlab is provided through the [[https://www.sepp.ee.ethz.ch/SEPP package system]]. There are several versions available which can be listed on the command line with `sepp grep E '^IL matlab'`: {{{ IL matlab2021bfg 20211214 Application for interactive scientific computation IL matlab2020bme 20210119 Application for interactive scientific computation IL matlab2019bfg 20191220 Application for interactive scientific computation IL matlab2018bfg 20181025 Application for interactive scientific computation ... }}} Typing `matlab` on the command line and pressing `TAB` for autocompletion shows available versions as well: {{{ matlab matlab2017b matlab2018bfg matlab2021b matlab8.3r2014afg matlab2015b matlab2017bfg matlab2019b matlab2021bfg matlab2015bfg matlab2018a matlab2019bfg matlab7.14r2012a matlab2016b matlab2018asd matlab2020b matlab7.14r2012abs matlab2016bfg matlab2018b matlab2020bme matlab8.3r2014a }}} The command `matlab` without any suffix points to the current '''default''' version of Matlab. Which version this is can be shown with the following command sequence: {{{#!highlight bash numbers=disable matlab nodisplay nojvm r "disp(version('release')); exit" grep E '^[09]{4}[ab]{1}$' }}} == First Steps == Matlab has a lot of tutorials by its own. You can find them in Matlab: Help  Product Help  User Guides = Matlab Compiler = * `mcc` (both: UNIX and Windows) points to the default MATLAB Compiler. You can use the `mcc` command either from the MATLAB command prompt or the commandline * The advantage of a compiled matlab program is, that no matlab license is taken from the ETHlicenses. This means that you should prefer to compile matlab programs for which you intend to run many instances (e.g. hundreds, in a distributed computing setup for instance). If you do not compile the programs, one license is checked out on the ETH server for each Matlab instance you are running. As the overall amount of licenses on the ETH server is limited, checking out hundreds of licenses for a distributed computing job could lead to a license shortage, meaning that you and other users at ETH cannot start new matlab instances, until some allocated licenses are released. == How to use Matlab Compiler on Linux == This section shows an example on how to use MATLAB Compiler to code and build standalone applications. == Magic Square Example == A magic square is an array of integers arranged so that their sum is the same when added vertically, horizontally, or diagonally. Copy the following code in a textfile and save it as `magicsquare.m`: {{{ function m = magicsquare(n) %MAGICSQUARE generates a magic square matrix of the size % specified by the input parameter n. % Copyright 20032011 The MathWorks, Inc. if ischar(n) n=str2num(n); end m = magic(n); m }}} Important: When this program is executed in a Linux terminal, we have to use the function `str2num` (string to number). Arguments are used as strings, that's why they have to be converted into a number in Matlab. Compile the `magicsquare` function (with the command: `mcc`) in a Linux terminal. * Open a terminal and change to the directory where you stored `magicsquare.m`, then enter: {{{ mcc mv magicsquare.m }}} * This will generate two files: `magicsquare` and `run_magicsquare.sh` * `magicsquare` is the main file of the application. * `run_magicsquare.sh` is the script to start the application. It sets up the MCR (MATLAB Compiler Runtime) environment for the current platform architecture (`$ARCH`) and executes the specified command. To run the `magicsquare` program we give the shell script two arguments. The first is the path to the Matlab Compiler Runtime. The second argument in this example is an applicationspecific param for the program `magicsquare` itself.<<BR>> /!\ '''Important:''' The version of the compiler Runtime needs to be same that was used by the compiler `mcc`. If you used the default of `mcc`, the version of the default runtime can be passed with {{{#!highlight bash numbers=disable ./run_magicsquare.sh /usr/pack/$(matlab nodisplay nojvm r "disp(version('release')); exit" grep E '^[09]{4}[ab]{1}$') }}} Or typed directly if you know the version: {{{ > ./run_magicsquare.sh /usr/pack/matlab2021bfg 5  Setting up environment variables  LD_LIBRARY_PATH is .:/usr/pack/matlab2021bfg/runtime/glnxa64:/usr/pack/matlab2021bfg/bin/glnxa64:/usr/pack/matlab2021bfg/sys/os/glnxa64:/usr/pack/matlab2021bfg/sys/opengl/lib/glnxa64 m = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 }}} More help on `mcc`: Enter on commandline: `mcc help` Or see the MatlabDocumentation in Matlab: Help  Product Help  Matlab Compiler = Matlab on the cluster (Condor, Slurm) = * Every MatlabJob on the cluster uses one license. Therefore its very important, to run only compiled Matlab applications on the cluster. * Don't expand the Matlab search path with a large number of directories on NFSmounted resources such as your home directory. Don't use the matlab function `genpath` to expand the Matlab search path. * Set the environment variable `MCR_CACHE_ROOT` to a directory on your local computer (with `MCR_ROOT_CACHE` pointing to your (NFS)home directory, the load on the home servers becomes too high: {{{ mkdir p /tmp/$USER export MCR_CACHE_ROOT=/tmp/$USER }}} If you get the error message: "Could not access MCRcomponent cache", you need to make sure the path where `MCR_ROOT_CACHE` points to is used solely by your MATLAB instance (and not other instances, e.g. from other users). Also make sure you have the right to access the path you've set with `MCR_ROOT_CACHE`. * Use the following options for `mcc` when compiling: {{{ mcc m R singleCompThread R nodisplay R nojvm foo.m }}} * `R singleCompThread`: Limits MATLAB to a single computational thread. By default, MATLAB makes use of the multithreading capabilities of the computer on which it runs. * `R nodisplay`: Do not display any X windows or X commands. * `R nojvm`: Start MATLAB without the JVM software. Any tools that require Java software, such as the desktop/ GUI tools, cannot be used. Handle graphics and related functionality are not supported; MATLAB produces a warning when you use them. If you need to use Java software, you can run `mcc` without this option. = Limited amount of MATLAB licenses = The number of MATLAB licenses is limited. To ensure a fair and efficient usage of the (site)licenses throughout the ETH, the following measures have been put in place: * Matlab instances being idle for more than four hours will return their allocated license to the license pool * Excessive usage of licenses will be monitored and users will be asked to return licenses if needed == How to avoid allocating too many MATLAB licenses? == 1. '''Compile''' your MATLAB program. The best approach to avoid excessive usage of MATLAB licenses is to compile your MATLAB program. The resulting executable does not need ANY MATLAB licenses! This frees you from all MATLAB license restrictions and also allows you to provide your executable to users without a MATLAB installation. 1. '''Exit''' MATLAB after finishing your work. Only exiting matlab will really release all allocated licenses. 1. '''Announce''' the need for many MATLAB licenses, e.g. due to a MATLAB course, by registering your need in advance. Countermeasures can be taken in this case by the IT department which ensure that the requested amount of licenses will available. Use the IDES contact form therefore: https://idts.ethz.ch/hdweb/ (Nethzlogin required) 1. '''Buy your own''' MATLAB licenses if you must have a guaranteed 24/7 license availability or if you need constantly an excessive amount of licenses. == How do I know which MATLAB licenses I use? == * The MATLAB command `license('inuse')` lists the licenses allocated for the current MATLAB session. == How do I know how many MATLAB licenses are used by whom? == * You can list all checked out MATLAB base licenses using the following command on Linux: {{{ lmutil lmstat c 1965@licmatlab.ethz.ch f MATLAB  less }}} * MATLAB base licenses and all Toolbox licenses are listed using the following command: {{{ lmutil lmstat c 1965@licmatlab.ethz.ch a  less }}}  [[CategoryBTCH]] 
Contents
Matlab
Matlab is a highlevel language and interactive environment for numerical computation, visualization, and programming.
Start Matlab
 Start it on Linux (example for GNOME desktop): Type "terminal" in the search field, then click the Terminal icon. Then, type in the opened terminal window, "matlab" (Enter).
 Start it on Windows: Start menu  Matlab  Matlab. You may also use the search function, entering "matlab" in the search field.
Available versions
Matlab is provided through the SEPP package system. There are several versions available which can be listed on the command line with sepp grep E '^IL matlab':
IL matlab2021bfg 20211214 Application for interactive scientific computation IL matlab2020bme 20210119 Application for interactive scientific computation IL matlab2019bfg 20191220 Application for interactive scientific computation IL matlab2018bfg 20181025 Application for interactive scientific computation ...
Typing matlab on the command line and pressing TAB for autocompletion shows available versions as well:
matlab matlab2017b matlab2018bfg matlab2021b matlab8.3r2014afg matlab2015b matlab2017bfg matlab2019b matlab2021bfg matlab2015bfg matlab2018a matlab2019bfg matlab7.14r2012a matlab2016b matlab2018asd matlab2020b matlab7.14r2012abs matlab2016bfg matlab2018b matlab2020bme matlab8.3r2014a
The command matlab without any suffix points to the current default version of Matlab. Which version this is can be shown with the following command sequence:
matlab nodisplay nojvm r "disp(version('release')); exit" grep E '^[09]{4}[ab]{1}$'
First Steps
Matlab has a lot of tutorials by its own. You can find them in Matlab: Help  Product Help  User Guides
Matlab Compiler
mcc (both: UNIX and Windows) points to the default MATLAB Compiler. You can use the mcc command either from the MATLAB command prompt or the commandline
 The advantage of a compiled matlab program is, that no matlab license is taken from the ETHlicenses. This means that you should prefer to compile matlab programs for which you intend to run many instances (e.g. hundreds, in a distributed computing setup for instance). If you do not compile the programs, one license is checked out on the ETH server for each Matlab instance you are running. As the overall amount of licenses on the ETH server is limited, checking out hundreds of licenses for a distributed computing job could lead to a license shortage, meaning that you and other users at ETH cannot start new matlab instances, until some allocated licenses are released.
How to use Matlab Compiler on Linux
This section shows an example on how to use MATLAB Compiler to code and build standalone applications.
Magic Square Example
A magic square is an array of integers arranged so that their sum is the same when added vertically, horizontally, or diagonally. Copy the following code in a textfile and save it as magicsquare.m:
function m = magicsquare(n) %MAGICSQUARE generates a magic square matrix of the size % specified by the input parameter n. % Copyright 20032011 The MathWorks, Inc. if ischar(n) n=str2num(n); end m = magic(n); m
Important: When this program is executed in a Linux terminal, we have to use the function str2num (string to number). Arguments are used as strings, that's why they have to be converted into a number in Matlab.
Compile the magicsquare function (with the command: mcc) in a Linux terminal.
Open a terminal and change to the directory where you stored magicsquare.m, then enter:
mcc mv magicsquare.m
This will generate two files: magicsquare and run_magicsquare.sh
magicsquare is the main file of the application.
run_magicsquare.sh is the script to start the application. It sets up the MCR (MATLAB Compiler Runtime) environment for the current platform architecture ($ARCH) and executes the specified command.
To run the magicsquare program we give the shell script two arguments. The first is the path to the Matlab Compiler Runtime. The second argument in this example is an applicationspecific param for the program magicsquare itself.
Important: The version of the compiler Runtime needs to be same that was used by the compiler mcc. If you used the default of mcc, the version of the default runtime can be passed with
./run_magicsquare.sh /usr/pack/$(matlab nodisplay nojvm r "disp(version('release')); exit" grep E '^[09]{4}[ab]{1}$')
Or typed directly if you know the version:
> ./run_magicsquare.sh /usr/pack/matlab2021bfg 5  Setting up environment variables  LD_LIBRARY_PATH is .:/usr/pack/matlab2021bfg/runtime/glnxa64:/usr/pack/matlab2021bfg/bin/glnxa64:/usr/pack/matlab2021bfg/sys/os/glnxa64:/usr/pack/matlab2021bfg/sys/opengl/lib/glnxa64 m = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
More help on mcc: Enter on commandline: mcc help
Or see the MatlabDocumentation in Matlab: Help  Product Help  Matlab Compiler
Matlab on the cluster (Condor, Slurm)
 Every MatlabJob on the cluster uses one license. Therefore its very important, to run only compiled Matlab applications on the cluster.
Don't expand the Matlab search path with a large number of directories on NFSmounted resources such as your home directory. Don't use the matlab function genpath to expand the Matlab search path.
Set the environment variable MCR_CACHE_ROOT to a directory on your local computer (with MCR_ROOT_CACHE pointing to your (NFS)home directory, the load on the home servers becomes too high:
mkdir p /tmp/$USER export MCR_CACHE_ROOT=/tmp/$USER
If you get the error message: "Could not access MCRcomponent cache", you need to make sure the path where MCR_ROOT_CACHE points to is used solely by your MATLAB instance (and not other instances, e.g. from other users). Also make sure you have the right to access the path you've set with MCR_ROOT_CACHE.
Use the following options for mcc when compiling:
mcc m R singleCompThread R nodisplay R nojvm foo.m
R singleCompThread: Limits MATLAB to a single computational thread. By default, MATLAB makes use of the multithreading capabilities of the computer on which it runs.
R nodisplay: Do not display any X windows or X commands.
R nojvm: Start MATLAB without the JVM software. Any tools that require Java software, such as the desktop/ GUI tools, cannot be used. Handle graphics and related functionality are not supported; MATLAB produces a warning when you use them. If you need to use Java software, you can run mcc without this option.
Limited amount of MATLAB licenses
The number of MATLAB licenses is limited. To ensure a fair and efficient usage of the (site)licenses throughout the ETH, the following measures have been put in place:
 Matlab instances being idle for more than four hours will return their allocated license to the license pool
 Excessive usage of licenses will be monitored and users will be asked to return licenses if needed
How to avoid allocating too many MATLAB licenses?
Compile your MATLAB program. The best approach to avoid excessive usage of MATLAB licenses is to compile your MATLAB program. The resulting executable does not need ANY MATLAB licenses! This frees you from all MATLAB license restrictions and also allows you to provide your executable to users without a MATLAB installation.
Exit MATLAB after finishing your work. Only exiting matlab will really release all allocated licenses.
Announce the need for many MATLAB licenses, e.g. due to a MATLAB course, by registering your need in advance. Countermeasures can be taken in this case by the IT department which ensure that the requested amount of licenses will available. Use the IDES contact form therefore: https://idts.ethz.ch/hdweb/ (Nethzlogin required)
Buy your own MATLAB licenses if you must have a guaranteed 24/7 license availability or if you need constantly an excessive amount of licenses.
How do I know which MATLAB licenses I use?
The MATLAB command license('inuse') lists the licenses allocated for the current MATLAB session.
How do I know how many MATLAB licenses are used by whom?
You can list all checked out MATLAB base licenses using the following command on Linux:
lmutil lmstat c 1965@licmatlab.ethz.ch f MATLAB  less
MATLAB base licenses and all Toolbox licenses are listed using the following command:
lmutil lmstat c 1965@licmatlab.ethz.ch a  less