10 Technical guidelines¶
This section contains some more in-depth technical guidelines for API for MATLAB, not strictly necessary for basic use of MOSEK.
10.1 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.
Constraints can be assigned names when added with mosekmodel.appendcons
, and variable names can be set with mosekmodel.varname
.
10.2 Timing¶
Unless otherwise mentioned all parameters, information items and log output entries in MOSEK which refer to time measurement are expressed in seconds of wall-clock time.
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
mosekmodel.solve
, is called the first time andit 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
"checkinlicense"
command ofmosekenv
.mosekenv("checkinlicense");
The default license path can be changed using the
"licfile"
argument ofmosekmodel.solve
. Note, that although this argument can be used for each solve, the path will in fact be set globally, so the path set at the first optimization will apply to all subsequent ones. To avoid undefined behavior if the MOSEK library is temporarily unloaded, we strongly recommend that if the"licfile"
argument is used at all, then it must be used with exactly the same value for all invocations ofmosekmodel.solve
.
10.5 Deployment¶
When redistributing a Matlab application using the MOSEK API for MATLAB 11.0.0(BETA), the following shared libraries from the MOSEK bin
folder are required:
Linux :
libmosek64
,libtbb
,Windows :
mosek64
,tbb
,svml_dispmd
,OSX :
libmosek64
,libtbb
.
together with all the *.mex*
and *.m
files from the same folder.