首页 > 解决方案 > 大型线性规划的 Mosek 内存问题

问题描述

我使用 MOSEK 在 Matlab 中运行一个非常大的线性规划问题(32768 个未知数和 691621 个约束)。代码在基于 Linux 的集群中提交。在 bash 文件中,我请求以下内存量:

#$ -l h_vmem=20G
#$ -l tmem=20G

但得到Mosek error: MSK_RES_ERR_SPACE (Out of space.)

我可以请求更多内存(但是,还不清楚还有多少?),但这意味着在集群中排队很长时间。

因此,我想知道是否可以尝试以其他方式改善这个问题。

1)引用一些 MOSEK 常见问题解答:

Java, .NET, amd Python applications runs under a virtual machine. MOSEK shares memeory
with the virtual machine. This implies it might be necessary to force the virtual machine to
free unused memory by explicitly calling the garbage collector (for example before optimization
is performed) in order to make sufficient memory available to MOSEK.

这个建议有用吗?调用垃圾收集器是什么意思(即,我应该将哪一行添加到我的 Matlab 代码中?)。

2)https://docs.mosek.com/9.2/pythonapi/guidelines-optimizer.html(即使这是为Python),它建议设置

Task.putmaxnumvar. Estimate for the number of variables.
Task.putmaxnumcon. Estimate for the number of constraints.
Task.putmaxnumcone. Estimate for the number of cones.
Task.putmaxnumbarvar. Estimate for the number of semidefinite matrix variables.
Task.putmaxnumanz. Estimate for the number of non-zeros in A.
Task.putmaxnumqnz. Estimate for the number of non-zeros in the quadratic terms.

我可以在 Matlab 中做到这一点吗?如何?

3)来自http://ask.cvxr.com/t/how-to-deal-with-out-of-space-error-when-using-mosek-to-solve-a-conic-optimization-problem/7510:“如果您在 1 个线程上运行,它将在一定程度上减少内存消耗(在 cvx 求解器选项中将 MSK_IPAR_NUM_THREADS 设置为 1 或将 MSK_IPAR_INTPNT_MULTI_THREAD 设置为 0)”

这也可以在 Matlab 中完成吗?我努力了

param_MOSEK.MSK_IPAR_NUM_THREADS = 1;
param_MOSEK.MSK_IPAR_INTPNT_MULTI_THREAD = 'MSK_OFF';

但它似乎不起作用,因为输出文件仍然给出

Optimizer  - threads                : 16              
Optimizer  - solved problem         : the dual        
...

与以下问题相关的评论:

2020 年 9 月 9 日星期三 08:10:47 BST 任务 ID 为 6

                            < M A T L A B (R) >
                  Copyright 1984-2019 The MathWorks, Inc.
              R2019b Update 3 (9.7.0.1261785) 64-bit (glnxa64)
                             November 27, 2019
 
For online documentation, see https://www.mathworks.com/support
For product information, visit www.mathworks.com.
 

MOSEK Version 9.2.5 (Build date: 2020-4-22 22:56:56)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Linux/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : LO (linear optimization problem)
  Constraints            : 691597          
  Cones                  : 0               
  Scalar variables       : 32768           
  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.33            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 2.99    
GP based matrix reordering started.
GP based matrix reordering terminated.
Optimizer terminated. Time: 20.15   


Interior-point solution summary
  Problem status  : UNKNOWN
  Solution status : UNKNOWN
  Primal.  obj: 0.0000000000e+00    nrm: 1e+00    Viol.  con: 1e+00    var: 0e+00  
  Dual.    obj: 0.0000000000e+00    nrm: 0e+00    Viol.  con: 0e+00    var: 0e+00  
Optimizer summary
  Optimizer                 -                        time: 20.15   
    Interior-point          - iterations : 0         time: 19.95   
      Basis identification  -                        time: 0.00    
        Primal              - iterations : 0         time: 0.00    
        Dual                - iterations : 0         time: 0.00    
        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    

Mosek error: MSK_RES_ERR_SPACE (Out of space.)

标签: matlabmosek

解决方案


  1. 在 Matlab 中无关紧要。

  2. 在 Matlab 中不相关且不可能。MEX 接口一次性将问题输入 Mosek,并自行处理所有分配。

  3. 要尊重 MSK_IPAR_NUM_THREADS,您必须重新启动整个过程,即 Matlab。请参阅https://docs.mosek.com/9.2/faq/faq.html#mosek-is-ignoring-the-limit-on-the-number-of-threads。但是,当您设置 MSK_IPAR_INTPNT_MULTI_THREAD = 'MSK_OFF' 时,Mosek 将使用 1 个线程,而不管所有可用线程的数量,即打印到日志的数量只是一个上限。您应该能够在任务管理器/顶部/任何其他 CPU 负载跟踪器中看到只有 1 个 CPU 正在使用中。

基本问题是:您是否尝试在没有任何内存限制的情况下运行该问题以查看它是否完全有效并估计内存消耗?它可以在其他机器上运行吗?


推荐阅读