5 Guidelines

5.1 The MOSEK integration with MATLAB

In this section we provide some details concerning the integration of MOSEK with MATLAB. The information in this section is not strictly necessary for basic use of the MOSEK optimization toolbox for MATLAB.

5.1.1 The mosekopt MEX file

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

5.1.2 Controlling log-output from mosekopt

Solver log-output is controlled using the echo parameter for mosekopt. The output is directed to the MATLAB console window. In newer versions of MATLAB (2015 or newer), the console output is not displayed until after the solver has terminated, which is a nuisance for long-running optimization tasks. As an accomodation, the log output can be copied to a log-file, using the log parameter for mosekopt. This log-file can then be inspected during the optimization task.

5.1.3 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 Section 17.1. 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 conjuctions with the MOSEK implementations of linprog, etc., and similarly optimget should be used in conjunction with the MATLAB implementations.

The corresponding MATLAB file for each function is located in the toolbox/solvers directory of the MOSEK distribution.

5.1.4 MOSEK and 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.

5.2 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.

5.3 The license system

MOSEK is requires a license when used which is implemented as follows

  1. a license token is checked out when any MOSEK function involving optimization, as for instance mosekopt is called the first time and
  2. it is returned when MATLAB is terminated.

Now if the license should be checked in after use and hence be made available for another user then the license caching should be disabled as follows

param.MSK_IPAR_CACHE_LICENSE = 'MSK_OFF'; % set parameter.
[r,res] = mosekopt('minimize',prob,param); % call

Alternatively the command


will free all unused MOSEK licenses.

By default an error will be returned if no license token is available. However, by setting the parameter MSK_IPAR_LICENSE_WAIT MOSEK can be instructed to wait until a license token is available.

param.MSK_IPAR_LICENSE_WAIT = 'MSK_ON'; %set parameter.
[r,res] = mosekopt('minimize',prob,param); %call