Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make library relocatable #362

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
MadNLPMOI = "MathOptInterface"

[compat]
LDLFactorizations = "0.10"
MINLPTests = "~0.5"
MadNLPTests = "0.5"
MathOptInterface = "1"
NLPModels = "~0.17.2, 0.18, 0.19, 0.20, 0.21"
SolverCore = "~0.3"
LDLFactorizations = "0.10"
julia = "1.9"

[extras]
Expand Down
6 changes: 3 additions & 3 deletions lib/MadNLPMumps/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ uuid = "3b83494e-c0a4-4895-918b-9157a7a085a1"
version = "0.4.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MUMPS_seq_jll = "d7ed1dd3-d0ae-5e8e-bfb4-87a502085b8d"
OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2"
MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2"

[compat]
MUMPS_seq_jll = "~5.3, ~500.600"
OpenBLAS32_jll = "0.3"
MadNLP = "0.5, 0.6, 0.7, 0.8"
MadNLPTests = "0.5"
OpenBLAS32_jll = "0.3"
julia = "1.6"

[extras]
Expand Down
38 changes: 19 additions & 19 deletions lib/MadNLPMumps/src/MadNLPMumps.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module MadNLPMumps

import MUMPS_seq_jll
using MUMPS_seq_jll
import MadNLP:
MadNLP, parsefile, dlopen,
MadNLP, parsefile,
@kwdef, MadNLPLogger, @debug, @warn, @error,
SparseMatrixCSC, SubVector,
SymbolicException,FactorizationException,SolveException,InertiaException,
Expand All @@ -19,7 +19,7 @@ function __init__()
end
end

const version = parsefile(joinpath(dirname(pathof(MUMPS_seq_jll)),"..","Project.toml"))["version"]
version = string(pkgversion(@__MODULE__))

setindex(tup,a,n) = (tup[1:n-1]...,a,tup[n+1:end]...)
tzeros(n) = tuple((0 for i=1:n)...)
Expand Down Expand Up @@ -151,22 +151,22 @@ mutable struct MumpsSolver{T} <: AbstractLinearSolver{T}
logger::MadNLPLogger
end

for (lib,fname,typ) in [(MUMPS_seq_jll.libdmumps,:dmumps_c,Float64), (MUMPS_seq_jll.libsmumps, :smumps_c,Float32)]
@eval begin
dmumps_c(mumps_struc::Struc{$typ})=ccall(
($(string(fname)),$lib),
Cvoid,
(Ref{Struc},),
mumps_struc)
# this is necessary, when multi-threaded calls are made with Mumps, not to clash with MPI
mumps_lock = Threads.SpinLock()

function locked_mumps_c(mumps_struc::Struc{Float32})
lock(mumps_lock)
try
@ccall libsmumps.smumps_c(mumps_struc::Ref{Struc{Float32}})::Cvoid
finally
unlock(mumps_lock)
end
end

# this is necessary, when multi-threaded calls are made with Mumps, not to clash with MPI
mumps_lock = Threads.SpinLock()
function locked_dmumps_c(mumps_struc::Struc)
function locked_mumps_c(mumps_struc::Struc{Float64})
lock(mumps_lock)
try
dmumps_c(mumps_struc)
@ccall libdmumps.dmumps_c(mumps_struc::Ref{Struc{Float64}})::Cvoid
finally
unlock(mumps_lock)
end
Expand All @@ -188,7 +188,7 @@ function MumpsSolver(csc::SparseMatrixCSC{T,Int32};
mumps_struc.job = -1
mumps_struc.comm_fortran = -987654 # MPI.COMM_WORLD.val

locked_dmumps_c(mumps_struc)
locked_mumps_c(mumps_struc)
mumps_struc.n = csc.n;
mumps_struc.nz= nnz(csc);
mumps_struc.a = pointer(csc.nzval)
Expand All @@ -215,7 +215,7 @@ function MumpsSolver(csc::SparseMatrixCSC{T,Int32};
a = copy(csc.nzval) # would there be a better way?
csc.nzval.=1

locked_dmumps_c(mumps_struc);
locked_mumps_c(mumps_struc);
mumps_struc.info[1] < 0 && throw(SymbolicException())

csc.nzval.=a
Expand All @@ -231,7 +231,7 @@ function factorize!(M::MumpsSolver)
M.mumps_struc.job = 2;
cnt = 0
while true
locked_dmumps_c(M.mumps_struc)
locked_mumps_c(M.mumps_struc)
if M.mumps_struc.info[1] in [-8,-9]
cnt >= 10 && throw(FactorizationException())
M.mumps_struc.icntl = setindex(M.mumps_struc.icntl,M.mumps_struc.icntl[14]*2.,14)
Expand All @@ -252,7 +252,7 @@ function solve!(M::MumpsSolver{T},rhs::Vector{T}) where T
M.is_singular && return rhs
M.mumps_struc.rhs = pointer(rhs)
M.mumps_struc.job = 3
locked_dmumps_c(M.mumps_struc)
locked_mumps_c(M.mumps_struc)
M.mumps_struc.info[1] < 0 && throw(SolveException())
return rhs
end
Expand All @@ -277,7 +277,7 @@ end

function finalize(M::MumpsSolver)
M.mumps_struc.job = -2
locked_dmumps_c(M.mumps_struc);
locked_mumps_c(M.mumps_struc);
end

introduce(::MumpsSolver)="mumps"
Expand Down
2 changes: 1 addition & 1 deletion src/MadNLP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export MadNLPSolver, MadNLPOptions, UmfpackSolver, LDLSolver, CHOLMODSolver, Lap
import LDLFactorizations

# Version info
version() = parsefile(joinpath(@__DIR__,"..","Project.toml"))["version"]
version() = string(pkgversion(@__MODULE__))
introduce() = "MadNLP version v$(version())"

include("enums.jl")
Expand Down
Loading