Skip to content

Commit

Permalink
Remove automatic initialization
Browse files Browse the repository at this point in the history
This just strikes me as a bad design decision.
  • Loading branch information
Jeremy E Kozdon committed Jul 7, 2021
1 parent 456e964 commit daa9c46
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ksp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LinearAlgebra.adjoint(ksp) = LinearAlgebra.Adjoint(ksp)
@for_libpetsc begin

function KSP{$PetscScalar}(comm::MPI.Comm; kwargs...)
initialize($PetscScalar)
@assert initialized($PetscScalar)
opts = Options{$PetscScalar}(kwargs...)
ksp = KSP{$PetscScalar}(C_NULL, comm, nothing, nothing, opts)
@chk ccall((:KSPCreate, $libpetsc), PetscErrorCode, (MPI.MPI_Comm, Ptr{CKSP}), comm, ksp)
Expand Down
4 changes: 2 additions & 2 deletions src/mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end

@for_libpetsc begin
function MatSeqAIJ{$PetscScalar}(m::Integer, n::Integer, nnz::Vector{$PetscInt})
initialize($PetscScalar)
@assert initialized($PetscScalar)
comm = MPI.COMM_SELF
mat = MatSeqAIJ{$PetscScalar}(C_NULL, comm)
@chk ccall((:MatCreateSeqAIJ, $libpetsc), PetscErrorCode,
Expand All @@ -50,7 +50,7 @@ end
return mat
end
function MatSeqDense(A::Matrix{$PetscScalar})
initialize($PetscScalar)
@assert initialized($PetscScalar)
comm = MPI.COMM_SELF
mat = MatSeqDense(C_NULL, comm, A)
@chk ccall((:MatCreateSeqDense, $libpetsc), PetscErrorCode,
Expand Down
2 changes: 1 addition & 1 deletion src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ scalartype(::Options{T}) where {T} = T

@for_libpetsc begin
function Options{$PetscScalar}()
initialize($PetscScalar)
@assert initialized($PetscScalar)
opts = Options{$PetscScalar}(C_NULL)
@chk ccall((:PetscOptionsCreate, $libpetsc), PetscErrorCode, (Ptr{CPetscOptions},), opts)
finalizer(destroy, opts)
Expand Down
4 changes: 2 additions & 2 deletions src/snes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end
@for_libpetsc begin

function SNES{$PetscScalar}(comm::MPI.Comm; kwargs...)
initialize($PetscScalar)
@assert initialized($PetscScalar)
opts = Options{$PetscScalar}(kwargs...)
snes = SNES{$PetscScalar}(C_NULL, comm, opts, nothing, nothing, nothing, nothing, nothing)
@chk ccall((:SNESCreate, $libpetsc), PetscErrorCode, (MPI.MPI_Comm, Ptr{CSNES}), comm, snes)
Expand Down Expand Up @@ -157,4 +157,4 @@ end

end

solve!(x::AbstractVector{T}, snes::SNES{T}) where {T} = parent(solve!(AbstractVec(x), snes))
solve!(x::AbstractVector{T}, snes::SNES{T}) where {T} = parent(solve!(AbstractVec(x), snes))
2 changes: 1 addition & 1 deletion src/vec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Base.parent(v::AbstractVec) = v.array

@for_libpetsc begin
function VecSeq(comm::MPI.Comm, X::Vector{$PetscScalar}; blocksize=1)
initialize($PetscScalar)
@assert initialized($PetscScalar)
v = VecSeq(C_NULL, comm, X)
@chk ccall((:VecCreateSeqWithArray, $libpetsc), PetscErrorCode,
(MPI.MPI_Comm, $PetscInt, $PetscInt, Ptr{$PetscScalar}, Ptr{CVec}),
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Test
using PETSc, MPI, LinearAlgebra, SparseArrays
PETSc.initialize()

@testset "Tests" begin
m,n = 20,20
Expand Down

0 comments on commit daa9c46

Please sign in to comment.