Allocation-free trunk #63
Replies: 3 comments 9 replies
-
Iteration profile for Time profile for |
Beta Was this translation helpful? Give feedback.
-
Do you mean that this line allocates? |
Beta Was this translation helpful? Give feedback.
-
After 30min, I questionned the scope of n = 100
x = rand(n)
# equal to default arwhead
function my_arwhead1(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
n < 2 && @warn("arwhead: number of variables must be ≥ 2")
n = max(2, n)
function f(x)
n = length(x)
return sum((x[i]^2 + x[n]^2)^2 - 4 * x[i] + 3 for i = 1:(n - 1))
end
x0 = ones(T, n)
return ADNLPModels.ADNLPModel(f, x0, name = "arwhead"; kwargs...)
end
# replacing n by _n in f
function my_arwhead2(; n::Int = default_nvar, type::Val{T} = Val(Float64), kwargs...) where {T}
n < 2 && @warn("arwhead: number of variables must be ≥ 2")
n = max(2, n)
function f(x)
_n = length(x)
return sum((x[i]^2 + x[_n]^2)^2 - 4 * x[i] + 3 for i = 1:(_n - 1))
end
x0 = ones(T, n)
return ADNLPModels.ADNLPModel(f, x0, name = "arwhead"; kwargs...)
end
adnlp1 = my_arwhead1(;n)
adnlp2 = my_arwhead2(;n)
@benchmark NLPModels.obj(adnlp1, x) # Memory estimate: 14.02 KiB, allocs estimate: 893.
@benchmark NLPModels.obj(adnlp2, x) # Memory estimate: 16 bytes, allocs estimate: 1. I think that solves our issue. |
Beta Was this translation helpful? Give feedback.
-
@dpo, here are the results related to PartitionedVector PartitiallyseparableNLPModels PR.
It shows allocations during
solve!(::TrunkSolver)
.I compared different kind of NLPModels on
arwhead
a very partially-separable problem.I used PProf to check where the last allocations were, and it comes from the objective evaluation, which is the same as the
obj(adnlp)
.Overall the results are great.
The last issue may be the performance of algorithms used to perform partial separability detection, and
will count the partial separability detection in
bmark_solver
.I am working on it.
After the [email protected] release, I will push the changes on the PR mentioned at the start.
PS: @tmigot, it might interest you
Beta Was this translation helpful? Give feedback.
All reactions