Showing posts with label performance. Show all posts
Showing posts with label performance. Show all posts

Wednesday, June 22, 2022

On the performance improvement of the semi-definite optimizer when switching from version 9 to 10

The most reason Mosek version 10.0.16(beta) includes a very significant improvement of the optimizer for semi-definite problems. The improvement is most notable for problems having many matrix variables. In order to illustrate the potential performance gain we use a problem supplied by Mosek user. Some statistics about the problem can be seen in the Mosek log output:


Optimizer  - solved problem         : the primal
Optimizer  - Constraints            : 8808
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 0                 conic                  : 0
Optimizer  - Semi-definite variables: 49                scalarized             : 76493
Factor     - setup time             : 8.26              dense det. time        : 0.00
Factor     - ML order time          : 0.50              GP order time          : 0.06
Factor     - nonzeros before factor : 3.38e+07          after factor           : 3.38e+07
Factor     - dense dim.             : 0                 flops                  : 2.45e+11
Factor     - GP saved nzs           : 4.97e+06          GP saved flops         : 4.60e+10
Hence, the problem has 8808 constraints and 49 matrix variables. In addition it should be mentioned that the contraint matrix is not that sparse.

Below the computational results is shown.

CPU 9.3.20 9.3.20 (MT) 10.0.16 10.0.16 (MT)
Intel Xeon Gold 6126 (12 core) 1165 1171 833 207
AMD EPYC 7402P (24 core) 1189 1049 777 108
The table shows the computational time in wall clock seconds for running version 9.3.20 and 10.0.16 single and multi-threaded respectively. Moreover, the timing result is shown for an Intel and an AMD CPU.

The main conclusions from the table are

  • version 10 is much faster than version 9 and the difference is more notable on the AMD CPU.
  • version 10 offers much better speed-up when using multiple threads. In fact there are virtually no speed-up when using multiple threads in version 9.
It should emphasized that the performance improvement for solving semi-definite problems when switching from version 9 to version 10 is dependent on the structure of the problem. However, as illustrated above a big performance boost can be realized for some problems.

PS. Despite the AMD CPU being the fastest in the table above then this post do not claim AMD CPUs are better than Intel CPUs or the other way around.

Monday, June 6, 2016

Improving Python API performance

Recently a MOSEK user pointed out out that sometimes the MOSEK Python API can be quite slow when it comes to input large amount of data. In particular the problem is related to the way MOSEK handles 32 and 64 bit integers.


If you use Numpy with a 64-bit Python, integer arrays will usually end up being arrays of numpy.int64 since the native Python integer is an int64.


Most MOSEK functions require arrays of numpy.int32, e.g. for variable or constraint indexing. In this case it can often significantly speed up the function call to explicitly convert the types.

To this extent is worth using numpy.array class to convert arrays of indexes to the right size: the numpy implementation is highly efficient and saves a lot of time!

Tests

To show the performance gain in Python 2.7 we implement a simple tests involving
  • n=1000000 variables,
  • linear objective function terms and
  • quadratic objective function terms.
using Python timeit module. Each tests is repeated num=100 times and we removed from the timing unecessart contributions such as module import and task/environment declaration.

Note we show source code without timeit instrumentation to keep it simple. 

The complete testing code is available at the end of the post.

Objective function linear coefficents.

Say we want to input the coefficients for n variables in the objective function. We can do it using Python arrays or  numpy arrays instead. The code to time the running time is


We obtain the following results


  • direct input: 1.113329s
  • using numpy : 0.017299s


Objective function quadratic coefficients.

Say we want to input the coefficients of the linear part of the objective function. The benchmark code is



It provides the following results


  • direct input: 2.239344s
  • using numpy : 0.028208s


Conclusion

The MOSEK Python API converts by default 64bit integers to 32 bit ones, and this operation could introduce significant overhead. Using numpy array to convert integer arrays to 32 bit is a simple simple workaround that allows to speed up the input process significantly. 

The improvement is quite remarkable. However, it must be noticed that not all users will experience such an improvement. Nevertheless it is a good idea to check your code and see whether you can gain some performance.

Remember that this issue is solved in the new MOSEK 8 release.


Complete code