Skip to content

Commit 60203f0

Browse files
authored
Remove all allocations (#449)
* Remove all allocations * debug allocations * Update allocation tests * Remove another hidden allocation
1 parent 00c9986 commit 60203f0

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

src/CUTEst.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using JSON
1212
import Libdl.dlsym
1313
import REPL.TerminalMenus
1414
import Base.format_bytes
15+
import Base.RefValue
1516
import Printf.@sprintf
1617
import DataStructures: OrderedDict
1718

src/julia_interface.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,14 @@ function NLPModels.jac_nln_structure!(
324324
) where {T}
325325
@lencheck nlp.meta.nln_nnzj rows cols
326326
k = 1
327-
for i in findall(j -> j in nlp.meta.nln, nlp.jrows)
328-
rows[k] = nlp.jrows[i] - count(x < nlp.jrows[i] for x in nlp.meta.lin)
329-
cols[k] = nlp.jcols[i]
330-
k += 1
327+
for index in eachindex(nlp.jrows)
328+
jr = nlp.jrows[index]
329+
if jr in nlp.meta.nln
330+
offset = count(x < nlp.jrows[index] for x in nlp.meta.lin)
331+
rows[k] = jr - offset
332+
cols[k] = nlp.jcols[index]
333+
k += 1
334+
end
331335
end
332336
return rows, cols
333337
end
@@ -759,15 +763,14 @@ function NLPModels.jth_hess_coord!(
759763
@rangecheck 1 nlp.meta.ncon j
760764
ref_j = nlp.index
761765
ref_j[] = j
762-
nnzh_output = Ref{Cint}()
763766
cish(
764767
T,
765768
nlp.libsif,
766769
nlp.status,
767770
nlp.nvar,
768771
x,
769772
ref_j,
770-
nnzh_output,
773+
nlp.nnzh_jth,
771774
nlp.nnzh,
772775
vals,
773776
nlp.hcols,

src/model.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ mutable struct CUTEstModel{T} <: AbstractNLPModel{T, Vector{T}}
1919
Jvar::Vector{Cint}
2020

2121
libsif::Ptr{Cvoid}
22-
funit::Ref{Cint}
23-
index::Ref{Cint}
24-
nvar::Ref{Cint}
25-
ncon::Ref{Cint}
26-
nnzj::Ref{Cint}
27-
nnzh::Ref{Cint}
28-
f::Ref{T}
29-
status::Ref{Cint}
22+
funit::RefValue{Cint}
23+
index::RefValue{Cint}
24+
nvar::RefValue{Cint}
25+
ncon::RefValue{Cint}
26+
nnzj::RefValue{Cint}
27+
nnzh::RefValue{Cint}
28+
nnzh_jth::RefValue{Cint}
29+
f::RefValue{T}
30+
status::RefValue{Cint}
3031
end
3132

3233
"""
@@ -326,6 +327,7 @@ function CUTEstModel{T}(
326327
Ref{Cint}(ncon),
327328
Ref{Cint}(nnzj),
328329
Ref{Cint}(nnzh),
330+
Ref{Cint}(),
329331
Ref{T}(),
330332
status,
331333
)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ include("test_core.jl")
6060
include("test_julia.jl")
6161
include("coverage.jl")
6262
include("multiple_precision.jl")
63+
include("test_allocations.jl")
6364

6465
for problem in problems
6566
for T in (Float32, Float64, Float128)

test/test_allocations.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# using CUTEst, NLPModelsTest, NLPModels, Quadmath
2+
3+
@testset "allocations -- $pb" for pb in ("BROWNDEN", "HS5", "HS6", "HS10", "HS11", "HS13", "HS14")
4+
@testset "precision -- $T" for T in (Float32, Float64, Float128)
5+
(T == Float128) && (Sys.ARCH == :aarch64) && Sys.islinux() && continue
6+
nlp = CUTEstModel{T}(pb)
7+
NLPModelsTest.test_zero_allocations(nlp; linear_api=true, exclude=[jac_op])
8+
# mems = NLPModelsTest.test_allocs_nlpmodels(nlp; linear_api=true, exclude=[jac_op])
9+
# display(mems)
10+
finalize(nlp)
11+
end
12+
end

0 commit comments

Comments
 (0)