Skip to content

Commit d56fd84

Browse files
authored
Clarify that Gurobi.Env are not thread safe
1 parent 18666a0 commit d56fd84

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ optimize!(model)
271271

272272
## Reusing the same Gurobi environment for multiple solves
273273

274-
When using this package via other packages such as [JuMP.jl](https://github.com/jump-dev/JuMP.jl),
275-
the default behavior is to obtain a new Gurobi license token every time a model
276-
is created. If you are using Gurobi in a setting where the number of concurrent
274+
The default behavior of `Gurobi.Optimizer()` is to create a new Gurobi
275+
environment (and license token) for each model.
276+
277+
If you are using Gurobi in a setting where the number of concurrent
277278
Gurobi uses is limited (for example, ["Single-Use" or "Floating-Use" licenses](http://www.gurobi.com/products/licensing-pricing/licensing-overview)),
278279
you might instead prefer to obtain a single license token that is shared by all
279280
models that your program solves.
@@ -292,6 +293,13 @@ model_2 = direct_model(Gurobi.Optimizer(GRB_ENV))
292293
set_attribute(model_2, "OutputFlag", 0)
293294
```
294295

296+
### Environments are not thread-safe
297+
298+
`Gurobi.Env` are NOT thread-safe. If two models both use the same environment
299+
you must not solve them simultaneously on different threads.
300+
301+
### Environments inside a module
302+
295303
If you create a module with a `Gurobi.Env` as a module-level constant, use an
296304
`__init__` function to ensure that a new environment is created each time the
297305
module is loaded:
@@ -315,7 +323,7 @@ create_optimizer() = Gurobi.Optimizer(GRB_ENV_REF[])
315323
end # MyModule
316324
```
317325

318-
## Pass parameters to an Environment
326+
### Pass parameters to an Environment
319327

320328
To set parameters in an environment before the environment is started, pass a
321329
`Dict{String,Any}` that maps parameter names to values:

0 commit comments

Comments
 (0)