# Parallel Solves in Gurobi.jl

**URL:** https://discourse.julialang.org/t/parallel-solves-in-gurobi-jl/9908
**Category:** Optimization (Mathematical)
**Created:** [March 22, 2018, 9:49pm UTC](https://discourse.julialang.org/t/parallel-solves-in-gurobi-jl/9908 "2018-03-22T21:49:28Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 15, 2020, 1:44am UTC](https://discourse.julialang.org/t/parallel-solves-in-gurobi-jl/9908/8 "2020-07-15T01:44:16Z")

</div>

> [@pearlzli](#):
>
> ```julia-auto
> A = 1:10
> m0 = make_model()
> @distributed (+) for a in A
> update_and_optimize!(m0, a)
> end
> 
> ```

This makes the model `m0` once, and then copies it to each worker. You need to construct the model with a different env on each worker.

```Julia
using Distributed
addprocs(3; exeflags = "--project=/tmp/gur") # Replace with your project
@everywhere begin
    using JuMP
    using Gurobi
    const ENV = Gurobi.Env()
end
@everywhere begin
    model = Model(() -> Gurobi.Optimizer(ENV))
    set_silent(model)
    @variable(model, 0 <= x <= 1)
    function update_and_solve(a)
        println("Solving $(a) from $(myid())")
        @objective(model, Max, a * x)
        optimize!(model)
        sleep(1.0)
        return objective_value(model)
    end
end

julia> @distributed (+) for a in 1:10
           update_and_solve(a)
       end
      From worker 3:	Solving 5 from 3
      From worker 2:	Solving 1 from 2
      From worker 4:	Solving 8 from 4
      From worker 3:	Solving 6 from 3
      From worker 2:	Solving 2 from 2
      From worker 4:	Solving 9 from 4
      From worker 4:	Solving 10 from 4
      From worker 3:	Solving 7 from 3
      From worker 2:	Solving 3 from 2
      From worker 2:	Solving 4 from 2
55.0

```

---

_[View the full topic](https://discourse.julialang.org/t/parallel-solves-in-gurobi-jl/9908)._
