Differences between revisions 21 and 29 (spanning 8 versions)
Revision 21 as of 2012-10-02 15:31:45
Size: 5701
Editor: bifelix
Comment:
Revision 29 as of 2013-03-19 16:10:03
Size: 6156
Editor: gfreudig
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
 * Start it on Linux: Applications - Accessories - Terminal. Then type: Matlab (Enter)  * Start it on Linux: Applications - Accessories - Terminal. Then type: matlab (Enter)
Line 14: Line 14:
 * mcc (both: UNIX and Windows) is the MATLAB Compiler. You can use the mcc command either from the MATLAB command prompt (MATLAB mode) or the command-line (standalone mode).  * mcc (both: UNIX and Windows) is the MATLAB Compiler. You can use the mcc command either from the MATLAB command prompt or the command-line
Line 18: Line 18:
 * This chapter describes how to use MATLAB Compiler to code and build standalone applications. This section shows an example on how to use MATLAB Compiler to code and build standalone applications.
Line 21: Line 21:
 * 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 text-file and save it as magicsquare.m
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 text-file and save it as magicsquare.m
Line 39: Line 38:
Important: When this programm is runned in a Linux-Terminal, we have to use the function str2num (string to number). Arguments are used as strings, thats why it has to be converted in a number. Important: When this programm is runned in a Linux-Terminal, we have to use the function str2num (string to number). Arguments are used as strings, thats why they have to be converted in a number in Matlab.
Line 41: Line 40:
Compile the magicsqure function (with the command: mcc) in a Linux-Terminal
Line 42: Line 42:
 * Compile the magicsqure function (with the command: mcc):
Line 48: Line 46:
 * This generates you 2 files: magicsquare and magicsquare.sh  * This generates you 2 files: magicsquare and run_magicsquare.sh
Line 50: Line 48:
  * magicsquare.sh is the script to start the application. It sets up the MCR (MATLAB Compiler Runtime) environment for the current $ARCH and executes the specified command.   * run_magicsquare.sh is the script to start the application. It sets up the MCR (MATLAB Compiler Runtime) environment for the current $ARCH and executes the specified command.
Line 52: Line 50:
  * To run the magicsquare programm we give the shell-script 2 arguments. The first is the path to the Matlab Compiler Runtime. The second is for the programm magicsquare itself. To run the magicsquare programm we give the shell-script 2 arguments. The first is the path to the Matlab Compiler Runtime.

'''Important:'''
The version of the compiler Runtime needs to be same that was used by the compiler mcc.

The second argument in this example
is for the programm magicsquare itself.
Line 55: Line 57:
 ./run_magicsquare.sh /usr/pack/matlab-7.13r2011b-sd 5 > ./run_magicsquare.sh /usr/pack/matlab-8.0r2012b-bs 5
Line 59: Line 61:
LD_LIBRARY_PATH is .:/usr/pack/matlab-7.13r2011b-sd/runtime/glnxa64:/usr/pack/matlab-7.13r2011b-sd/bin/glnxa64:/usr/pack/matlab-7.13r2011b-sd/sys/os/glnxa64:/usr/pack/matlab-7.13r2011b-sd/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/pack/matlab-7.13r2011b-sd/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/pack/matlab-7.13r2011b-sd/sys/java/jre/glnxa64/jre/lib/amd64/client:/usr/pack/matlab-7.13r2011b-sd/sys/java/jre/glnxa64/jre/lib/amd64 LD_LIBRARY_PATH is .:/usr/pack/matlab-8.0r2012b-bs/runtime/glnxa64:/usr/pack/matlab-8.0r2012b-bs/bin/glnxa64:/usr/pack/matlab-8.0r2012b-bs/sys/os/glnxa64:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64/client:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64
Line 69: Line 71:
Line 71: Line 74:
 * More help on mcc: Enter on commandline: mcc -help
 * Or see the Matlab-Documentation in Matlab: Help - Product Help - Matlab Compiler
More help on mcc: Enter on commandline: mcc -help

Or see the Matlab-Documentation in Matlab: Help - Product Help - Matlab Compiler
Line 78: Line 82:
 export MCR_CACHE_ROOT=/tmp  mkdir -p /tmp/$USER
export MCR_CACHE_ROOT=/tmp/$USER
Line 80: Line 85:
If you get the error message: "Could not access MCRcomponent cache", you have to make it unique (make shure no other user is using the same path) and check the accessibility of this path.
Line 87: Line 94:
 * -R nojvm: Start MATLAB without the JVM software. Use the current window to enter commands. The MATLAB desktop does not open. Any tools that require Java software, such as the desktop tools, cannot be used. Handle Graphics and related functionality are not supported; MATLAB produces a warning when you use them.  * -R nojvm: Start MATLAB without the JVM software. Any tools that require Java software, such as the desktop 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.
Line 97: Line 104:
 1. Register the need for many MATLAB licences due to a MATLAB course By registering your need in advance, we can take countermeasures and ensure that these licences are available.  1. Register the need for many MATLAB licences due to a MATLAB course by registering your need in advance, there can be taken countermeasures and ensure that these licences are available. Use the ides contact forumular therefore: https://idts.ethz.ch/hdweb/ (Nethz-login required)
Line 104: Line 111:
 * You can list all checked-out MATLAB licences with the following command.
* Linux: lmutil lmstat -c 1965@lic-matlab.ethz.ch -a | less
 * You can list all checked-out MATLAB licences with the following command on Linux:   {{{
lmutil lmstat -c 1965@lic-matlab.ethz.ch -a | less
 }}}

Matlab

Matlab is a high-level language and interactive environment for numerical computation, visualization, and programming.

Start Matlab

  • Start it on Linux: Applications - Accessories - Terminal. Then type: matlab (Enter)
  • Start it on Windows: Start - Matlab - Matlab

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) is the MATLAB Compiler. You can use the mcc command either from the MATLAB command prompt or the command-line
  • The advantage of a compiled matlab program is, that no matlab license is taken from the ETH-licenses.

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 text-file 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 2003-2011 The MathWorks, Inc.
    
    if ischar(n)
        n=str2num(n);
    end
    m = magic(n);
    m

Important: When this programm is runned in a Linux-Terminal, we have to use the function str2num (string to number). Arguments are used as strings, thats why they have to be converted in a number in Matlab.

Compile the magicsqure function (with the command: mcc) in a Linux-Terminal

  • Start a Terminal (Applications - Accessoires - Terminal) and change to the directory where you stored magicsquare.m
    mcc -mv magicsquare.m
  • This generates you 2 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 $ARCH and executes the specified command.

To run the magicsquare programm we give the shell-script 2 arguments. The first is the path to the Matlab Compiler Runtime.

Important: The version of the compiler Runtime needs to be same that was used by the compiler mcc.

The second argument in this example is for the programm magicsquare itself.

  • > ./run_magicsquare.sh /usr/pack/matlab-8.0r2012b-bs 5
    ------------------------------------------
    Setting up environment variables
    ---
    LD_LIBRARY_PATH is .:/usr/pack/matlab-8.0r2012b-bs/runtime/glnxa64:/usr/pack/matlab-8.0r2012b-bs/bin/glnxa64:/usr/pack/matlab-8.0r2012b-bs/sys/os/glnxa64:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64/client:/usr/pack/matlab-8.0r2012b-bs/sys/java/jre/glnxa64/jre/lib/amd64
    
    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 Matlab-Documentation in Matlab: Help - Product Help - Matlab Compiler

Matlab on the cluster

  • Every Matlab-Job on the Cluster uses one license. Therefore its very important, to run only compiled Matlab-Applications on the cluster.
  • Set the variable MCR_CACHE_ROOT to a directory on your local computer. The NFS-Load on the Homeservers gets too big for the homedirectory.
     mkdir -p /tmp/$USER
     export MCR_CACHE_ROOT=/tmp/$USER

If you get the error message: "Could not access MCRcomponent cache", you have to make it unique (make shure no other user is using the same path) and check the accessibility of this path.

  • Use the following Options of 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 is running.
  • -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 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 licenses

The number of MATLAB licences is limited. To ensure a fair and efficient usage of the licences throughout the ETH the following measures have been put in place:

  • licences will be returned if not used for 4 hours
  • excessive usage of licences will be monitored and users will be asked to return licences if needed

What can you do?

  1. Compile your MATLAB program. The best approach to avoid excessive usage of MATLAB licences is to compile your MATLAB program. The resulting executable does not need ANY MATLAB licence! This frees you from all MATLAB licence restrictions and also allows you to provide your executable to users without a MATLAB installation.
  2. Exit MATLAB when finished. Only then will all used licences be given back.
  3. Register the need for many MATLAB licences due to a MATLAB course by registering your need in advance, there can be taken countermeasures and ensure that these licences are available. Use the ides contact forumular therefore: https://idts.ethz.ch/hdweb/ (Nethz-login required)

  4. Buy your own MATLAB licences if you must have a guaranteed 24/7 service or if you need to use an excessive amount of licences.

How do I know which MATLAB licences I use?

  • The MATLAB command "license('inuse')" lists the licences checked out for the current MATLAB session.

How do I know how many MATLAB licences are used by whom?

  • You can list all checked-out MATLAB licences with the following command on Linux:
     lmutil lmstat -c 1965@lic-matlab.ethz.ch -a | less

Programming/Matlab (last edited 2023-12-18 07:51:43 by stroth)