Number of threads used when solving a model within a callback
AnsweredHello,
I am solving a bi-level MIP (both inner and outer problems are an MIP) using Bender's decomposition implemented using lazy constraints (i.e., the Bender's cuts are added using callbacks). Thus, to compute a new cut I need to solve the inner MIP. If I set the Threads parameter for the inner MIP to a number (e.g., 10) will it use 10 threads or will it only use a single thread?
I am unsure because my understanding is that callbacks are always called from thread 0 (https://groups.google.com/g/gurobi/c/YKbG9ybykew). However, when I run my code it says that the inner MIP is solved using 10 threads, i.e., the output is:
Thread count: 10 physical cores, 10 logical processors, using up to 10 threads
Thank you,
Hugh
-
Hi Hugh,
The outer MIP can use 10 threads, and all those threads might find a solution in branch-and-bound that needs to be checked for violation by your callback.
However, since the callback in Gurobi is not threadsafe, it is ensured that your callback is only called sequentially (from thread 0), and during its execution, the solver waits.
Therefore, within your callback, you can run your inner MIP, again spawning 10 new threads, since the outer MIP is currently waiting and nothing else is using the CPU.Best regards,
Mario0
Please sign in to leave a comment.
Comments
1 comment