10 Technical guidelines

This section contains some more in-depth technical guidelines for Optimization Toolbox for MATLAB, not strictly necessary for basic use of MOSEK.

10.1 Integration with MATLAB

The mosekopt MEX file

The central part of Optimization Toolbox for MATLAB is the mosekopt MEX file. It provides an interface to MOSEK that is employed by all the other functions provided in the toolbox. Therefore, we recommend to mosekopt function if possible because that give rise to the least overhead and provides the maximum of features.

Compatibility with the MATLAB Optimization Toolbox

For compatibility with the MATLAB Optimization Toolbox, MOSEK provides the following functions:

  • linprog: Solves linear optimization problems.

  • intlinprog: Solves a linear optimization problem with integer constrained variables.

  • quadprog: Solves quadratic optimization problems.

  • lsqlin: Minimizes a least-squares objective with linear constraints.

  • lsqnonneg: Minimizes a least-squares objective with nonnegativity constraints.

  • mskoptimget: Getting an options structure for MATLAB compatible functions.

  • mskoptimset: Setting up an options structure for MATLAB compatible functions.

These functions are described in detail in Sec. 15.2 (Command Reference). The functions mskoptimget and mskoptimset are not fully compatible with the MATLAB counterparts, optimget and optimset, so the MOSEK versions should only be used in conjunction with the MOSEK implementations of linprog, etc., and similarly optimget should be used in conjunction with the MATLAB implementations.

Caveats using the MATLAB compiler

When using MOSEK with the MATLAB compiler it is necessary manually:

  • to remove mosekopt.m before compilation,

  • copy the MEX file to the directory with MATLAB binary files and

  • copy the mosekopt.m file back after compilation.

10.2 Names

All elements of an optimization problem in MOSEK (objective, constraints, variables, etc.) can be given names. Assigning meaningful names to variables and constraints makes it much easier to understand and debug optimization problems dumped to a file. On the other hand, note that assigning names can substantially increase setup time, so it should be avoided in time-critical applications.

Names of various elements of the problem are assigned using the names structure within an optimization problem specification prob.

Note that file formats impose various restrictions on names, so not all names can be written verbatim to each type of file. If at least one name cannot be written to a given format then generic names and substitutions of offending characters will be used when saving to a file, resulting in a transformation of all names in the problem. See Sec. 16 (Supported File Formats).

10.3 Multithreading

Parallelization

The interior-point and mixed-integer optimizers in MOSEK are parallelized. By default MOSEK will automatically select the number of threads. However, the maximum number of threads allowed can be changed by setting the parameter MSK_IPAR_NUM_THREADS and related parameters. This should never exceed the number of cores.

The speed-up obtained when using multiple threads is highly problem and hardware dependent. We recommend experimenting with various thread numbers to determine the optimal settings. For small problems using multiple threads may be counter-productive because of the associated overhead. Note also that not all parts of the algorithm can be parallelized, so there are times when CPU utilization is only 1 even if more cores are available.

Determinism

By default the optimizer is run-to-run deterministic, which means that it will return the same answer each time it is run on the same machine with the same input, the same parameter settings (including number of threads) and no time limits.

Setting the number of threads

The number of threads the optimizer uses can be changed with the parameter MSK_IPAR_NUM_THREADS.

The MATLAB Parallel Computing Toolbox

Running MOSEK with the MATLAB Parallel Computing Toolbox requires multiple MOSEK licenses, since each thread runs a separate instance of the MOSEK optimizer. Each thread thus requires a MOSEK license.

10.4 The license system

MOSEK is a commercial product that always needs a valid license to work. MOSEK uses a third party license manager to implement license checking. The number of license tokens provided determines the number of optimizations that can be run simultaneously.

By default a license token remains checked out from the first optimization until the end of the MOSEK session, i.e.

  • a license token is checked out when any MOSEK function involving optimization, as for instance mosekopt, is called the first time and

  • it is returned when MATLAB is terminated.

Starting the optimization when no license tokens are available will result in an error.

Default behaviour of the license system can be changed in several ways:

  • Setting the parameter MSK_IPAR_CACHE_LICENSE to "MSK_OFF" will force MOSEK to return the license token immediately after the optimization completed.

  • Setting the parameter MSK_IPAR_LICENSE_WAIT will force MOSEK to wait until a license token becomes available instead of returning with an error.

  • All licenses currently checked out and not in use can be released on demand using the nokeepenv command of mosekopt.

    mosekopt('nokeepenv');