JuliaSmoothOptimizers / PartitionedVectors.jl

Other
8 stars 1 forks source link

Allocation in `solve!(::CgSolver)` #21

Closed paraynaud closed 1 year ago

paraynaud commented 1 year ago

To avoid duplication one can write:

# y .= x .* s .+ y .* t
function axpby!(
  s::Y1,
  x::PartitionedVector{T},
  t::Y2,
  y::PartitionedVector{T},
  ::VB, # Val{true} | Val{False}
  ::VB, # Val{true} | Val{False}
) where {T <: Number, Y1 <: Number, Y2 <: Number, B, VB<:Val{B}}
  N = x.epv.N
  for i in 1:N
    yi = y[i].vec
    xi = x[i].vec
    axpby!(s, xi, t, yi)
  end
  return y
end

But it breaks the new tests about allocation-free methods (from 0 to 16 bytes allocated).

dpo commented 1 year ago

Where are the allocations in the code above?

paraynaud commented 1 year ago

I don't know...

Maybe the allocations are due to VB which may be set dynamically to Val{true} or Val{false}. It is just a guess.

dpo commented 1 year ago

https://www.youtube.com/watch?v=BFvpwC8hEWQ

paraynaud commented 1 year ago

22