Skip to content

Instantly share code, notes, and snippets.

@abelsiqueira
Created November 5, 2015 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsiqueira/d4ca585c62204516bf37 to your computer and use it in GitHub Desktop.
Save abelsiqueira/d4ca585c62204516bf37 to your computer and use it in GitHub Desktop.
include("src/CUTEst.jl")
using CUTEst
macro dlsym(func, lib)
z, zlocal = gensym(string(func)), gensym()
eval(current_module(), :(global $z = C_NULL))
z = esc(z)
quote
let $zlocal::Ptr{Void} = $z::Ptr{Void}
if $zlocal == C_NULL
$zlocal = Libdl.dlsym($(esc(lib))::Ptr{Void}, $(esc(func)))
global $z = $zlocal
end
$zlocal
end
end
end
function test(nlp; N = 100)
x = zeros(nlp.meta.nvar)
c = zeros(nlp.meta.ncon)
for i = 1:N
n = Cint[nlp.meta.nvar]
m = Cint[nlp.meta.ncon]
io_err = Cint[0]
f = [0.0]
ccall(@dlsym(:cutest_cfn_,mylib), Void,
(Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Float64}, Ptr{Float64},
Ptr{Float64}),
io_err, n, m, x, f, c)
end
end
nlp = CUTEstModel("HS35")
mylib = Libdl.dlopen(nlp.libname)
test(nlp, N=1)
test(nlp, N=100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment