From 40dc42e13729a89b2c425ce1104845807df76e65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 23 Oct 2019 14:52:05 +0200 Subject: [PATCH] Add support for Julia BLAS and LAPACK --- .travis.yml | 4 + deps/build.jl | 36 ++++++++- deps/clang.jl | 4 +- deps/compile.jl | 7 +- deps/constants.jl | 10 +-- src/MOI_wrapper.jl | 10 +-- src/MPB_wrapper.jl | 10 +-- src/blockmat.h.jl | 18 ++--- src/blockmat.jl | 8 +- src/debug-mat.jl | 2 +- src/declarations.h.jl | 172 +++++++++++++++++++++--------------------- src/declarations.jl | 30 ++++---- 12 files changed, 173 insertions(+), 138 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c67149..ddc584d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,10 @@ matrix: allow_failures: - julia: nightly +env: + - CSDP_USE_JULIA_LAPACK=true + - CSDP_USE_JULIA_LAPACK=false + addons: apt: # apt-get for linux packages: diff --git a/deps/build.jl b/deps/build.jl index b7b144b..f3b7fa3 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -3,12 +3,35 @@ using LinearAlgebra, Libdl @BinDeps.setup +blas = library_dependency("libblas", alias=["libblas.dll"]) +lapack = library_dependency("liblapack", alias=["liblapack.dll"]) + +const ENV_VAR = "CSDP_USE_JULIA_LAPACK" +const JULIA_LAPACK = if haskey(ENV, ENV_VAR) + value = ENV[ENV_VAR] + if lowercase(value) in ["1", "true", "yes"] + @info "Using the blas and lapack libraries shipped with Julia as the environment variable `$ENV_VAR` is set to `$value`." + true + elseif lowercase(value) in ["0", "false", "no"] + @info "Using system blas and lapack libraries as the environment variable `$ENV_VAR` is set to `$value`." + false + else + error("The environment variable `$ENV_VAR` is set to `$value`. Set it to `1` or `0` instead.") + end +else + if BinDeps.issatisfied(blas) && BinDeps.issatisfied(lapack) + @info "Using system blas and lapack libraries. Set the environment variable `$ENV_VAR` to `1` to use the blas/lapack library shipped with Julia." + false + else + @info "Using the blas and lapack libraries shipped with Julia as there is no system blas and lapack libraries installed." + true + end +end + include("constants.jl") include("compile.jl") # @info "libname = $libname" -blas = library_dependency("libblas", alias=["libblas.dll"]) -lapack = library_dependency("liblapack", alias=["liblapack.dll"]) depends = JULIA_LAPACK ? [] : [blas, lapack] # LaPack/BLAS dependencies @@ -47,3 +70,12 @@ provides(Binaries, [csdp, lapack, blas], unpacked_dir="usr", os = :Windows) @BinDeps.install Dict(:csdp => :csdp) + +open(joinpath(dirname(@__FILE__), "deps.jl"), write = true, append = true) do io + print(io, "const CSDP_INT = ") + if JULIA_LAPACK + println(io, "Clong") + else + println(io, "Cint") + end +end diff --git a/deps/clang.jl b/deps/clang.jl index babcc5a..6d88ea8 100644 --- a/deps/clang.jl +++ b/deps/clang.jl @@ -43,12 +43,12 @@ readchangewrite(header_naming("blockmat.h")) do b #,(r"::Ptr", s"::Ref") ,(r"\ntype "m, "\nimmutable ") ] - b = replace(b, pat, subs) + b = replace(b, pat => subs) end b end readchangewrite(header_naming("declarations.h")) do d - replace(d, r"\nfunction \w+_\(\)\n(.+?)\nend\n"sm, "") + replace(d, r"\nfunction \w+_\(\)\n(.+?)\nend\n"sm => "") end diff --git a/deps/compile.jl b/deps/compile.jl index cce70ae..eeb682e 100644 --- a/deps/compile.jl +++ b/deps/compile.jl @@ -49,8 +49,9 @@ function patch_int(; verbose::Bool = false) (r"\(int\)", s"(integer)"), (r"%d", s"%ld"), (r"%2d", s"%2ld"), - (r" int ", s" integer ")] - content = replace(content, re, subst) + (r" int ", s" integer "), + (r"dsymv_", s"dsymv_64_")] + content = replace(content, re => subst) end open(cfile, "w") do io print(io, content) @@ -63,7 +64,7 @@ end function compile_objs(JULIA_LAPACK=JULIA_LAPACK) if JULIA_LAPACK lapack = Libdl.dlpath(LinearAlgebra.LAPACK.liblapack) - lflag = replace(splitext(basename(lapack))[1], r"^lib", "") + lflag = replace(splitext(basename(lapack))[1], r"^lib" => "") libs = ["-L$(dirname(lapack))", "-l$lflag"] @info libs if endswith(LinearAlgebra.LAPACK.liblapack, "64_") diff --git a/deps/constants.jl b/deps/constants.jl index a55ed18..15b6f20 100644 --- a/deps/constants.jl +++ b/deps/constants.jl @@ -1,16 +1,14 @@ # use Julia's libopenblas instead of system's liblapack and libblas? -const JULIA_LAPACK = false -const suffix = JULIA_LAPACK ? ".64" : "" const version = "6.2.0" -const libname = "libcsdp$suffix.$(Libdl.dlext)" +const libname = "libcsdp.$(Libdl.dlext)" const csdpversion = "Csdp-readprob" const download_url = "https://github.com/blegat/Csdp/archive/readprob.zip" -patchf = joinpath(dirname(@__FILE__), "src$suffix", "debug-mat.c") -srcdir = joinpath(dirname(@__FILE__), "src$suffix", csdpversion, "lib") +patchf = joinpath(dirname(@__FILE__), "src", "debug-mat.c") +srcdir = joinpath(dirname(@__FILE__), "src", csdpversion, "lib") prefix = joinpath(dirname(@__FILE__), "usr") -builddir = joinpath(dirname(@__FILE__), "build$suffix") +builddir = joinpath(dirname(@__FILE__), "build") cflags = ["-I$srcdir/../include", "-DNOSHORTS", "-g"] libdir = joinpath(prefix, @static Sys.iswindows() ? "bin" : "lib/") dlpath = joinpath(libdir, libname) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index c9ebd68..8e0a8fb 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -6,7 +6,7 @@ const AFFEQ = MOI.ConstraintIndex{MOI.ScalarAffineFunction{Cdouble}, MOI.EqualTo mutable struct Optimizer <: MOI.AbstractOptimizer objconstant::Cdouble objsign::Int - blockdims::Vector{Cint} + blockdims::Vector{CSDP_INT} varmap::Vector{Tuple{Int, Int, Int}} # Variable Index vi -> blk, i, j num_entries::Dict{Tuple{Int, Int}, Int} b::Vector{Cdouble} @@ -15,7 +15,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer X::blockmatrix y::Union{Nothing, Vector{Cdouble}} Z::blockmatrix - status::Cint + status::CSDP_INT pobj::Cdouble dobj::Cdouble solve_time::Float64 @@ -23,7 +23,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer options::Dict{Symbol, Any} function Optimizer(; kwargs...) optimizer = new( - zero(Cdouble), 1, Cint[], Tuple{Int, Int, Int}[], + zero(Cdouble), 1, CSDP_INT[], Tuple{Int, Int, Int}[], Dict{Tuple{Int, Int}, Int}(), Cdouble[], blockmatrix(), nothing, blockmatrix(), nothing, blockmatrix(), -1, NaN, NaN, NaN, false, Dict{Symbol, Any}()) @@ -211,11 +211,11 @@ function MOIU.load_variables(optimizer::Optimizer, nvars) if dummy # See https://github.com/coin-or/Csdp/issues/2 optimizer.b = [one(Cdouble)] - optimizer.blockdims = [optimizer.blockdims; Cint(-1)] + optimizer.blockdims = [optimizer.blockdims; CSDP_INT(-1)] count_entry(optimizer, 1, length(optimizer.blockdims)) end optimizer.C.nblocks = length(optimizer.blockdims) - num_entries = zeros(Cint, length(optimizer.b), length(optimizer.blockdims)) + num_entries = zeros(CSDP_INT, length(optimizer.b), length(optimizer.blockdims)) for (key, value) in optimizer.num_entries num_entries[key...] = value end diff --git a/src/MPB_wrapper.jl b/src/MPB_wrapper.jl index a268dde..a8cfca3 100644 --- a/src/MPB_wrapper.jl +++ b/src/MPB_wrapper.jl @@ -20,20 +20,20 @@ end CSDPSolver(; kwargs...) = CSDPSolver(checkoptions(Dict{Symbol,Any}(kwargs))) mutable struct CSDPMathProgModel <: SDM.AbstractSDModel - blockdims::Vector{Cint} + blockdims::Vector{CSDP_INT} b::Vector{Cdouble} - entries::Vector{Tuple{Cint,Cint,Cint,Cint,Cdouble}} + entries::Vector{Tuple{CSDP_INT,CSDP_INT,CSDP_INT,CSDP_INT,Cdouble}} C::blockmatrix problem::Union{Nothing, LoadingProblem} X::blockmatrix y::Union{Nothing, Vector{Cdouble}} Z::blockmatrix - status::Cint + status::CSDP_INT pobj::Cdouble dobj::Cdouble options::Dict{Symbol,Any} function CSDPMathProgModel(; kwargs...) - new(Cint[], Cdouble[], Tuple{Cint,Cint,Cint,Cint,Cdouble}[], + new(CSDP_INT[], Cdouble[], Tuple{CSDP_INT,CSDP_INT,CSDP_INT,CSDP_INT,Cdouble}[], blockmatrix(), nothing, blockmatrix(), nothing, blockmatrix(), -1, 0.0, 0.0, checkoptions(Dict{Symbol, Any}(kwargs))) end @@ -93,7 +93,7 @@ function MPB.optimize!(m::CSDPMathProgModel) if m.problem === nothing # `m.problem` is not `nothing` if it was loaded from a file. m.C.nblocks = length(m.blockdims) - num_entries = zeros(Cint, length(m.b), length(m.blockdims)) + num_entries = zeros(CSDP_INT, length(m.b), length(m.blockdims)) for entry in m.entries if entry[1] > 0 num_entries[entry[1], entry[2]] += 1 diff --git a/src/blockmat.h.jl b/src/blockmat.h.jl index e814c1c..df57c19 100644 --- a/src/blockmat.h.jl +++ b/src/blockmat.h.jl @@ -6,7 +6,7 @@ @static if Sys.iswindows() const csdpshort = Cushort else - const csdpshort = Cint + const csdpshort = CSDP_INT end # begin enum blockcat @@ -27,10 +27,10 @@ struct blockrec <: AbstractMatrix{Cdouble} end mutable struct blockmatrix <: AbstractBlockMatrix{Cdouble} - nblocks::Cint + nblocks::CSDP_INT blocks::Ptr{blockrec} end -blockmatrix() = blockmatrix(Cint(0), C_NULL) +blockmatrix() = blockmatrix(CSDP_INT(0), C_NULL) mutable struct sparseblock next::Ptr{sparseblock} @@ -38,7 +38,7 @@ mutable struct sparseblock entries::Ptr{Cdouble} iindices::Ptr{csdpshort} jindices::Ptr{csdpshort} - numentries::Cint + numentries::CSDP_INT blocknum::csdpshort blocksize::csdpshort constraintnum::csdpshort @@ -67,16 +67,16 @@ mutable struct paramstruc objtol::Cdouble pinftol::Cdouble dinftol::Cdouble - maxiter::Cint + maxiter::CSDP_INT minstepfrac::Cdouble maxstepfrac::Cdouble minstepp::Cdouble minstepd::Cdouble - usexzgap::Cint - tweakgap::Cint - affine::Cint + usexzgap::CSDP_INT + tweakgap::CSDP_INT + affine::CSDP_INT perturbobj::Cdouble - fastmode::Cint + fastmode::CSDP_INT end function paramstruc(options::Dict) diff --git a/src/blockmat.jl b/src/blockmat.jl index a31545c..d3799f2 100644 --- a/src/blockmat.jl +++ b/src/blockmat.jl @@ -174,7 +174,7 @@ mutable struct SparseBlock <: AbstractMatrix{Cdouble} i::Vector{csdpshort} j::Vector{csdpshort} v::Vector{Cdouble} - n::Cint + n::CSDP_INT csdp::sparseblock function SparseBlock(i::Vector{csdpshort}, j::Vector{csdpshort}, v::Vector{Cdouble}, n::Integer, csdp) new(i, j, v, n, csdp) @@ -217,7 +217,7 @@ function SparseBlock(A::SparseMatrixCSC{Cdouble}) end SparseBlock(I, J, V, n) end -SparseBlock(A::AbstractMatrix{Cdouble}) = SparseBlock(SparseMatrixCSC{Cdouble, Cint}(A)) +SparseBlock(A::AbstractMatrix{Cdouble}) = SparseBlock(SparseMatrixCSC{Cdouble, CSDP_INT}(A)) SparseBlock(A::AbstractMatrix) = SparseBlock(map(Cdouble, A)) Base.convert(::Type{SparseBlock}, A::AbstractMatrix) = SparseBlock(A) @@ -320,8 +320,8 @@ export BlockMatrix, ConstraintMatrix """Solver status""" mutable struct Csdp - n::Cint - k::Cint + n::CSDP_INT + k::CSDP_INT X::BlockMatrix y::Vector{Cdouble} constant_offset::Cdouble diff --git a/src/debug-mat.jl b/src/debug-mat.jl index 9dfeee9..970805f 100644 --- a/src/debug-mat.jl +++ b/src/debug-mat.jl @@ -19,7 +19,7 @@ function print_sizeof() end function print_constraints(C::Vector{constraintmatrix}) - ccall((:print_constraints, CSDP.csdp), Nothing, (Cint, Ptr{constraintmatrix}), length(C), fptr(C)) + ccall((:print_constraints, CSDP.csdp), Nothing, (CSDP_INT, Ptr{constraintmatrix}), length(C), fptr(C)) end diff --git a/src/declarations.h.jl b/src/declarations.h.jl index 26290ae..7e69f50 100644 --- a/src/declarations.h.jl +++ b/src/declarations.h.jl @@ -23,36 +23,36 @@ function free_mat_packed(A::blockmatrix) ccall((:free_mat_packed,CSDP.csdp),Nothing,(blockmatrix,),A) end -function structnnz(n::Cint,k::Cint,C::blockmatrix,constraints::Ptr{constraintmatrix}) - ccall((:structnnz,CSDP.csdp),Cint,(Cint,Cint,blockmatrix,Ptr{constraintmatrix}),n,k,C,constraints) +function structnnz(n::CSDP_INT,k::CSDP_INT,C::blockmatrix,constraints::Ptr{constraintmatrix}) + ccall((:structnnz,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,blockmatrix,Ptr{constraintmatrix}),n,k,C,constraints) end -function actnnz(n::Cint,lda::Cint,A::Ptr{Cdouble}) - ccall((:actnnz,CSDP.csdp),Cint,(Cint,Cint,Ptr{Cdouble}),n,lda,A) +function actnnz(n::CSDP_INT,lda::CSDP_INT,A::Ptr{Cdouble}) + ccall((:actnnz,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,Ptr{Cdouble}),n,lda,A) end -function bandwidth(n::Cint,lda::Cint,A::Ptr{Cdouble}) - ccall((:bandwidth,CSDP.csdp),Cint,(Cint,Cint,Ptr{Cdouble}),n,lda,A) +function bandwidth(n::CSDP_INT,lda::CSDP_INT,A::Ptr{Cdouble}) + ccall((:bandwidth,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,Ptr{Cdouble}),n,lda,A) end -function qreig(n::Cint,maindiag::Ptr{Cdouble},offdiag::Ptr{Cdouble}) - ccall((:qreig,CSDP.csdp),Nothing,(Cint,Ptr{Cdouble},Ptr{Cdouble}),n,maindiag,offdiag) +function qreig(n::CSDP_INT,maindiag::Ptr{Cdouble},offdiag::Ptr{Cdouble}) + ccall((:qreig,CSDP.csdp),Nothing,(CSDP_INT,Ptr{Cdouble},Ptr{Cdouble}),n,maindiag,offdiag) end -function sort_entries(k::Cint,C::blockmatrix,constraints::Ptr{constraintmatrix}) - ccall((:sort_entries,CSDP.csdp),Nothing,(Cint,blockmatrix,Ptr{constraintmatrix}),k,C,constraints) +function sort_entries(k::CSDP_INT,C::blockmatrix,constraints::Ptr{constraintmatrix}) + ccall((:sort_entries,CSDP.csdp),Nothing,(CSDP_INT,blockmatrix,Ptr{constraintmatrix}),k,C,constraints) end -function norm2(n::Cint,x::Ptr{Cdouble}) - ccall((:norm2,CSDP.csdp),Cdouble,(Cint,Ptr{Cdouble}),n,x) +function norm2(n::CSDP_INT,x::Ptr{Cdouble}) + ccall((:norm2,CSDP.csdp),Cdouble,(CSDP_INT,Ptr{Cdouble}),n,x) end -function norm1(n::Cint,x::Ptr{Cdouble}) - ccall((:norm1,CSDP.csdp),Cdouble,(Cint,Ptr{Cdouble}),n,x) +function norm1(n::CSDP_INT,x::Ptr{Cdouble}) + ccall((:norm1,CSDP.csdp),Cdouble,(CSDP_INT,Ptr{Cdouble}),n,x) end -function norminf(n::Cint,x::Ptr{Cdouble}) - ccall((:norminf,CSDP.csdp),Cdouble,(Cint,Ptr{Cdouble}),n,x) +function norminf(n::CSDP_INT,x::Ptr{Cdouble}) + ccall((:norminf,CSDP.csdp),Cdouble,(CSDP_INT,Ptr{Cdouble}),n,x) end function Fnorm(A::blockmatrix) @@ -75,44 +75,44 @@ function calc_pobj(C::blockmatrix,X::blockmatrix,constant_offset::Cdouble) ccall((:calc_pobj,CSDP.csdp),Cdouble,(blockmatrix,blockmatrix,Cdouble),C,X,constant_offset) end -function calc_dobj(k::Cint,a::Ptr{Cdouble},y::Ptr{Cdouble},constant_offset::Cdouble) - ccall((:calc_dobj,CSDP.csdp),Cdouble,(Cint,Ptr{Cdouble},Ptr{Cdouble},Cdouble),k,a,y,constant_offset) +function calc_dobj(k::CSDP_INT,a::Ptr{Cdouble},y::Ptr{Cdouble},constant_offset::Cdouble) + ccall((:calc_dobj,CSDP.csdp),Cdouble,(CSDP_INT,Ptr{Cdouble},Ptr{Cdouble},Cdouble),k,a,y,constant_offset) end function trace_prod(A::blockmatrix,B::blockmatrix) ccall((:trace_prod,CSDP.csdp),Cdouble,(blockmatrix,blockmatrix),A,B) end -function linesearch(n::Cint,dX::blockmatrix,work1::blockmatrix,work2::blockmatrix,work3::blockmatrix,cholinv::blockmatrix,q::Ptr{Cdouble},z::Ptr{Cdouble},workvec::Ptr{Cdouble},stepfrac::Cdouble,start::Cdouble,printlevel::Cint) - ccall((:linesearch,CSDP.csdp),Cdouble,(Cint,blockmatrix,blockmatrix,blockmatrix,blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Cdouble,Cdouble,Cint),n,dX,work1,work2,work3,cholinv,q,z,workvec,stepfrac,start,printlevel) +function linesearch(n::CSDP_INT,dX::blockmatrix,work1::blockmatrix,work2::blockmatrix,work3::blockmatrix,cholinv::blockmatrix,q::Ptr{Cdouble},z::Ptr{Cdouble},workvec::Ptr{Cdouble},stepfrac::Cdouble,start::Cdouble,printlevel::CSDP_INT) + ccall((:linesearch,CSDP.csdp),Cdouble,(CSDP_INT,blockmatrix,blockmatrix,blockmatrix,blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Cdouble,Cdouble,CSDP_INT),n,dX,work1,work2,work3,cholinv,q,z,workvec,stepfrac,start,printlevel) end -function pinfeas(k::Cint,constraints::Ptr{constraintmatrix},X::blockmatrix,a::Ptr{Cdouble},workvec::Ptr{Cdouble}) - ccall((:pinfeas,CSDP.csdp),Cdouble,(Cint,Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble},Ptr{Cdouble}),k,constraints,X,a,workvec) +function pinfeas(k::CSDP_INT,constraints::Ptr{constraintmatrix},X::blockmatrix,a::Ptr{Cdouble},workvec::Ptr{Cdouble}) + ccall((:pinfeas,CSDP.csdp),Cdouble,(CSDP_INT,Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble},Ptr{Cdouble}),k,constraints,X,a,workvec) end -function dinfeas(k::Cint,C::blockmatrix,constraints::Ptr{constraintmatrix},y::Ptr{Cdouble},Z::blockmatrix,work1::blockmatrix) - ccall((:dinfeas,CSDP.csdp),Cdouble,(Cint,blockmatrix,Ptr{constraintmatrix},Ptr{Cdouble},blockmatrix,blockmatrix),k,C,constraints,y,Z,work1) +function dinfeas(k::CSDP_INT,C::blockmatrix,constraints::Ptr{constraintmatrix},y::Ptr{Cdouble},Z::blockmatrix,work1::blockmatrix) + ccall((:dinfeas,CSDP.csdp),Cdouble,(CSDP_INT,blockmatrix,Ptr{constraintmatrix},Ptr{Cdouble},blockmatrix,blockmatrix),k,C,constraints,y,Z,work1) end -function dimacserr3(k::Cint,C::blockmatrix,constraints::Ptr{constraintmatrix},y::Ptr{Cdouble},Z::blockmatrix,work1::blockmatrix) - ccall((:dimacserr3,CSDP.csdp),Cdouble,(Cint,blockmatrix,Ptr{constraintmatrix},Ptr{Cdouble},blockmatrix,blockmatrix),k,C,constraints,y,Z,work1) +function dimacserr3(k::CSDP_INT,C::blockmatrix,constraints::Ptr{constraintmatrix},y::Ptr{Cdouble},Z::blockmatrix,work1::blockmatrix) + ccall((:dimacserr3,CSDP.csdp),Cdouble,(CSDP_INT,blockmatrix,Ptr{constraintmatrix},Ptr{Cdouble},blockmatrix,blockmatrix),k,C,constraints,y,Z,work1) end -function op_a(k::Cint,constraints::Ptr{constraintmatrix},X::blockmatrix,result::Ptr{Cdouble}) - ccall((:op_a,CSDP.csdp),Nothing,(Cint,Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble}),k,constraints,X,result) +function op_a(k::CSDP_INT,constraints::Ptr{constraintmatrix},X::blockmatrix,result::Ptr{Cdouble}) + ccall((:op_a,CSDP.csdp),Nothing,(CSDP_INT,Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble}),k,constraints,X,result) end -function op_at(k::Cint,y::Ptr{Cdouble},constraints::Ptr{constraintmatrix},result::blockmatrix) - ccall((:op_at,CSDP.csdp),Nothing,(Cint,Ptr{Cdouble},Ptr{constraintmatrix},blockmatrix),k,y,constraints,result) +function op_at(k::CSDP_INT,y::Ptr{Cdouble},constraints::Ptr{constraintmatrix},result::blockmatrix) + ccall((:op_at,CSDP.csdp),Nothing,(CSDP_INT,Ptr{Cdouble},Ptr{constraintmatrix},blockmatrix),k,y,constraints,result) end -function makefill(k::Cint,C::blockmatrix,constraints::Ptr{constraintmatrix},pfill::Ref{constraintmatrix},work1::blockmatrix,printlevel::Cint) - ccall((:makefill,CSDP.csdp),Nothing,(Cint,blockmatrix,Ptr{constraintmatrix},Ref{constraintmatrix},blockmatrix,Cint),k,C,constraints,pfill,work1,printlevel) +function makefill(k::CSDP_INT,C::blockmatrix,constraints::Ptr{constraintmatrix},pfill::Ref{constraintmatrix},work1::blockmatrix,printlevel::CSDP_INT) + ccall((:makefill,CSDP.csdp),Nothing,(CSDP_INT,blockmatrix,Ptr{constraintmatrix},Ref{constraintmatrix},blockmatrix,CSDP_INT),k,C,constraints,pfill,work1,printlevel) end -function op_o(k::Cint,constraints::Ptr{constraintmatrix},byblocks::Ptr{Ptr{sparseblock}},Zi::blockmatrix,X::blockmatrix,O::Ptr{Cdouble},work1::blockmatrix,work2::blockmatrix) - ccall((:op_o,CSDP.csdp),Nothing,(Cint,Ptr{constraintmatrix},Ptr{Ptr{sparseblock}},blockmatrix,blockmatrix,Ptr{Cdouble},blockmatrix,blockmatrix),k,constraints,byblocks,Zi,X,O,work1,work2) +function op_o(k::CSDP_INT,constraints::Ptr{constraintmatrix},byblocks::Ptr{Ptr{sparseblock}},Zi::blockmatrix,X::blockmatrix,O::Ptr{Cdouble},work1::blockmatrix,work2::blockmatrix) + ccall((:op_o,CSDP.csdp),Nothing,(CSDP_INT,Ptr{constraintmatrix},Ptr{Ptr{sparseblock}},blockmatrix,blockmatrix,Ptr{Cdouble},blockmatrix,blockmatrix),k,constraints,byblocks,Zi,X,O,work1,work2) end function addscaledmat(A::blockmatrix,scale::Cdouble,B::blockmatrix,C::blockmatrix) @@ -155,12 +155,12 @@ function mat_multspc(scale1::Cdouble,scale2::Cdouble,A::blockmatrix,B::blockmatr ccall((:mat_multspc,CSDP.csdp),Nothing,(Cdouble,Cdouble,blockmatrix,blockmatrix,blockmatrix,constraintmatrix),scale1,scale2,A,B,C,fill) end -function mat_mult_raw(n::Cint,scale1::Cdouble,scale2::Cdouble,ap::Ptr{Cdouble},bp::Ptr{Cdouble},cp::Ptr{Cdouble}) - ccall((:mat_mult_raw,CSDP.csdp),Nothing,(Cint,Cdouble,Cdouble,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble}),n,scale1,scale2,ap,bp,cp) +function mat_mult_raw(n::CSDP_INT,scale1::Cdouble,scale2::Cdouble,ap::Ptr{Cdouble},bp::Ptr{Cdouble},cp::Ptr{Cdouble}) + ccall((:mat_mult_raw,CSDP.csdp),Nothing,(CSDP_INT,Cdouble,Cdouble,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble}),n,scale1,scale2,ap,bp,cp) end -function mat_mult_rawatlas(n::Cint,scale1::Cdouble,scale2::Cdouble,ap::Ptr{Cdouble},bp::Ptr{Cdouble},cp::Ptr{Cdouble}) - ccall((:mat_mult_rawatlas,CSDP.csdp),Nothing,(Cint,Cdouble,Cdouble,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble}),n,scale1,scale2,ap,bp,cp) +function mat_mult_rawatlas(n::CSDP_INT,scale1::Cdouble,scale2::Cdouble,ap::Ptr{Cdouble},bp::Ptr{Cdouble},cp::Ptr{Cdouble}) + ccall((:mat_mult_rawatlas,CSDP.csdp),Nothing,(CSDP_INT,Cdouble,Cdouble,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble}),n,scale1,scale2,ap,bp,cp) end function matvec(A::blockmatrix,x::Ptr{Cdouble},y::Ptr{Cdouble}) @@ -175,8 +175,8 @@ function free_mat(A::blockmatrix) ccall((:free_mat,CSDP.csdp),Nothing,(blockmatrix,),A) end -function initparams(params::Ptr{paramstruc},pprintlevel::Ptr{Cint}) - ccall((:initparams,CSDP.csdp),Nothing,(Ptr{paramstruc},Ptr{Cint}),params,pprintlevel) +function initparams(params::Ptr{paramstruc},pprintlevel::Ptr{CSDP_INT}) + ccall((:initparams,CSDP.csdp),Nothing,(Ptr{paramstruc},Ptr{CSDP_INT}),params,pprintlevel) end function loaded_initsoln(problem::Ptr{Cvoid}, X::Ref{blockmatrix}, Z::Ref{blockmatrix}) @@ -184,11 +184,11 @@ function loaded_initsoln(problem::Ptr{Cvoid}, X::Ref{blockmatrix}, Z::Ref{blockm ccall((:loaded_initsoln,CSDP.csdp),Nothing,(Ptr{Cvoid},Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{blockmatrix}),problem,X,y,Z) return y[] end -function initsoln(n::Cint,k::Cint,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix}) +function initsoln(n::CSDP_INT,k::CSDP_INT,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix}) X = Ref{blockmatrix}(blockmatrix(0, C_NULL)) y = Ref{Ptr{Cdouble}}(C_NULL) Z = Ref{blockmatrix}(blockmatrix(0, C_NULL)) - ccall((:initsoln,CSDP.csdp),Nothing,(Cint,Cint,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{blockmatrix}),n,k,C,a,constraints,X,y,Z) + ccall((:initsoln,CSDP.csdp),Nothing,(CSDP_INT,CSDP_INT,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{blockmatrix}),n,k,C,a,constraints,X,y,Z) X[], y[], Z[] end @@ -201,36 +201,36 @@ function chol_inv(A::blockmatrix,B::blockmatrix) end function chol(A::blockmatrix) - ccall((:chol,CSDP.csdp),Cint,(blockmatrix,),A) + ccall((:chol,CSDP.csdp),CSDP_INT,(blockmatrix,),A) end -function solvesys(m::Cint,ldam::Cint,A::Ptr{Cdouble},rhs::Ptr{Cdouble}) - ccall((:solvesys,CSDP.csdp),Cint,(Cint,Cint,Ptr{Cdouble},Ptr{Cdouble}),m,ldam,A,rhs) +function solvesys(m::CSDP_INT,ldam::CSDP_INT,A::Ptr{Cdouble},rhs::Ptr{Cdouble}) + ccall((:solvesys,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,Ptr{Cdouble},Ptr{Cdouble}),m,ldam,A,rhs) end -function user_exit(n::Cint,k::Cint,C::blockmatrix,a::Ptr{Cdouble},dobj::Cdouble,pobj::Cdouble,constant_offset::Cdouble,constraints::Ptr{constraintmatrix},X::blockmatrix,y::Ptr{Cdouble},Z::blockmatrix,params::paramstruc) - ccall((:user_exit,CSDP.csdp),Cint,(Cint,Cint,blockmatrix,Ptr{Cdouble},Cdouble,Cdouble,Cdouble,Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble},blockmatrix,paramstruc),n,k,C,a,dobj,pobj,constant_offset,constraints,X,y,Z,params) +function user_exit(n::CSDP_INT,k::CSDP_INT,C::blockmatrix,a::Ptr{Cdouble},dobj::Cdouble,pobj::Cdouble,constant_offset::Cdouble,constraints::Ptr{constraintmatrix},X::blockmatrix,y::Ptr{Cdouble},Z::blockmatrix,params::paramstruc) + ccall((:user_exit,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,blockmatrix,Ptr{Cdouble},Cdouble,Cdouble,Cdouble,Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble},blockmatrix,paramstruc),n,k,C,a,dobj,pobj,constant_offset,constraints,X,y,Z,params) end -function read_sol(fname::Ptr{UInt8},n::Cint,k::Cint,C::blockmatrix,pX::Ptr{blockmatrix},py::Ptr{Ptr{Cdouble}},pZ::Ptr{blockmatrix}) - ccall((:read_sol,CSDP.csdp),Cint,(Ptr{UInt8},Cint,Cint,blockmatrix,Ptr{blockmatrix},Ptr{Ptr{Cdouble}},Ptr{blockmatrix}),fname,n,k,C,pX,py,pZ) +function read_sol(fname::Ptr{UInt8},n::CSDP_INT,k::CSDP_INT,C::blockmatrix,pX::Ptr{blockmatrix},py::Ptr{Ptr{Cdouble}},pZ::Ptr{blockmatrix}) + ccall((:read_sol,CSDP.csdp),CSDP_INT,(Ptr{UInt8},CSDP_INT,CSDP_INT,blockmatrix,Ptr{blockmatrix},Ptr{Ptr{Cdouble}},Ptr{blockmatrix}),fname,n,k,C,pX,py,pZ) end function load_prob_from_file(fname::String,C::Ref{blockmatrix},printlevel::Integer=1) problem = Ref{Ptr{Cvoid}}(C_NULL) - ret = ccall((:load_prob_from_file,CSDP.csdp),Cint,(Ptr{UInt8},Ref{blockmatrix},Ref{Ptr{Cvoid}},Cint),fname,C,problem,printlevel) + ret = ccall((:load_prob_from_file,CSDP.csdp),CSDP_INT,(Ptr{UInt8},Ref{blockmatrix},Ref{Ptr{Cvoid}},CSDP_INT),fname,C,problem,printlevel) if !iszero(ret) error("`CSDP.load_prob_from_file` failed.") end return LoadingProblem(problem[]) end function read_prob(fname::String,printlevel::Integer=1) - n = Ref{Cint}(0) - k = Ref{Cint}(0) + n = Ref{CSDP_INT}(0) + k = Ref{CSDP_INT}(0) C = Ref{blockmatrix}(blockmatrix(0, C_NULL)) a = Ref{Ptr{Cdouble}}(C_NULL) constraints = Ref{Ptr{constraintmatrix}}(C_NULL) - ccall((:read_prob,CSDP.csdp),Cint,(Ptr{UInt8},Ref{Cint},Ref{Cint},Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{Ptr{constraintmatrix}},Cint),fname,n,k,C,a,constraints,printlevel) + ccall((:read_prob,CSDP.csdp),CSDP_INT,(Ptr{UInt8},Ref{CSDP_INT},Ref{CSDP_INT},Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{Ptr{constraintmatrix}},CSDP_INT),fname,n,k,C,a,constraints,printlevel) C = mywrap(C[]) a = mywrap(a[], k[]) constraints = mywrap(constraints[], k[]) @@ -243,38 +243,38 @@ function read_prob(fname::String,printlevel::Integer=1) end function write_prob(fname::String, - n::Cint, - k::Cint, + n::CSDP_INT, + k::CSDP_INT, C::blockmatrix, a::Ptr{Cdouble}, constraints::Ptr{constraintmatrix}) - ccall((:write_prob,CSDP.csdp),Cint,(Ptr{UInt8},Cint,Cint,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix}), + ccall((:write_prob,CSDP.csdp),CSDP_INT,(Ptr{UInt8},CSDP_INT,CSDP_INT,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix}), fname,n,k,C,a,constraints) end function write_sol(fname::String, - n::Cint, - k::Cint, + n::CSDP_INT, + k::CSDP_INT, X::blockmatrix, y::Ptr{Cdouble}, Z::blockmatrix) ccall((:write_sol,CSDP.csdp), - Cint, + CSDP_INT, (Ptr{UInt8}, - Cint, - Cint, + CSDP_INT, + CSDP_INT, blockmatrix, Ptr{Cdouble}, blockmatrix), fname,n,k,X,y,Z) end -function free_prob(n::Cint,k::Cint,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},X::blockmatrix,y::Ptr{Cdouble},Z::blockmatrix) - ccall((:free_prob,CSDP.csdp),Nothing,(Cint,Cint,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble},blockmatrix),n,k,C,a,constraints,X,y,Z) +function free_prob(n::CSDP_INT,k::CSDP_INT,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},X::blockmatrix,y::Ptr{Cdouble},Z::blockmatrix) + ccall((:free_prob,CSDP.csdp),Nothing,(CSDP_INT,CSDP_INT,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},blockmatrix,Ptr{Cdouble},blockmatrix),n,k,C,a,constraints,X,y,Z) end #function new_blockmatrix(nblocks::Integer) -# return ccall((:new_blockmatrix,CSDP.csdp),Ptr{Cvoid},(Cint,),nblocks) +# return ccall((:new_blockmatrix,CSDP.csdp),Ptr{Cvoid},(CSDP_INT,),nblocks) #end #function free_blockmatrix(C::Ptr{Cvoid}) # ccall((:free_blockmatrix,CSDP.csdp),Nothing,(Ptr{Cvoid},),C) @@ -282,14 +282,14 @@ end function Base.getindex(A::blockrec, i::Integer, j::Integer) - return ccall((:getindex,CSDP.csdp), Cdouble, (blockrec,Cint,Cint), A, i, j) + return ccall((:getindex,CSDP.csdp), Cdouble, (blockrec,CSDP_INT,CSDP_INT), A, i, j) end function getblockrec(A::blockmatrix, i::Integer) - return ccall((:getblockrec,CSDP.csdp), blockrec, (blockmatrix,Cint), A, i) + return ccall((:getblockrec,CSDP.csdp), blockrec, (blockmatrix,CSDP_INT), A, i) end -function allocate_loading_prob(pC::Ref{blockmatrix}, block_dims::Ptr{Cint}, num_constraints::Integer, num_entries::Ptr{Cint}, printlevel::Integer) - return ccall((:allocate_loading_prob,CSDP.csdp),Ptr{Cvoid},(Ref{blockmatrix},Ptr{Cint},Cint,Ptr{Cint},Cint),pC,block_dims,num_constraints,num_entries,printlevel) +function allocate_loading_prob(pC::Ref{blockmatrix}, block_dims::Ptr{CSDP_INT}, num_constraints::Integer, num_entries::Ptr{CSDP_INT}, printlevel::Integer) + return ccall((:allocate_loading_prob,CSDP.csdp),Ptr{Cvoid},(Ref{blockmatrix},Ptr{CSDP_INT},CSDP_INT,Ptr{CSDP_INT},CSDP_INT),pC,block_dims,num_constraints,num_entries,printlevel) end function free_loading_prob(problem::Ptr{Cvoid}) ccall((:free_loading_prob,CSDP.csdp),Nothing,(Ptr{Cvoid},),problem) @@ -299,13 +299,13 @@ function free_loaded_prob(problem::Ptr{Cvoid},X::blockmatrix,y::Ptr{Cdouble},Z:: end function setconstant(problem::Ptr{Cvoid}, mat::Integer, ent::Cdouble) - ccall((:setconstant,CSDP.csdp),Nothing,(Ptr{Cvoid},Cint,Cdouble),problem,mat,ent) + ccall((:setconstant,CSDP.csdp),Nothing,(Ptr{Cvoid},CSDP_INT,Cdouble),problem,mat,ent) end function addentry(problem::Ptr{Cvoid}, mat::Integer, blk::Integer, indexi::Integer, indexj::Integer, ent::Cdouble, allow_duplicates::Integer) - ccall((:addentry,CSDP.csdp),Cint,(Ptr{Cvoid},Cint,Cint,Cint,Cint,Cdouble,Cint),problem,mat,blk,indexi,indexj,ent,allow_duplicates) + ccall((:addentry,CSDP.csdp),CSDP_INT,(Ptr{Cvoid},CSDP_INT,CSDP_INT,CSDP_INT,CSDP_INT,Cdouble,CSDP_INT),problem,mat,blk,indexi,indexj,ent,allow_duplicates) end -function sdp(n::Cint, k::Cint, +function sdp(n::CSDP_INT, k::CSDP_INT, C::blockmatrix, a::Ptr{Cdouble}, constant_offset::Cdouble, constraints::Ptr{constraintmatrix}, byblocks::Ptr{Ptr{sparseblock}}, X::blockmatrix, y::Ptr{Cdouble}, Z::blockmatrix, @@ -313,7 +313,7 @@ function sdp(n::Cint, k::Cint, diagO::Ptr{Cdouble}, besty::Ptr{Cdouble}, O::Ptr{Cdouble}, rhs::Ptr{Cdouble}, dy::Ptr{Cdouble}, dy1::Ptr{Cdouble}, Fp::Ptr{Cdouble}, - printlevel::Cint, parameters::paramstruc) + printlevel::CSDP_INT, parameters::paramstruc) pobj = Ref{Cdouble}(0.0) dobj = Ref{Cdouble}(0.0) @@ -336,8 +336,8 @@ function sdp(n::Cint, k::Cint, sort_entries(k, C, constraints) - status = ccall((:sdp, CSDP.csdp), Cint, - (Cint, Cint, # n, k + status = ccall((:sdp, CSDP.csdp), CSDP_INT, + (CSDP_INT, CSDP_INT, # n, k blockmatrix, Ptr{Cdouble}, Cdouble, Ptr{constraintmatrix}, Ptr{Ptr{sparseblock}}, constraintmatrix, # byblocks, fill blockmatrix, Ptr{Cdouble}, blockmatrix, @@ -350,7 +350,7 @@ function sdp(n::Cint, k::Cint, Ptr{Cdouble}, # besty blockmatrix,blockmatrix, # bestz, Zi Ptr{Cdouble},Ptr{Cdouble},blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble}, - Cint,paramstruc), + CSDP_INT,paramstruc), n, k, C, a, constant_offset, constraints, byblocks, fill[], @@ -381,31 +381,31 @@ function sdp(n::Cint, k::Cint, return status, pobj[], dobj[] end -function loaded_sdp(problem::Ptr{Cvoid},constant_offset::Cdouble,pX::Ref{blockmatrix},py::Ref{Ptr{Cdouble}},pZ::Ref{blockmatrix},printlevel::Cint,parameters::paramstruc) +function loaded_sdp(problem::Ptr{Cvoid},constant_offset::Cdouble,pX::Ref{blockmatrix},py::Ref{Ptr{Cdouble}},pZ::Ref{blockmatrix},printlevel::CSDP_INT,parameters::paramstruc) pobj = Ref{Cdouble}(0.0) dobj = Ref{Cdouble}(0.0) - status = ccall((:loaded_sdp,CSDP.csdp),Cint, - (Ptr{Cvoid},Cdouble, Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{blockmatrix},Ref{Cdouble},Ref{Cdouble},Cint,paramstruc), + status = ccall((:loaded_sdp,CSDP.csdp),CSDP_INT, + (Ptr{Cvoid},Cdouble, Ref{blockmatrix},Ref{Ptr{Cdouble}},Ref{blockmatrix},Ref{Cdouble},Ref{Cdouble},CSDP_INT,paramstruc), problem, constant_offset,pX, py, pZ,pobj,dobj,printlevel,parameters) return status, pobj[], dobj[] end -function parametrized_sdp(n::Cint,k::Cint,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},constant_offset::Cdouble,pX::Ptr{blockmatrix},py::Ref{Ptr{Cdouble}},pZ::Ptr{blockmatrix},printlevel::Cint,parameters::paramstruc) +function parametrized_sdp(n::CSDP_INT,k::CSDP_INT,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},constant_offset::Cdouble,pX::Ptr{blockmatrix},py::Ref{Ptr{Cdouble}},pZ::Ptr{blockmatrix},printlevel::CSDP_INT,parameters::paramstruc) pobj = Ref{Cdouble}(0.0) dobj = Ref{Cdouble}(0.0) - status = ccall((:parametrized_sdp,CSDP.csdp),Cint,(Cint,Cint,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},Cdouble,Ptr{blockmatrix},Ref{Ptr{Cdouble}},Ptr{blockmatrix},Ref{Cdouble},Ref{Cdouble},Cint,paramstruc),n,k,C,a,constraints,constant_offset,pX,py,pZ,pobj,dobj,printlevel,parameters) + status = ccall((:parametrized_sdp,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},Cdouble,Ptr{blockmatrix},Ref{Ptr{Cdouble}},Ptr{blockmatrix},Ref{Cdouble},Ref{Cdouble},CSDP_INT,paramstruc),n,k,C,a,constraints,constant_offset,pX,py,pZ,pobj,dobj,printlevel,parameters) return status, pobj[], dobj[] end -function easy_sdp(n::Cint,k::Cint,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},constant_offset::Cdouble,pX::Ptr{blockmatrix},py::Ref{Ptr{Cdouble}},pZ::Ptr{blockmatrix}) +function easy_sdp(n::CSDP_INT,k::CSDP_INT,C::blockmatrix,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},constant_offset::Cdouble,pX::Ptr{blockmatrix},py::Ref{Ptr{Cdouble}},pZ::Ptr{blockmatrix}) pobj = Ref{Cdouble}(0.0) dobj = Ref{Cdouble}(0.0) - status = ccall((:easy_sdp,CSDP.csdp),Cint,(Cint,Cint,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},Cdouble,Ptr{blockmatrix},Ref{Ptr{Cdouble}},Ptr{blockmatrix},Ref{Cdouble},Ref{Cdouble}),n,k,C,a,constraints,constant_offset,pX,py,pZ,pobj,dobj) + status = ccall((:easy_sdp,CSDP.csdp),CSDP_INT,(CSDP_INT,CSDP_INT,blockmatrix,Ptr{Cdouble},Ptr{constraintmatrix},Cdouble,Ptr{blockmatrix},Ref{Ptr{Cdouble}},Ptr{blockmatrix},Ref{Cdouble},Ref{Cdouble}),n,k,C,a,constraints,constant_offset,pX,py,pZ,pobj,dobj) return status, pobj[], dobj[] end -function tweakgap(n::Cint,k::Cint,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},gap::Cdouble,Z::blockmatrix,dZ::blockmatrix,y::Ptr{Cdouble},dy::Ptr{Cdouble},work1::blockmatrix,work2::blockmatrix,work3::blockmatrix,work4::blockmatrix,workvec1::Ptr{Cdouble},workvec2::Ptr{Cdouble},workvec3::Ptr{Cdouble},workvec4::Ptr{Cdouble},printlevel::Cint) - ccall((:tweakgap,CSDP.csdp),Nothing,(Cint,Cint,Ptr{Cdouble},Ptr{constraintmatrix},Cdouble,blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},blockmatrix,blockmatrix,blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Cint),n,k,a,constraints,gap,Z,dZ,y,dy,work1,work2,work3,work4,workvec1,workvec2,workvec3,workvec4,printlevel) +function tweakgap(n::CSDP_INT,k::CSDP_INT,a::Ptr{Cdouble},constraints::Ptr{constraintmatrix},gap::Cdouble,Z::blockmatrix,dZ::blockmatrix,y::Ptr{Cdouble},dy::Ptr{Cdouble},work1::blockmatrix,work2::blockmatrix,work3::blockmatrix,work4::blockmatrix,workvec1::Ptr{Cdouble},workvec2::Ptr{Cdouble},workvec3::Ptr{Cdouble},workvec4::Ptr{Cdouble},printlevel::CSDP_INT) + ccall((:tweakgap,CSDP.csdp),Nothing,(CSDP_INT,CSDP_INT,Ptr{Cdouble},Ptr{constraintmatrix},Cdouble,blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},blockmatrix,blockmatrix,blockmatrix,blockmatrix,Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},CSDP_INT),n,k,a,constraints,gap,Z,dZ,y,dy,work1,work2,work3,work4,workvec1,workvec2,workvec3,workvec4,printlevel) end -function bisect_(n::Ptr{Cint},eps1::Ptr{Cdouble},d::Ptr{Cdouble},e::Ptr{Cdouble},e2::Ptr{Cdouble},lb::Ptr{Cdouble},ub::Ptr{Cdouble},mm::Ptr{Cint},m::Ptr{Cint},w::Ptr{Cdouble},ind::Ptr{Cint},ierr::Ptr{Cint},rv4::Ptr{Cdouble},rv5::Ptr{Cdouble}) - ccall((:bisect_,CSDP.csdp),Cint,(Ptr{Cint},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cint},Ptr{Cint},Ptr{Cdouble},Ptr{Cint},Ptr{Cint},Ptr{Cdouble},Ptr{Cdouble}),n,eps1,d,e,e2,lb,ub,mm,m,w,ind,ierr,rv4,rv5) +function bisect_(n::Ptr{CSDP_INT},eps1::Ptr{Cdouble},d::Ptr{Cdouble},e::Ptr{Cdouble},e2::Ptr{Cdouble},lb::Ptr{Cdouble},ub::Ptr{Cdouble},mm::Ptr{CSDP_INT},m::Ptr{CSDP_INT},w::Ptr{Cdouble},ind::Ptr{CSDP_INT},ierr::Ptr{CSDP_INT},rv4::Ptr{Cdouble},rv5::Ptr{Cdouble}) + ccall((:bisect_,CSDP.csdp),CSDP_INT,(Ptr{CSDP_INT},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{CSDP_INT},Ptr{CSDP_INT},Ptr{Cdouble},Ptr{CSDP_INT},Ptr{CSDP_INT},Ptr{Cdouble},Ptr{Cdouble}),n,eps1,d,e,e2,lb,ub,mm,m,w,ind,ierr,rv4,rv5) end diff --git a/src/declarations.jl b/src/declarations.jl index 06308df..f717d4e 100644 --- a/src/declarations.jl +++ b/src/declarations.jl @@ -4,7 +4,7 @@ struct LoadingProblem ptr::Ptr{Cvoid} end -function allocate_loading_prob(pC::Ref{blockmatrix}, block_dims::Vector{Cint}, num_constraints::Integer, num_entries::Matrix{Cint}, printlevel::Integer) +function allocate_loading_prob(pC::Ref{blockmatrix}, block_dims::Vector{CSDP_INT}, num_constraints::Integer, num_entries::Matrix{CSDP_INT}, printlevel::Integer) ptr = allocate_loading_prob(pC, fptr(block_dims), num_constraints, pointer(num_entries), printlevel) return LoadingProblem(ptr) end @@ -28,7 +28,7 @@ function loaded_initsoln(problem::LoadingProblem, num_constraints::Integer, X::R end function initsoln(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{constraintmatrix}) m = length(As) - X, y, Z = initsoln(Cint(size(C, 1)), Cint(m), C.csdp, fptr(b), fptr(As)) + X, y, Z = initsoln(CSDP_INT(size(C, 1)), CSDP_INT(m), C.csdp, fptr(b), fptr(As)) mywrap(X), mywrap(y, m), mywrap(Z) end function initsoln(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{ConstraintMatrix}) @@ -75,8 +75,8 @@ function sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{ConstraintMatrix}, X Zcsdp = Z.csdp Ascsdp = map(A->A.csdp, As) - n = Cint(size(C, 1)) - k = Cint(length(As)) + n = CSDP_INT(size(C, 1)) + k = CSDP_INT(length(As)) nd = sizeof(Cdouble) * (n+1) kd = sizeof(Cdouble) * (k+1) md = max(nd, kd) @@ -85,8 +85,8 @@ function sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{ConstraintMatrix}, X byblocks = setupAs!(As, C) - status, pobj, dobj = sdp(n, # n::Cint - k, # k::Cint + status, pobj, dobj = sdp(n, # n::CSDP_INT + k, # k::CSDP_INT C.csdp, # C::blockmatrix fptr(b), # a::Ptr{Cdouble} 0.0, # constant_offset::Cdouble @@ -110,7 +110,7 @@ function sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{ConstraintMatrix}, X pointer(Vector{Cdouble}(undef, kd)), # dy::Ptr{Cdouble} pointer(Vector{Cdouble}(undef, kd)), # dy1::Ptr{Cdouble} pointer(Vector{Cdouble}(undef, kd)), # Fp::Ptr{Cdouble} - Cint(printlevel), # printlevel::Cint + CSDP_INT(printlevel), # printlevel::CSDP_INT params) # parameters::paramstruc # I can even assert that they won't change @assert Xcsdp == X.csdp @@ -133,7 +133,7 @@ function loaded_sdp(problem::LoadingProblem, X::Ref{blockmatrix}, y::Vector{Cdou X, # pX::Ptr{blockmatrix} ycsdp, # py::Ptr{Cdouble} Z, # pZ::Ptr{blockmatrix} - Cint(printlevel), # printlevel::Cint + CSDP_INT(printlevel), # printlevel::CSDP_INT params) # parameters::paramstruc # I can even assert that they won't change @assert ycsdp[] == fptr(y) @@ -151,8 +151,8 @@ function parametrized_sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{Constra Ascsdp = map(A->A.csdp, As) status, pobj, dobj = parametrized_sdp( - Cint(size(C, 1)), # n::Cint - Cint(length(As)), # k::Cint + CSDP_INT(size(C, 1)), # n::CSDP_INT + CSDP_INT(length(As)), # k::CSDP_INT C.csdp, # C::blockmatrix fptr(b), # a::Ptr{Cdouble} fptr(Ascsdp), # constraints::Ptr{constraintmatrix} @@ -160,7 +160,7 @@ function parametrized_sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{Constra ptr(Xcsdp), # pX::Ptr{blockmatrix} ycsdp, # py::Ptr{Cdouble} ptr(Zcsdp), # pZ::Ptr{blockmatrix} - Cint(printlevel), # printlevel::Cint + CSDP_INT(printlevel), # printlevel::CSDP_INT params) # parameters::paramstruc # I can even assert that they won't change @assert Xcsdp == X.csdp @@ -176,8 +176,8 @@ function easy_sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{constraintmatri ycsdp = Ref{Ptr{Cdouble}}(fptr(y)) Zcsdp = Z.csdp - status, pobj, dobj = easy_sdp(Cint(size(C, 1)), # n::Cint - Cint(length(As)), # k::Cint + status, pobj, dobj = easy_sdp(CSDP_INT(size(C, 1)), # n::CSDP_INT + CSDP_INT(length(As)), # k::CSDP_INT C.csdp, # C::blockmatrix fptr(b), # a::Ptr{Cdouble} fptr(As), # constraints::Ptr{constraintmatrix} @@ -193,9 +193,9 @@ function easy_sdp(C::BlockMatrix, b::Vector{Cdouble}, As::Vector{constraintmatri end function write_prob(fname::String, C::BlockMatrix, b::Vector{Cdouble}, As::Vector{constraintmatrix}) - write_prob(fname, Cint(size(C, 1)), Cint(length(As)), C.csdp, fptr(b), fptr(As)) + write_prob(fname, CSDP_INT(size(C, 1)), CSDP_INT(length(As)), C.csdp, fptr(b), fptr(As)) end function write_sol(fname::String, X::BlockMatrix, y::Vector{Cdouble}, Z::BlockMatrix) - write_sol(fname, Cint(size(X, 1)), Cint(length(y)), X.csdp, fptr(y), Z.csdp) + write_sol(fname, CSDP_INT(size(X, 1)), CSDP_INT(length(y)), X.csdp, fptr(y), Z.csdp) end