Reputation: 2915
I met a problem when I run my code, every time I run a relatively larger instance, then the program got stuck and matlab then is not responding, I need to restart the computer, basically I will need to use cplexqcp function to solve SOCP in ILOG CPLEX. I debug the code and following is where the program got stuck
for i=1:prog.Sddcount
if prog.Sdd(i).totalSddVars~=0
for j=1:prog.Sdd(i).totalSdd
diagvec = sparse([varSum+prog.Sdd(i).numAlpha+(j-1)*5+4:varSum+prog.Sdd(i).numAlpha+(j-1)*5+6],[1 1 1],[1 -1 1],prog.Socp.numVars+1,1);
prog.Socp.qc(alphaSum+j).a=sparse([],[],[],prog.Socp.numVars+1,1);
prog.Socp.qc(alphaSum+j).rhs=0;
prog.Socp.qc(alphaSum+j).Q = spdiags(diagvec(:),0,prog.Socp.numVars+1,prog.Socp.numVars+1);
end
alphaSum = alphaSum + prog.Sdd(i).totalSdd;
end
varSum = varSum + prog.Sdd(i).totalVars;
end
And the parameter of one instance that kills the program is
prog.Sddcount=11;
[prog.Sdd.totalSdd]=[1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 7875]
prog.Socp.numVars=117061;
I guess it might be the huge size (117061 by 117061) and large number(sum([prog.Sdd.totalSdd])) of matrix Q , but it is highly sparse and only three entries is nonzero, so I think it would be OK...but every time I run an instance of similar size, it crashes. From the information above, can anyone tell where the problem is? Is it out of memory or I need to allocate enough memory in advance for
prog.Socp.qc.Q
And how can I modify the code? Thanks very much.
Upvotes: 0
Views: 125
Reputation: 1346
Others have already helped OP find that his program was using all the computers physical memory and essentially freezing the computer. One way to check for this would be to include the following code;
max_memory_bytes = 2^32; %limit my script to 4Gb
for i = doing stuff
stuff stuff stuff
mem = memory;
if mem.MemUsedMATLAB > max_memory_bytes
error('Matlab exceeded memory limit of %d Bytes',max_memory_bytes);
end
Memory is a builtin function that provides some useful information. By calling it periodically, one can automatically monitor memory usage and error out before your computer freezes. Of course, if inside the loop you call something like ones(1e4)
that uses a ton of memory, this addition won't help you very much.
Upvotes: 2