Skip to content

Commit

Permalink
Bug fixes for Knitro 13.0 (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamferreira authored Feb 25, 2022
1 parent e3c714b commit fa14a8b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
14 changes: 7 additions & 7 deletions examples/knitro.opt
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ mip_implications yes
mip_integer_tol 1e-08

# Specifies absolute stop tolerance for sufficiently small integrality gap.
mip_integral_gap_abs 1e-06
mip_opt_gap_abs 1e-06

# Specifies relative stop tolerance for sufficiently small integrality gap.
mip_integral_gap_rel 1e-06
mip_opt_gap_rel 1e-06

# How to handle integer variables by default.
# none = 0 = no special treatment
Expand Down Expand Up @@ -692,28 +692,28 @@ outmode screen
# Number of threads to use in parallel BLAS.
# choose any positive integer, or
# 0 = determine automatically based on par_numthreads
par_blasnumthreads 0
blas_numthreads 0

# Whether to allow simultaneous evaluations in parallel.
# no = 0 = only one thread can perform an evaluation at a time
# yes = 1 = allow multi-threaded simultaneous evaluations
par_concurrent_evals yes
concurrent_evals yes

# Number of threads to use in parallel linear solver.
# choose any positive integer, or
# 0 = determine automatically based on par_numthreads
par_lsnumthreads 0
linsolver_numthreads 0

# Number of threads to use in parallel multistart.
# choose any positive integer, or
# 0 = determine automatically based on par_numthreads
par_msnumthreads 0
ms_numthreads 0

# Number of threads to use in parallel features.
# choose any positive integer, or
# 0 = value determined by OMP_NUM_THREADS environment variable
# -1 = run sequential version of Knitro code
par_numthreads 1
numthreads 1

# Specifies the initial pivot threshold used in the factorization routine.
# The value must be in the range [0 0.5] with higher values resulting
Expand Down
2 changes: 1 addition & 1 deletion examples/multistart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function example_multistart(; verbose=true)
nThreads = Sys.CPU_THREADS
if nThreads > 1
println("Force Knitro multistart to run in parallel with 1 threads (instead of $nThreads).")
KNITRO.KN_set_param(kc, KNITRO.KN_PARAM_PAR_MSNUMTHREADS, 1)
KNITRO.KN_set_param(kc, KNITRO.KN_PARAM_MS_NUMTHREADS, 1)
end

# Solve the problem.
Expand Down
6 changes: 5 additions & 1 deletion examples/tuner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ function example_tuner(; verbose=true)
nThreads = Sys.CPU_THREADS
if nThreads > 1
println("Force Knitro multistart to run in parallel with 1 threads (instead of $nThreads).")
KNITRO.KN_set_param(kc, KNITRO.KN_PARAM_PAR_NUMTHREADS, 1)
if KNITRO.KNITRO_VERSION >= v"13.0"
KNITRO.KN_set_param(kc, KNITRO.KN_PARAM_NUMTHREADS, 1)
else
KNITRO.KN_set_param(kc, KNITRO.KN_PARAM_PAR_NUMTHREADS, 1)
end
end

# Solve the problem.
Expand Down
1 change: 1 addition & 0 deletions src/kn_defines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ if KNITRO_VERSION >= v"13.0"
const KN_BFGS_SCALING_HESS = Cint(2)
const KN_PARAM_BAR_INITSHIFTTOL = Cint(1132)
const KN_PARAM_NUMTHREADS = Cint(1133)
const KN_PARAM_MIP_NUMTHREADS = Cint(2048)
const KN_PARAM_CONCURRENT_EVALS = Cint(1134)
const KN_CONCURRENT_EVALS_NO = Cint(0)
const KN_CONCURRENT_EVALS_YES = Cint(1)
Expand Down
1 change: 1 addition & 0 deletions src/kn_params.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const KN_paramName2Indx = Dict(
"KN_PARAM_BLAS_NUMTHREADS" => Cint(1135),
"KN_PARAM_LINSOLVER_NUMTHREADS" => Cint(1136),
"KN_PARAM_MS_NUMTHREADS" => Cint(1137),
"KN_PARAM_MIP_NUMTHREADS" => Cint(2048),
"KN_PARAM_CONIC_NUMTHREADS" => Cint(1138),
"KN_PARAM_NCVX_QCQP_INIT" => Cint(1139),
"KN_PARAM_MIP_OPTGAPABS" => Cint(2004),
Expand Down
10 changes: 8 additions & 2 deletions src/kn_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ function KN_solve(m::Model)
# as we have trouble calling Julia code from multithreaded C
# code. See issue #93 on https://github.com/jump-dev/KNITRO.jl.
if has_callbacks(m)
KN_set_param(m, "par_numthreads", 1)
KN_set_param(m, "par_msnumthreads", 1)
if KNITRO_VERSION >= v"13.0"
KN_set_param(m, KN_PARAM_MS_NUMTHREADS, 1)
KN_set_param(m, KN_PARAM_NUMTHREADS, 1)
KN_set_param(m, KN_PARAM_MIP_NUMTHREADS, 1)
else
KN_set_param(m, "par_numthreads", 1)
KN_set_param(m, "par_msnumthreads", 1)
end
end
# For KN_solve, we do not return an error if ret is different of 0.
m.status = @kn_ccall(solve, Cint, (Ptr{Cvoid},), m.env)
Expand Down
1 change: 1 addition & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const MOI_BASE_EXCLUDED = String[
"test_linear_transform", # Knitro does not support model transform
"test_linear_Semicontinuous_integration", # Wrong return status
"test_linear_Semiinteger_integration", # Wrong return status
"test_linear_integration_Interval", # TODO ? Knitro 13.0 converges to 9.99999* instead of 10.0
# QUADRATIC
"test_quadratic_Integer_SecondOrderCone", # MOI.get(model, MOI.TerminationStatus()) == MOI.OTHER_LIMIT
# CONIC
Expand Down
6 changes: 3 additions & 3 deletions test/knitroapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ end

@test KNITRO.KN_get_mip_number_nodes(kc) >= 1
@test KNITRO.KN_get_mip_number_solves(kc) >= 1
@test KNITRO.KN_get_mip_relaxation_bnd(kc) 31.0495680023
@test KNITRO.KN_get_mip_lastnode_obj(kc) 32.0
@test KNITRO.KN_get_mip_relaxation_bnd(kc) 31.3632000015
@test KNITRO.KN_get_mip_lastnode_obj(kc) 31.3632000015
@test KNITRO.KN_get_con_values(kc)[1] == 4.0
@test KNITRO.KN_get_mip_incumbent_obj(kc) 32.0
@test KNITRO.KN_get_mip_incumbent_x(kc) == 0.0
Expand Down Expand Up @@ -901,7 +901,7 @@ end

# Create a new Knitro solver instance.
kc = KNITRO.KN_new()
KNITRO.KN_set_param(kc, "outlev", 6)
KNITRO.KN_set_param(kc, "outlev", 0)

# Initialize Knitro with the problem definition.

Expand Down

0 comments on commit fa14a8b

Please sign in to comment.