【问题标题】:Mosek memory issue for large linear programming大型线性规划的 Mosek 内存问题
【发布时间】:2020-09-09 10:42:19
【问题描述】:

我使用 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),它将在一定程度上减少内存消耗” p>

这也可以在 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        
...

与以下问题相关的评论:

  • 代码在我的 MacOS 64 位中使用 16 个线程在 180 秒内运行。这 计算机内存为 32 GB 2667 MHz DDR4。它使用的内存远少于 20G(大约 9G)。

  • 在请求 20G 的 vmem 和 tmem 后,代码在我的 univ(基于 Linux)的集群上运行时失败。在集群中,MOSEK 执行预求解、基于 GP 的矩阵重新排序,然后失败。这是一个典型的日志文件

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

【问题讨论】:

    标签: matlab mosek


    【解决方案1】:
    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 正在使用。

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

    【讨论】:

    • 在集群上,当你以完整的日志输出运行时,它会说什么?错误是立即发生,还是您在日志中得到一些求解器输出,然后它在中间某处终止?如果是这样,那么它会走多远?没有这些信息,就很难调试任何东西。
    • 谢谢。我在问题的末尾添加了一些与您的问题相关的 cmets。我想知道问题是否可能是我被分配到一台具有许多内核的机器上,MOSEK 试图使用所有内核,这需要大量内存?
    • @user3285148 我将通过将线程数固定为 1 来开始试验,看看它是如何从那里开始的。
    • @user3285148 直接关掉,请问集群机有多少核?我认为减少线程数有助于解决这个问题?
    • 是的,4核和10G内存似乎可以工作。
    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 2013-11-27
    相关资源
    最近更新 更多