Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 03/24/17 12:57 PM

    Originally posted by: davidsf


    Dear IBM,

    I am a PhD student in Pisa and my tutors own the Academic licence under the IBM academic initiative.

    I am facing with a big problem using parallel computing in matlab. This problem appears on the computer of the lab whose characteristics follows below:

    Hardware:
    -Motherboard: intel s5520hc
    -Processors: 2 x intel Xeon X5650 (2 phisical processors)
    -RAM: 16 Gb (2x8Gb)

    Software:
    -Windows 10 Enterprise
    -Matlab 2016a
    -Cplex 12.7

    I run a code summarized below and evaluated the time required to be computed.

    parfor i=1:NP

        for i=1:NI
            ->initialization the matrix A, b, Aeq, beq, f_obj, ctype, and x0(x0 = [])

            [x,fobiettivo,exitflag,output]=cplexmilp(f_obj, A, b, Aeq, beq,[],[],[], [], [], ctype, x0);

         end
    end

    Unexpectly, I observed that simulations with 2 threads in parallel (NP = 2) requires a lot of time more to be executed (745.78 sec.), while running it using a normal for instead of the parfor require just 11.75 sec.
    Using the parfor the processor goes at the 100% while with a normal for it stays down less than 50%, and the computing time is around 70 time lower.

    Sometimes the combination of MATLAB 2016a + CPLEX 12.7 crashed, too, but it happens usually when I use the class Cplex instead of the cplexmilp function. Currently, I need just the cplexmilp, so I am not so interested in the class function. I built the model also with the class in order to try if it could be better.
    The problem is that with the cplexmilp, the computational burden increases instead of reducing
    Unfortunately, I don't think I can give you the code up to now because it is a research for a paper. Maybe, when the paper is published I could give you the code by private to developers, but I have to ask to the professors.

    None of this problems happens using my computer Windows 7 with MATLAB 2016a + CPLEX 12.6.1 and the parallel computing works fine.

    In addition, I was wondering if in the meantime I could try to install also into the lab computer the previoud version 12.6.1, but I would need the installer back. I would really appreciate if you could provide me the link.

    Thanks in advace,

    Davide


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 03/24/17 03:24 PM

    If you run cplexmilp() with just default settings, then CPLEX will create as many threads as your machine has CPUs. If you now do this in parallel then you will end up with (a lot) more threads than there are CPUs. So CPUs will be oversubscribed and threads will have to compete for CPUs. This is usually not a good idea for CPLEX. I suggest to adjust the 'threads' parameter for the calls to cplexmilp() so that the total number of threads created by CPLEX does not exceed the number of CPUs on your computer. I am not sure why you did not face these problems with 12.6.1 but at first glance they don't seem related to the CPLEX version.

    When you use the class API, do you have a separate CPLEX instance for each thread? I.e., do you instantiate CPLEX in the innermost loop? Instances of the Cplex class are not designed to be used from different threads simultaneously and doing so will certainly cause trouble.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 03/25/17 10:47 PM

    Originally posted by: davidsf


    Thank you very much for your help, I used the options parameter of cplexmilp and now it works fine. I adjusted the matlab threads and cplex threads with some oversubscription to be close to the 100% of CPU use. My code includes also tasks less time consuming that doesn't involve cplex, thus to be close to the 90-100% of CPU usage, I used 5 matlab threads and 8 cplex threads.

    I observed that sometimes with higher level of those levels, MATLAB crashes by an internal error.

    Each optimization run using cplex APIs is called and instantiated in the inner loop, inside a function. Thus, the cplex class would be automatically deallocated by matlab at the end when the function completes. So, each thread has only one cplex class running simultaneusly. Is it compatible with cplex class?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 03/26/17 02:21 AM

    Yes, that use of the CPLEX class is fine.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 03/29/17 01:26 PM

    Originally posted by: davidsf


    Thank you very much for your help.

    Reducing the number of threads Matlab complete the simulations. I observed that usually if I interupt the computing (by pressing ctrl+c) and I restart the computation when the workers have stopped the previous operations, Matlab crash. By rebooting matlab few times the problem disappear.

    I am a bit afraid of using the number of total threads (matlab workers times cplex threads) only up to the available cores, because in the simulation I don't require cplex to be run 100%, thus I would loose a lot of CPU runs. In additions the average computing time of each CPLEX call is lower than 1 s (except for some times where a high number of cplex threads help). 

    Currently I am using 6 matlab workers each with 12 cplex threads. I will try different configurations in order to check which one is better for my problem. What do you think?

    Anyway, with the first question you solved my big issues, so I accepted the answer.

    Thank you very much.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 04/25/17 04:33 AM

    Honestly, I have no idea what is the best setting for matlab workers and cplex threads. That heavily depends on the models you solve. How well CPLEX parallelizes on them, how long each individual solve takes etc. So I guess the best you can do is run some experiments to figure out the best setting.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Problem with MATLAB parallel computing and CPLEX: 70 times slower

    Posted 04/27/17 05:08 PM

    Originally posted by: davidsf


    Thank you very much. I will try.

    Regards,

    Davide Fioriti


    #CPLEXOptimizers
    #DecisionOptimization