Allocate more RAM to CVX to be faster?

Uncategorized
Jan 30, 2021
P

Hi there,

Firstly, thanks for this useful toolbox.

My problem is:

I am running a CVX code with Mosek as the solver. I need to solve an LP for a high number of constraints let’s say 10^5 to 10^8. When I run the code in MATLAB, and check the activity monitor in my iMac, MATLAB only utilizes 10% of RAM. It works but takes lots of time. Is there a way to use the full capacity of RAM to make CVX faster?
Is there any setting in CVX to make it able to use a higher amount of RAM?

I should add that my code is not parallelizable. Besides, as far as I know, MATLAB uses as much RAM as it needs.

All the best,

M

The general answer is no. You may want to post the Mosek log output to check if that looks reasonable.

P
Replying to #2

Thanks for your answer, where can I find teh Mosek log output?

M

Provided you don’t use the quiet option for CVX, the solver output will appear in your MATLAB console after cvx_end and some CVX pleasantries (such as informing you that it is solving the dual problem).

Bottom line: Copy and paste all the output after cvx_end into a reply.

P

Thanks,

Calling Mosek 9.1.9: 203188 variables, 24 equality constraints
For improved efficiency, Mosek is solving the dual problem.

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:32:15)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86

Problem
Name :
Objective sense : min
Type : LO (linear optimization problem)
Constraints : 24
Cones : 0
Scalar variables : 203188
Matrix variables : 0
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.01
Lin. dep. - number : 0
Presolve terminated. Time: 0.49
Problem
Name :
Objective sense : min
Type : LO (linear optimization problem)
Constraints : 24
Cones : 0
Scalar variables : 203188
Matrix variables : 0
Integer variables : 0

Optimizer - threads : 8
Optimizer - solved problem : the primal
Optimizer - Constraints : 11
Optimizer - Cones : 0
Optimizer - Scalar variables : 103188 conic : 0
Optimizer - Semi-definite variables: 0 scalarized : 0
Factor - setup time : 0.13 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 66 after factor : 66
Factor - dense dim. : 0 flops : 1.12e+07
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 1.8e+05 1.8e+00 6.8e+04 0.00e+00 3.728625730e+04 0.000000000e+00 3.3e+00 0.82
1 4.5e+03 4.5e-02 1.7e+03 3.00e+00 4.708614674e+02 8.027085990e-04 8.2e-02 1.00
2 2.7e+01 2.6e-04 9.9e+00 1.02e+00 2.822202441e+00 8.112731264e-02 4.8e-04 1.04
3 1.5e+01 1.5e-04 5.5e+00 -7.89e-01 3.049452267e+00 4.696687046e-01 2.7e-04 1.09
4 4.7e+00 4.7e-05 1.8e+00 -9.29e-01 4.329623382e+00 2.148224853e+00 8.6e-05 1.14
5 4.7e+00 4.7e-05 1.8e+00 -5.16e-02 4.296255295e+00 2.143244907e+00 8.6e-05 1.17
6 1.9e+00 1.9e-05 7.0e-01 -2.19e-01 4.578020915e+00 3.618383062e+00 3.4e-05 1.22
7 1.9e+00 1.9e-05 7.0e-01 9.03e-01 4.554604478e+00 3.596599581e+00 3.4e-05 1.25
8 1.2e+00 1.2e-05 4.5e-01 8.87e-01 4.147554668e+00 3.535523134e+00 2.2e-05 1.29
9 2.8e-01 2.8e-06 1.1e-01 8.87e-01 3.809590485e+00 3.658737640e+00 5.1e-06 1.33
10 2.8e-01 2.8e-06 1.1e-01 8.05e-01 3.809590485e+00 3.658737640e+00 5.1e-06 1.36
11 2.8e-01 2.8e-06 1.0e-01 8.05e-01 3.782580544e+00 3.636950021e+00 5.1e-06 1.43
12 1.1e-01 1.1e-06 4.0e-02 8.02e-01 3.748380660e+00 3.685552365e+00 1.9e-06 1.50
13 5.7e-02 5.7e-07 2.1e-02 8.68e-01 3.738301060e+00 3.702374141e+00 1.0e-06 1.59
14 2.9e-02 2.9e-07 1.1e-02 5.92e-01 3.743240786e+00 3.720198409e+00 5.3e-07 1.69
15 2.9e-02 2.9e-07 1.1e-02 7.29e-01 3.742472145e+00 3.719859584e+00 5.2e-07 1.78
16 1.9e-02 1.9e-07 7.0e-03 6.71e-01 3.737326030e+00 3.723089594e+00 3.4e-07 1.89
17 1.3e-02 1.3e-07 4.7e-03 9.26e-01 3.735246584e+00 3.725426349e+00 2.3e-07 1.98
18 1.2e-03 1.2e-08 4.4e-04 9.57e-01 3.730618015e+00 3.729679758e+00 2.1e-08 2.08
19 1.6e-06 1.6e-11 6.1e-07 9.97e-01 3.729775464e+00 3.729774163e+00 2.9e-11 2.17
20 1.6e-10 1.5e-13 6.1e-11 1.00e+00 3.729774273e+00 3.729774273e+00 2.9e-15 2.23
21 1.9e-14 1.7e-13 5.3e-15 1.00e+00 3.729774273e+00 3.729774273e+00 2.9e-19 2.28
Basis identification started.
Primal basis identification phase started.
Primal basis identification phase terminated. Time: 0.00
Dual basis identification phase started.
Dual basis identification phase terminated. Time: 0.01
Basis identification terminated. Time: 0.08
Optimizer terminated. Time: 2.63

Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 3.7297742729e+00 nrm: 4e+00 Viol. con: 1e-11 var: 0e+00
Dual. obj: 3.7297742729e+00 nrm: 1e+01 Viol. con: 0e+00 var: 3e-13

Basic solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 3.7297742729e+00 nrm: 4e+00 Viol. con: 3e-13 var: 0e+00
Dual. obj: 3.7297742729e+00 nrm: 1e+01 Viol. con: 0e+00 var: 3e-13
Optimizer summary
Optimizer - time: 2.63
Interior-point - iterations : 21 time: 2.49
Basis identification - time: 0.08
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.01
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00


Status: Solved
Optimal value (cvx_optval): -3.72977

E
Replying to #5

MOSEK solves your problem in 21 iteration spending 2.63 seconds. That seems quite decent given the size of the problem and perhaps a bit slow PC.

Maybe CVX is spending a lot of time building your model. If that is the case then could try calling Mosek directly if you want to stick with Matlab.

P

Thanks for the answer!
Yes, you are right! I have not paid attention to this point. Most of time is used for constructing the model by MATLAB. Actually, I am generating N samples randomly using rand(1) in MATLAB and construct 3 different matrices based on some if conditions. Then, I feed these matrices to CVX.

min cost
s.t:
A1.x<=B1
A2.x<=B2
A3.x<=B3

Maybe I have to a way to construct the matrices faster! I also would welcome if you have a suggestion.
And how can I call Mosek directly in MATLAB? (As you suggested in your reply)

Best