Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

Possible memory leak when invoking CPLEX from MATLAB

  • 1.  Possible memory leak when invoking CPLEX from MATLAB

    Posted Mon November 01, 2010 03:27 PM

    Originally posted by: PaulBerglund


    I am calling CPLEX from MATLAB. I do a large number
    of calls to CPLEX and over time my memory usage goes up
    and up. It seems like there might be a memory leak,
    whether in MATLAB, in CPLEX or in the interface between
    the two I can't say.

    Any ideas/suggestions?

    I am using IBM ILOG CPLEX Optimization Studio V12.2
    and MATLAB version 2009b, on Windows XP.

    Paul Berglund
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Fri November 12, 2010 01:42 PM

    Originally posted by: belenmartin


    Hi Paul,
    I am having the same problem.

    I am using the same IBM ILOG CPLEX optimization Studio V12.2
    and Matlab 2007b on windows 7.

    I have tried to save my data on disk, clear all and load them again, and it didn't solve the problem.
    Belén.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Sat November 13, 2010 07:05 PM

    Originally posted by: John Cui


    So, how do you call CPLEX in matlab? By toolbox or Cplex class?
    I recommend below code to reduce memory usage in matlab:

    for i=1:10
       cplex=Cplex();
       cplex.Model.A = your_A;
       cplex.Model.lb = your_lb;
       {...build your model...}
     
       cplex.solve();
       sol = cplex.Solution;
       clear cplex;
    end
    


    Is it helpful?

    John Cui
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Tue November 16, 2010 09:34 AM

    Originally posted by: belenmartin


    I am currently using the toolbox, but i'll try your suggestion.
    Thanks a lot,
    Belén
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Tue November 16, 2010 10:36 AM

    Originally posted by: belenmartin


    Hi,
    I've tried it but it didn't work.

    I've done a small test problem, you can see how memory is rising up and up, no matter I'm clearing the objects.
    load('prueba')
    whos
    for i=1:10
    cplex=Cplex('name');
    cplex.Model.name='name';
    cplex.Model.sense='minimize';
    cplex.Model.ub=inf*ones(size(L));
    cplex.Model.lhs=-inf*ones(size(beq));
    cplex.Model.Q = Qcost;
    cplex.Model.obj = cost;
    cplex.Model.lb = L;
    cplex.Model.A = Aeq;
    cplex.Model.rhs = beq;
    cplex.solve();
    sol = cplex.Solution;
    clear sol
    clear cplex.Model;
    clear cplex
    clear ans
    memory
    end

    Thanks for your suggestions, anyway.
    Belén
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Wed November 17, 2010 12:43 AM

    Originally posted by: John Cui


    Can you upload prueba file to here? Which I need to reproduce.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Wed November 17, 2010 04:21 AM

    Originally posted by: belenmartin


    I thought I had done it.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Wed November 17, 2010 04:26 AM

    Originally posted by: belenmartin


    You can find prueba.mat attatched to this post.
    Thanks a lot,
    Belén
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Thu November 18, 2010 12:43 PM

    Originally posted by: PaulBerglund


    For what it's worth I too am still having the
    problem. I switched from using the toolbox
    function to using the cplex class, but I am
    still seeing gradually increasing memory use
    for MATLAB. It is increasing fairly slowly;
    by about 5MB for each invocation of a function
    that makes on the order of 1000 calls to cplex
    every time it is invoked.

    The code I am using to call cplex is as follows:

    cplex = Cplex('projection');
    cplex.Model.sense = 'minimize';
    cplex.Model.Q = F;
    cplex.Model.obj = c;
    cplex.Model.lb = lb;
    cplex.Model.ub = ub;
    cplex.Model.A = A;
    cplex.Model.lhs=-inf*ones(size(b,1));
    cplex.Model.rhs = b;
    cplex.DisplayFunc = [];

    cplex.solve();
    x = cplex.Solution.x;
    clear cplex;
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Fri November 19, 2010 02:07 AM

    Originally posted by: SystemAdmin


    Are you using the academic version of CPLEX 12.2? Is so then you are probably suffering from a known memory leak in the license handler.
    The current recommended workaround is to reuse the CPLEX object as much as possible.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Possible memory leak when invoking CPLEX from MATLAB

    Posted Mon November 22, 2010 03:02 PM

    Originally posted by: PaulBerglund


    I changed to re-using the cplex object (I had been throwing
    it away every time I used it) and now memory use grows a lot
    more slowly. It still grows, though possibly not any faster
    than it actually needs to do.

    Thank you for the suggestion.

    Paul Berglund
    #CPLEXOptimizers
    #DecisionOptimization