Skip to content

Instantly share code, notes, and snippets.

@abelsiqueira
Created November 5, 2015 18:57
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/754e0484d9d11afad6a8 to your computer and use it in GitHub Desktop.
Save abelsiqueira/754e0484d9d11afad6a8 to your computer and use it in GitHub Desktop.
Examples showing that @eval is bad
include("src/CUTEst.jl")
using CUTEst
function test(nlp; N = 100)
n = Cint[nlp.meta.nvar]
m = Cint[nlp.meta.ncon]
x = zeros(nlp.meta.nvar)
c = zeros(nlp.meta.ncon)
io_err = Cint[0]
for i = 1:N
f = [0.0]
ccall((:cutest_cfn_, "libHS35.so"), 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")
test(nlp, N=1)
test(nlp, N=100000)
#include("src/CUTEst.jl")
#using CUTEst
io_err = Cint[0]
function test(nvar; N = 100)
n = Cint[nvar]
x = rand(nvar)
for i = 1:N
f = [0.0]
ccall((:cutest_ufn_, "libROSENBR.so"), Void,
(Ptr{Int32}, Ptr{Int32}, Ptr{Float64}, Ptr{Float64}),
io_err, n, x, f)
end
end
# Suppose libROSENBR.so and auxiliary .f files are available
funit = Int32(42)
outsdif = "OUTSDIF.d"
nvar = Cint[0]
ncon = Cint[0]
ccall((:fortran_open_, "libROSENBR.so"), Void,
(Ptr{Int32}, Ptr{UInt8}, Ptr{Int32}),
&funit, outsdif, io_err)
ccall((:cutest_cdimen_, "libROSENBR.so"), Void,
(Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}),
io_err, &funit, nvar, ncon)
x = Array(Float64, nvar[1])
bl = Array(Float64, nvar[1])
bu = Array(Float64, nvar[1])
ccall((:cutest_usetup_, "libROSENBR.so"), Void,
(Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{Float64},
Ptr{Float64}, Ptr{Float64}),
io_err, &funit, Cint[5], Cint[6], nvar, x, bl, bu)
ccall((:fortran_close_, "libROSENBR.so"), Void,
(Ptr{Int32}, Ptr{Int32}), &funit, io_err)
test(nvar[1], N=1)
test(nvar[1], N=100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment