Skip to main content

How to use multithreads more efficiently with Gurobi?

Answered

Comments

6 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    If I understand correctly you are using N1=44 cores to run 44 MIPs in parallel and for each of those MIPs you are setting Threads=20. Is this correct?

    0
  • shengzhi lai
    Gurobi-versary
    Curious
    Conversationalist

    Yes, Jaromił. That's correct.

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    In this case it is possible that multiple models will fight over resources. It is best to set Threads to a value which would avoid "overlapping" of processes, i.e., N1 / #MIPs = Threads. In your case this would mean to set Threads=1. It might make sense to do some testing before setting this value. You could test running a set of your MIPs with Threads=1,2,4,8 and see which Threads setting performs best on a representative test set of your MIPs. You can then still use N1 = 44 cores and then run 44/#threads MIPs with setting Threads=#threads. This way, each optimization run would not have to possibly fight for resources. As an example, you could use N1 = 44 cores and run 11 MIPs in parallel with each using Threads=4.

    Best regards, 
    Jaromił

    0
  • shengzhi lai
    Gurobi-versary
    Curious
    Conversationalist

    Thanks for your advice. In my case, each core will have one model running. So, do you mean it is better to set N1*N2 = #total cores (64 here), like N1=32, N2=2,or N1=64, N2=1, so that N1 models will not fight for resources? Moreover, I really care about the running time, so if I set N1=N2=32, each model might not benefit from Gurobi's multithreaded strategy because 32*32 >> 64? 

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    So, do you mean it is better to set N1*N2 = #total cores (64 here), like N1=32, N2=2,or N1=64, N2=1, so that N1 models will not fight for resources?

    Yes, this is what I mean. It might be worth considering to use N1=16, N2=4, or N1=8, N2=8, because usually MIPs benefit from multiple threads. This however has to be tested on your side.

    Moreover, I really care about the running time, so if I set N1=N2=32, each model might not benefit from Gurobi's multithreaded strategy because 32*32 >> 64? 

    Correct, different processes might start fighting over resources, causing a significant slowdown in the end.

    Best regards, 
    Jaromił

    0
  • shengzhi lai
    Gurobi-versary
    Curious
    Conversationalist

    Thanks again! I will try this out.

    0

Please sign in to leave a comment.