Skip to content

Commit

Permalink
alignment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillis committed Jul 15, 2024
1 parent a778db6 commit 12c301f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ primal_feas::Vector{Float64} = []
dual_feas::Vector{Float64} = []


cases::Vector{Tuple{Int,Int,Int}} = [(0,3,10)]
cases::Vector{Tuple{Int,Int,Int}} = [(0,0,10)]
# cases::Vector{Tuple{Int,Int,Int}} = [(0,3,10),(2,2,1000),(1,1,1000),(0,0,1000)]
for (lin_solver_id,print_level, max_iters) in cases
nlp_interface = MadnlpCInterface(
Expand Down
30 changes: 26 additions & 4 deletions src/MadNLP_C.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ mutable struct MadnlpCSolver
out_c::MadnlpCNumericOut
stats_c::MadnlpCStats
in::MadnlpCNumericIn{Vector{Float64}}

nzj_i::Array{Int64}
nzj_j::Array{Int64}
nzh_i::Array{Int64}
nzh_j::Array{Int64}
MadnlpCSolver() = new()
end

Expand Down Expand Up @@ -332,6 +337,22 @@ Base.@ccallable function madnlp_c_create(nlp_interface::Ptr{MadnlpCInterface})::
solver.out_c = MadnlpCNumericOut()
solver.stats_c = MadnlpCStats()

# nzj_i may not be properly aligned, so copying is neededs
solver.nzj_i = Array{Int64}(undef, interf.nnzj)
solver.nzj_j = Array{Int64}(undef, interf.nnzj)
solver.nzh_i = Array{Int64}(undef, interf.nnzh)
solver.nzh_j = Array{Int64}(undef, interf.nnzh)

stuff = Base.unsafe_convert(Ptr{Int64}, solver.nzj_i)
@info "solver.nzj_i" stuff
stuff2 = interf.nzj_i
@info "interf.nzj_i" stuff2

unsafe_copyto!(Base.unsafe_convert(Ptr{Int64}, solver.nzj_i), interf.nzj_i, interf.nnzj)
unsafe_copyto!(Base.unsafe_convert(Ptr{Int64}, solver.nzj_j), interf.nzj_j, interf.nnzj)
unsafe_copyto!(Base.unsafe_convert(Ptr{Int64}, solver.nzh_i), interf.nzh_i, interf.nnzh)
unsafe_copyto!(Base.unsafe_convert(Ptr{Int64}, solver.nzh_j), interf.nzh_j, interf.nnzh)

# Copy the solver object to the allocated memory
unsafe_store!(solver_ptr, solver)

Expand Down Expand Up @@ -449,10 +470,11 @@ Base.@ccallable function madnlp_c_solve(s::Ptr{MadnlpCSolver})::Cint

GPU_DEVICE::Bool = false

nzj_i = unsafe_wrap(Array, nlp_interface.nzj_i, (nlp_interface.nnzj,))
nzj_j = unsafe_wrap(Array, nlp_interface.nzj_j, (nlp_interface.nnzj,))
nzh_i = unsafe_wrap(Array, nlp_interface.nzh_i, (nlp_interface.nnzh,))
nzh_j = unsafe_wrap(Array, nlp_interface.nzh_j, (nlp_interface.nnzh,))

nzj_i = solver.nzj_i
nzj_j = solver.nzj_j
nzh_i = solver.nzh_i
nzh_j = solver.nzh_j

# @info "nzj_i" nzh_j
# @info "length" nlp_interface.nnzj
Expand Down

0 comments on commit 12c301f

Please sign in to comment.