Thread-safety of gurobipy
回答済みHi,
according to this article https://support.gurobi.com/hc/en-us/articles/360043111231-How-do-I-use-multiprocessing-in-Python-with-Gurobi- gurobipy is not thread-safe.
However, the reference manual (https://www.gurobi.com/wp-content/plugins/hd_documentations/documentation/9.5/refman.pdf, Section 3.1, p.15) states the following:
"In general, you should aim to create a single Gurobi environment in your program, even if you plan to work with multiple models. Reusing one environment is much more efficient than creating and destroying multiple environments. The one exception is if you are writing a multi-threaded program, since environments are not thread safe. In this case, you will need a separate environment for each of your threads"
So is it ok, to use gurobipy in a multi-threaded program using separate environments per thread or are there any other issues in gurobipy with multiple threads?
Thanks
-
Hi Marcel,
So is it ok, to use gurobipy in a multi-threaded program using separate environments per thread or are there any other issues in gurobipy with multiple threads?
Indeed, this is what you should do. Please make sure that you use the context managers (\(\texttt{with gp.Env(...) as env:}\)) as indicated in the article you linked.
Please note that this still appears in the updated version of the documentation for the Python API: gp.Env and the C API: GRBloadenv.Cheers,
David0
サインインしてコメントを残してください。
コメント
1件のコメント