multithreadingjuliagurobisilentjulia-jump

Julia 1.5.2 Suppressing Gurobi academic license in parallel


I am attempting to suppress the academic license output from Gurobi. I have to solve an LP several times in my code and the print statement is slow and annoying to look at. I have created a working example. I wish to be able to execute the LP in parallel in Julia to increase performance. To suppress the output I use the package Suppressor. This seems to work well when running only using a single processor. However if I wrap the LP in a function and insert this into a loop and attempt to run the model in parallel I get an error:

TaskFailedException: SystemError: dup: bad file descriptor

Running the code works fine when using Windows 7 and an i5 processor.

Running the code on MAC OS 10.13.6 with an 2.66 GHz Intel core 2 duo does not work.

I am capable of running the code in parallel on MAC when it is not suppressed. Is it just because the hardware in ancient (the cores might not be able to communicate correctly to share information)? or is there a fix to this issue?

Additional information:

Julia: 1.5.2
Gurobi License version: 9.0.1
JuMP: 0.21.5
Suppressor: 0.2.0


clearconsole()
using Gurobi
using JuMP
using Suppressor
using BenchmarkTools


# Create LP frunction
function runlp()

    @suppress begin
        global primal = Model(Gurobi.Optimizer)
        set_optimizer_attributes(primal, "OutputFlag" => 0)
        set_optimizer_attributes(primal, "Threads" => 1)
    end

    # Declare variables with lower bound 0
    @variable(primal, x1 >= 0)
    @variable(primal, x2 >= 0)
    @variable(primal, -Inf <= x3 <= Inf)

    # Declare minimization of costs objective function
    @objective(primal, Min, -5*x1+4*x2-3*x3)

    # Declare constraint for minimum of lubricant 1
    @constraint(primal, Cons_1,2*x1-3*x2-x3 <= 5)
    @constraint(primal, Cons_2,4*x1-x2+2*x3 >= 11)
    @constraint(primal, Cons_3,-3*x1+4*x2+2*x3 <= 8)
    @constraint(primal, Cons_4,6*x1-5*x2+x3 == 1)

    # Optimize model
    optimize!(primal)

end


# Create function to ru LP multiple times
function testing()

    for i in 1:100
        runlp()
    end

end

testing()

@btime testing()

function testing_par()

    @sync Threads.@threads for i in 1:100
        runlp()
    end

end

@btime testing_par()

Solution

  • I'm not sure how Supressor works, but the way to resolve this with Gurobi.jl is to re-use an environment for multiple solves:

    https://github.com/jump-dev/Gurobi.jl#reusing-the-same-gurobi-environment-for-multiple-solves