Skip to content

Commit

Permalink
removed gc_haven, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wrs28 committed May 31, 2019
1 parent d9ad9e6 commit 79f98b4
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 267 deletions.
15 changes: 12 additions & 3 deletions src/MUMPS3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ SparseArrays

function __init__()
if haskey(ENV,"MUMPS_PREFIX")
global MUMPS_LIB = joinpath(ENV["MUMPS_PREFIX"],"lib/libmumps_simple.dylib")
global MUMPS_LIB_S = joinpath(ENV["MUMPS_PREFIX"],"lib/libsmumps.dylib")
global MUMPS_LIB_D = joinpath(ENV["MUMPS_PREFIX"],"lib/libdmumps.dylib")
global MUMPS_LIB_C = joinpath(ENV["MUMPS_PREFIX"],"lib/libcmumps.dylib")
global MUMPS_LIB_Z = joinpath(ENV["MUMPS_PREFIX"],"lib/libzmumps.dylib")
else
global MUMPS_LIB = "/usr/local/opt/brewsci-mumps/lib/libmumps_simple.dylib"
global MUMPS_LIB_S = "/usr/local/opt/brewsci-mumps/lib/libsmumps.dylib"
global MUMPS_LIB_D = "/usr/local/opt/brewsci-mumps/lib/libdmumps.dylib"
global MUMPS_LIB_C = "/usr/local/opt/brewsci-mumps/lib/libcmumps.dylib"
global MUMPS_LIB_Z = "/usr/local/opt/brewsci-mumps/lib/libzmumps.dylib"
end
global LIB = dlopen(MUMPS_LIB)
global LIB_S = dlopen(MUMPS_LIB_S)
global LIB_D = dlopen(MUMPS_LIB_D)
global LIB_C = dlopen(MUMPS_LIB_C)
global LIB_Z = dlopen(MUMPS_LIB_Z)
end

include("mumps_types.jl")
Expand Down
70 changes: 35 additions & 35 deletions src/convenience_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ See also: [`mumps_solve`](@ref), [`get_sol!`](@ref), [`get_sol`](@ref)
function mumps_solve!(mumps::Mumps)
@assert has_matrix(mumps) "matrix not yet provided to mumps object"
@assert has_rhs(mumps) "rhs not yet provided to mumps object"
if mumps.mumpsc.job [2,4] # if already factored, just solve
mumps.mumpsc.job = 3
elseif mumps.mumpsc.job [1] # if analyzed only, factorize and solve
mumps.mumpsc.job=5
elseif mumps.mumpsc.job [3,5,6] # is solved already, retrieve solution
if mumps.job [2,4] # if already factored, just solve
mumps.job = 3
elseif mumps.job [1] # if analyzed only, factorize and solve
mumps.job=5
elseif mumps.job [3,5,6] # is solved already, retrieve solution
return nothing
else # else analyze, factor, solve
mumps.mumpsc.job=6
mumps.job=6
end
invoke_mumps!(mumps)
return nothing
Expand All @@ -106,13 +106,13 @@ function mumps_solve!(x::AbstractArray,A::AbstractArray,rhs::AbstractArray; kwar
end
function mumps_solve!(x::AbstractArray,mumps::Mumps,rhs::AbstractArray)
provide_rhs!(mumps,rhs)
if mumps.mumpsc.job [2,4] # if already factored, just solve
elseif mumps.mumpsc.job [1] # if analyzed only, factorize and solve
mumps.mumpsc.job=5
elseif mumps.mumpsc.job [3,5,6] # is solved already, reset to solve only
mumps.mumpsc.job=2
if mumps.job [2,4] # if already factored, just solve
elseif mumps.job [1] # if analyzed only, factorize and solve
mumps.job=5
elseif mumps.job [3,5,6] # is solved already, reset to solve only
mumps.job=2
else # else analyze, factor, solve
mumps.mumpsc.job=6
mumps.job=6
end
mumps_solve!(x,mumps)
end
Expand All @@ -128,7 +128,7 @@ If only input is `mumps` must also have been provided `y`.
See also: [`mumps_solve!`](@ref)
"""
function mumps_solve(mumps::Mumps)
if mumps.mumpsc.job [3,5,6]
if mumps.job [3,5,6]
x = get_sol(mumps)
else
x = get_rhs(mumps)
Expand Down Expand Up @@ -160,13 +160,13 @@ See also: [`mumps_factorize`](@ref)
"""
function mumps_factorize!(mumps::Mumps)
@assert has_matrix(mumps) "matrix not yet provided to mumps object"
if mumps.mumpsc.job [2,3,4,5,6] # already factored
if mumps.job [2,3,4,5,6] # already factored
@warn "already factored"
return nothing
elseif mumps.mumpsc.job [1] # if analyzed only, factorize
mumps.mumpsc.job=2
elseif mumps.job [1] # if analyzed only, factorize
mumps.job=2
else # else analyze, factor
mumps.mumpsc.job=4
mumps.job=4
end
invoke_mumps!(mumps)
end
Expand Down Expand Up @@ -205,12 +205,12 @@ See also: [`mumps_det`](@ref)
"""
function mumps_det!(mumps::Mumps; discard=true)
@assert has_matrix(mumps) "matrix not yet provided to mumps object"
if has_det(mumps) && mumps.mumpsc.job>1
if has_det(mumps) && mumps.job>1
return nothing
end
set_icntl!(mumps,31,Int(discard))
set_icntl!(mumps,33,1)
mumps.mumpsc.job>0 ? mumps.mumpsc.job=1 : nothing
mumps.job>0 ? mumps.job=1 : nothing
mumps_factorize!(mumps)
end
"""
Expand Down Expand Up @@ -242,14 +242,14 @@ See also: [`mumps_schur_complement`](@ref), [`get_schur_complement!`](@ref), [`g
function mumps_schur_complement!(mumps::Mumps, schur_inds::AbstractArray{Int,1})
@assert has_matrix(mumps) "matrix not yet provided to mumps object"
set_schur_centralized_by_column!(mumps, schur_inds)
if mumps.mumpsc.job [1] # if analyzed only, factorize
mumps.mumpsc.job=2
if mumps.job [1] # if analyzed only, factorize
mumps.job=2
else # else analyze, factor
mumps.mumpsc.job=4
mumps.job=4
end
invoke_mumps!(mumps)
end
mumps_schur_complement!(mumps::Mumps, x::SparseMatrixCSC) = mumps_schur_complement!(mumps,unique!(sort!(x.rowval)))
mumps_schur_complement!(mumps::Mumps, x::SparseMatrixCSC) = mumps_schur_complement!(mumps,unique!(sort(x.rowval)))
mumps_schur_complement!(mumps::Mumps, x::SparseVector) = mumps_schur_complement!(mumps,x.nzind)
"""
mumps_schur_complement(A,schur_inds) -> S
Expand Down Expand Up @@ -287,12 +287,12 @@ function mumps_select_inv!(x::AbstractSparseArray,mumps::Mumps)
set_icntl!(mumps,30,1)
set_icntl!(mumps,20,3)
provide_rhs!(mumps,x)
if mumps.mumpsc.job [2,4] # if already factored, just solve
mumps.mumpsc.job = 3
elseif mumps.mumpsc.job [1] # if analyzed only, factorize and solve
mumps.mumpsc.job=5
if mumps.job [2,4] # if already factored, just solve
mumps.job = 3
elseif mumps.job [1] # if analyzed only, factorize and solve
mumps.job=5
else # else analyze, factor, solve
mumps.mumpsc.job=6
mumps.job=6
end
invoke_mumps!(mumps)
get_rhs!(x,mumps)
Expand Down Expand Up @@ -338,7 +338,7 @@ See also: [`finalize`](@ref)
function initialize!(mumps::Mumps)
suppress_display!(mumps)
mumps.finalized=false
mumps.mumpsc.job=-1
mumps.job=-1
invoke_mumps!(mumps)
end

Expand All @@ -357,39 +357,39 @@ function finalize!(mumps::Mumps)
end
function finalize_unsafe!(mumps::Mumps)
mumps.finalized=true
mumps.mumpsc.job=-2
mumps.job=-2
invoke_mumps_unsafe!(mumps)
end


function Base.:\(mumps::Mumps,y)
suppress_display!(mumps)
if mumps.mumpsc.job < 2
if mumps.job < 2
mumps_factorize!(mumps)
end
x = mumps_solve(mumps,y)
return x
end
function LinearAlgebra.ldiv!(mumps::Mumps,y)
suppress_display!(mumps)
if mumps.mumpsc.job < 2
if mumps.job < 2
mumps_factorize!(mumps)
else
mumps.mumpsc.job=2
mumps.job=2
end
provide_rhs!(mumps,y)
mumps_solve!(y,mumps)
end
function LinearAlgebra.ldiv!(x,mumps::Mumps,y)
suppress_display!(mumps)
if mumps.mumpsc.job < 2
if mumps.job < 2
mumps_factorize!(mumps)
end
mumps_solve!(x,mumps,y)
end
function LinearAlgebra.inv(mumps::Mumps)
suppress_display!(mumps)
y = sparse(1:mumps.mumpsc.n,1:mumps.mumpsc.n,1:mumps.mumpsc.n,mumps.mumpsc.n,mumps.mumpsc.n)
y = sparse(1:mumps.n,1:mumps.n,1:mumps.n,mumps.n,mumps.n)
mumps_select_inv!(y,mumps)
finalize!(mumps)
return y
Expand Down
8 changes: 4 additions & 4 deletions src/icntl_alibis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ICNTL_DEFAULT = (6, 0, 6, 2, 0, 7, 7, 77, 1, 0, 0, 1, 0, 20, 0, 0, 0, 0, 0
reset ICNTL to its default
"""
function default_icntl!(mumps::Mumps)
mumps.mumpsc.icntl = ICNTL_DEFAULT
mumps.icntl = ICNTL_DEFAULT
return nothing
end

Expand All @@ -24,16 +24,16 @@ set_info_stream!(mumps::Mumps,i) = set_icntl!(mumps,3,i; displaylevel=0)
set_print_level!(mumps::Mumps,i) = set_icntl!(mumps,4,i; displaylevel=0)

suppress_printing!(mumps::Mumps) = set_print_level!(mumps,1)
toggle_printing!(mumps::Mumps) = set_print_level!(mumps,mod1(mumps.mumpsc.icntl[4]+1,2))
toggle_printing!(mumps::Mumps) = set_print_level!(mumps,mod1(mumps.icntl[4]+1,2))
suppress_display! = suppress_printing!
toggle_display! = toggle_printing!

sparse_matrix!(mumps::Mumps) = set_icntl!(mumps,5,0; displaylevel=0)
dense_matrix!(mumps::Mumps) = set_icntl!(mumps,5,1; displaylevel=0)

LinearAlgebra.transpose!(mumps::Mumps) = set_icntl!(mumps,9,mod(mumps.mumpsc.icntl[9]+1,2); displaylevel=0)
LinearAlgebra.transpose!(mumps::Mumps) = set_icntl!(mumps,9,mod(mumps.icntl[9]+1,2); displaylevel=0)

sparse_rhs!(mumps::Mumps) = set_icntl!(mumps, 20, 1; displaylevel=0)
dense_rhs!(mumps::Mumps) = set_icntl!(mumps, 20, 0; displaylevel=0)

toggle_null_pivot!(mumps::Mumps) = set_icntl!(mumps,24,mod(mumps.mumpsc.icntl[24]+1,2); displaylevel=0)
toggle_null_pivot!(mumps::Mumps) = set_icntl!(mumps,24,mod(mumps.icntl[24]+1,2); displaylevel=0)
Loading

0 comments on commit 79f98b4

Please sign in to comment.