将矩阵加载到求解器中时,如何避免同时拥有两个非常大的矩阵实例? [英] How can I avoid having two instances of a very large matrix at the same time when loading it into a solver?
问题描述
我在LP程序中同时使用Cplex和Gurobi,其不等式约束矩阵A可能会变得非常大-大约5到10GB.当我想使用这些求解器之一时,我必须创建一个具有所有问题约束的单独结构.这意味着我的工作区中有矩阵A,而我的求解器结构中同时有矩阵A.即使我尽可能快地在工作空间中清除它,仍然有一段时间两者都存在并且我的RAM超载.
I am using both Cplex and Gurobi for an LP program whose inequality constraint matrix A can become truly large -- around 5 to 10GB. When I want to use one of those solvers, I have to create a separate struct with all the problem constraints. This means that I have the matrix A in my workspace, and the matrix A in my solver struct at the same time. Even if I clear it in my Workspace as fast as possible, there is still a time when both exist and my RAM is overloaded.
我在问是否有一些聪明的方法可以将矩阵A传递到模型中,而不必同时存在两者.我现在唯一能想到的就是一小部分地交付它.
I am asking if there is some clever method to deliver the matrix A into the model without both existing at the same time. The only thing I can think of right now is delivering it in small chunks...
推荐答案
MATLAB使用写时复制或延迟复制.这意味着,只要您不修改其中一个副本,矩阵的所有副本都共享相同的数据:
MATLAB using copy-on-write, or lazy copying. This means that, as long as you don't modify one of the copies, all copies of a matrix share the same data:
A = randn(10000);
B = A; % does not take up extra memory
myfunc(B);
function myfunc(matrix)
C = matrix; % does not take up extra memory.
例如,请参见未记录的Matlab .
这篇关于将矩阵加载到求解器中时,如何避免同时拥有两个非常大的矩阵实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!