Thread safety
Summarizes special considerations about thread safety in parallel applications.
When you use callbacks with the CPLEX parallel optimizers, the nature of the callback can affect the thread safety of the application. You should consider the performance trade-offs that may occur in such a situation. For example, if the application invokes a callback that provides significant performance improvements, but cannot be written in a thread-safe way, you should assess whether running CPLEX in sequential mode in the presence of the callback yields better performance than running CPLEX in parallel mode without the callback.
Also, in order to make sure of thread safety, in certain cases CPLEX restricts the way in which it calls a callback. In particular, when it calls an informational callback in either deterministic or opportunistic mode, CPLEX makes sure of thread safety by calling the callback only from the main thread that contains the relevant global information required by the informational callback.
When CPLEX solves MIPs, each deterministic thread runs independently and solves a separate subtree, so you may see a significant number of nodes processed between calls to the callback.
For this reason, if you need to terminate an optimization running in parallel, you need to assess whether stopping the optimization deterministically or stopping it as quickly as possible is more important.
With respect to a query callback,
the routine CPXsetterminate in the C
API or methods of the class IloCplex::Aborter in
the object-oriented APIs yields the fastest termination but may compromise
determinism due to slight variations in system runtime. In contrast,
aborting the optimization by returning a nonzero status may take longer
since the run continues until the next synchronization point, but
the results will be deterministic.
With an informational callback, the two alternatives for terminating the optimization are both deterministic and do not delay the termination. However, CPLEX calls informational callbacks less frequently than it calls query callbacks.
| Type of callback | Parallel mode: Deterministic |
Parallel mode: Opportunistic |
Additional information |
|---|---|---|---|
| Informational callbacks | thread-safe | thread-safe | |
| Query or diagnostic callbacks | thread-safe, but user must make sure of determinism | thread-safe | Query callbacks and parallel search |
| Control callbacks | thread limit set to 1 (one) by default; otherwise, thread-safe; user must make sure of determinism | thread limit set to 1 (one) by default; otherwise, thread-safe | Thread safety and MIP control callbacks |
| Type of callback | MIP search mode: Dynamic |
MIP search mode: Conventional |
Additional information |
|---|---|---|---|
| Informational callbacks | compatible | compatible | |
| Query or diagnostic callbacks | compatible | compatible | Query callbacks and dynamic search |
| Control callbacks | incompatible | compatible | Control callbacks and dynamic search |