Julia 1.5.2 并行抑制 Gurobi 学术许可证

Julia 1.5.2 Suppressing Gurobi academic license in parallel

我正试图禁止从 Gurobi 输出学术许可证。我必须在我的代码中多次解决 LP,打印语句很慢而且看起来很烦人。我创建了一个工作示例。我希望能够在 Julia 中并行执行 LP 以提高性能。为了抑制输出,我使用包 Suppressor。当 运行ning 仅使用单个处理器时,这似乎很有效。但是,如果我将 LP 包装在一个函数中并将其插入一个循环并尝试并行 运行 模型,我会收到错误消息:

TaskFailedException: SystemError: dup: bad file descriptor

运行 使用 Windows 7 和 i5 处理器时代码运行良好。

运行 MAC OS 10.13.6 2.66 GHz Intel core 2 duo 上的代码不工作。

我能够在 MAC 上并行 运行 代码,当它没有被抑制时。难道仅仅是因为硬件太古老了(内核可能无法正确通信以共享信息)?或者这个问题有解决办法吗?

附加信息:

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()

我不确定 Supressor 是如何工作的,但是 Gurobi.jl 解决这个问题的方法是重新使用一个环境进行多次解决:

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