Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Using single thread

    Posted Tue April 17, 2018 10:34 PM

    Originally posted by: oarslan


    Hi!

    When solving a model (call it cplex1 object) using callbacks by a branch and cut algorithm, I solve another cplex object (say cplex2) in the callback to generate cuts. cplex2 is solved in a loop for several times at each call to the callback.

    My question is how to limit all processes in a single thread. In Java, I set IloCplex.Param.Threads equal to 1 for both cplex objects. But each time I start running the model (cplex1), the memory shows more than 100% (reaching up to 400%). This is related to the cplex2 object, because when I don't run it, the CPU never exceeds 100% (In such a case, I generate cuts by a heuristic, however I need exact separation by cplex2).

    I am assuming that each time a cplex object is solved, a thread is reserved. However in my application, the two objects should not be running concurrently, because when generating the cuts, I think the cplex1 object simply 'pauses'.

    I am trying to limit everything to a single thread because it is the policy of the university. They only allow a model to run in a cluster of computers if it uses only single thread.

    Thank you!

    Okan.


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Using single thread

    Posted Wed April 18, 2018 05:19 AM

    Setting the Threads parameter to 1 should definitely be enough. Can you call IloCplex.writeParam() before calling solve(), then check the generated files and make sure that the Threads parameter is set to 1 in all of them?

    Also, when you say that the memory reaches 400%, do you really mean memory or do you mean CPU load? How do you measure this?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Using single thread

    Posted Wed April 18, 2018 12:19 PM

    Originally posted by: oarslan


    I checked with writeparam if threads = 1, and they all do. 

    When checking the CPU load, I use 'Activity Monitor' in macOS (%CPU column) and look for the percentage in 'java' row. I also observe the same with top command in terminal.

    I am using a HashMap to keep all cplex objects and call them one by one in a loop and solve them. After solving, I only query some variables and that is it. I have no command to 'stop' or 'end' a cplex object.

    Thanks!

    Okan.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Using single thread

    Posted Thu April 19, 2018 08:49 AM

    Are you sure that all the threads consuming the 400% CPU are performing solves in CPLEX? Note that the java virtual machine usually creates additional threads (for garbage collection, finalization, ...) and these may show up there.

    CPLEX should not cause any CPU load unless you call IloCplex.solve() or similar. CPLEX should not use more than 1 thread if you set the Threads parameter to 1. The first property is by code design and the second property has been tested over and over again and so far we never heard of CPLEX using more threads than allowed.

    It might be a good idea to run your program through a debugger (for example jdb) and stop it when the load gets higher than expected. Then examine in the debugger which threads are up and what they are doing.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Using single thread

    Posted Thu April 19, 2018 11:07 AM

    Originally posted by: oarslan


    I also limit java for garbage collection by calling the file as "java  -XX:ParallelGCThreads=1 ...". So the problem should not be it.

    I actually call .solve() for several times. I attached a txt file with an outline of the code, to make sure we are on the same page. So, even if I call .solve() for several times as seen in outline code, I believe it should still be running on single thread, or not?

    I will investigate the problem more (using jdb or similar) to see if the problem lies in some other parts of the code.

    Thank you for your help!

    Okan.

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Using single thread

    Posted Thu April 19, 2018 11:19 AM

    Originally posted by: oarslan


    I attached the code outline now.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Using single thread

    Posted Fri April 20, 2018 03:05 AM

    Your code outline looks good to me. And as far as I can tell from that, CPLEX should never use more than a single thread. In the callback's main() method, the 'cplex.solve()' call should be stopped until the callback function returns. All the 'tempCplex.solve()' occur after each other and within the callback. So at any given time, there should be at most one solve() active and all these solve()s are correctly configured to use only one thread.

    I am not an expert in JVM configuration but you may also need options like '-XX:+UseSerialGC'.


    #CPLEXOptimizers
    #DecisionOptimization