I might want to use C-API? like
julia> function test(N)
m = Settings.Model() # a JuMP's gurobi direct model
JuMP.unset_silent(m)
o = m.moi_backend
v = fill(0., N)
t = fill(Int8(67), N) # variable type: all CONTINUOUS
@time JuMP.@variable(m, [1:N]) # by JuMP
@time Settings.addvars(o,N,v,v,v,t) # by Gurobi.GRBaddvars
Settings.opt_and_ter(m)
end;
julia> test(3) # let it compile for the first run
Set parameter OutputFlag to value 1
0.022536 seconds (35.39 k allocations: 1.754 MiB, 99.56% compilation time)
0.010390 seconds (13.19 k allocations: 650.391 KiB, 99.63% compilation time)
2 # OPTIMAL STATUS CODE
julia> test(100_000_000) # start a test
Set parameter OutputFlag to value 1
127.085007 seconds (300.00 M allocations: 23.548 GiB, 42.83% gc time)
28.775192 seconds (1 allocation: 16 bytes)
Gurobi Optimizer version 13.0.1 build v13.0.1rc0 (linux64gpu - "Ubuntu 24.04.4 LTS")
CPU model: AMD EPYC 7763 64-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 128 physical cores, 256 logical processors, using up to 1 threads
GPU model: NVIDIA RTX A6000, CUDA compute version 8.6, NVIDIA driver compatible with CUDA version 13
Non-default parameters:
Threads 1
Optimize a model with 0 rows, 200000000 columns and 0 nonzeros (Min)
Model fingerprint: 0x58ab99dd
Model has 0 linear objective coefficients
Coefficient statistics:
Matrix range [0e+00, 0e+00]
Objective range [0e+00, 0e+00]
Bounds range [0e+00, 0e+00]
RHS range [0e+00, 0e+00]
Presolve time: 26.98s
Iteration Objective Primal Inf. Dual Inf. Time
0 handle free variables 39s
Solved in 0 iterations and 51.90 seconds (5.11 work units)
Optimal objective 0.000000000e+00
2
And here is an example that use Gurobi.jl only (I think it’s my first time in such style).
import Gurobi
module Settings
import Gurobi
addvars(o,N,ov,lv,uv,tv) = Gurobi.GRBaddvars(o,N,0,C_NULL,C_NULL,C_NULL,ov,lv,uv,tv,C_NULL)
addvar(o,obj,l,u,t) = Gurobi.GRBaddvar(o,0,C_NULL,C_NULL,obj,l,u,t,C_NULL)
const _Default = Dict{String, Any}("OutputFlag" => 0, "Threads" => 1) # "Method" => 6, "PDHGGPU" => 1
Env() = Gurobi.Env(_Default)
Model() = Gurobi.Optimizer(Env())
end;
function test()
m = Settings.Model()
e = Gurobi.GRBgetenv(m)
Gurobi.GRBsetintparam(e, "OutputFlag", 1)
Settings.addvars(m,4,C_NULL,C_NULL,C_NULL,C_NULL)
Gurobi.GRBupdatemodel(m)
ci = Cint[0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]
cd = Cdouble[3, 3, 4, -5, 0, 0, 6, -2, 3, -2, 3, 2, 0, 8, -1, -5]
bg = Cint[0, 4, 8, 12]
sn = fill(Int8(61), 4) # sense is ==
b = Cdouble[1, 2, 3, 4]
Gurobi.GRBaddconstrs(m, 4, 16, bg, ci, cd, sn, b, C_NULL)
Gurobi.GRBsetdblparam(e, "TimeLimit", 7.)
Gurobi.GRBoptimize(m)
t = Ref{Cint}()
Gurobi.GRBgetintattr(m, "Status", t)
t.x == 2 || error()
x = fill(NaN, 4)
Gurobi.GRBgetdblattrarray(m, "X", 0, 4, x)
a = [3 3 4 -5; 0 0 6 -2; 3 -2 3 2; 0 8 -1 -5] # cf. `cd`
a * x - b
end;
test()