メインコンテンツへスキップ

Multiprocessing with gurobi

回答済み

コメント

1件のコメント

  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Hi Keyu,

    Thanks for posting here! In your example, all copies of the model live in the same (default) Gurobi environment, which is not thread-safe. Each model should live in its own, dedicated Gurobi environment. That can be done by constructing a new environment in your solve_model function and passing that as an argument to model.copy()

    However, my other concern is whether the approach with making the model a global variable works as expected. When using multiprocessing, Python already has to make its own copy of the model variable for each child process and I doubt if that copy operation is going to work on a Gurobi model.

    If the changes to the various copies of the model are minimal, you might consider using the "Multiple scenario" feature of Gurobi instead. Also, if constructing the model takes a significant amount of time, we could look into making that faster which might remove the need to work on model copies?

    Kind regards,
    Ronald

    0

サインインしてコメントを残してください。