diff --git a/Project.toml b/Project.toml index 86cda67b..b9231758 100644 --- a/Project.toml +++ b/Project.toml @@ -15,7 +15,7 @@ SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804" [compat] MPI = "0.20" MPIPreferences = "0.1" -PETSc_jll = "~3.21" +PETSc_jll = "3.22" SparseArrays = "1.10" julia = "1.10" diff --git a/examples/DMSTAG_Stokes_2D.jl b/examples/DMSTAG_Stokes_2D.jl index af7f516f..050c31ea 100644 --- a/examples/DMSTAG_Stokes_2D.jl +++ b/examples/DMSTAG_Stokes_2D.jl @@ -93,7 +93,7 @@ function FormJacobian!(ptr_x_g, J, P, user_ctx) # Extract the local vector #PETSc.DMGlobalToLocal(user_ctx.dm, cx_g, PETSc.INSERT_VALUES, user_ctx.x_l) PETSc.update!(user_ctx.x_l, ptr_x_g, PETSc.INSERT_VALUES) - x = PETSc.unsafe_localarray(Float64, user_ctx.x_l.ptr; write=false, read=true); + x = PETSc.unsafe_localarray(Float64, user_ctx.x_l.ptr; write=false); # Check the sparsity pattern if isnothing(user_ctx.jac) diff --git a/examples/DMSTAG_porwave_1D.jl b/examples/DMSTAG_porwave_1D.jl index 9869c830..ea5e95eb 100644 --- a/examples/DMSTAG_porwave_1D.jl +++ b/examples/DMSTAG_porwave_1D.jl @@ -84,7 +84,7 @@ function FormJacobian!(ptr_x_g, J, P, user_ctx) # Extract the local vector from pointer to global vector PETSc.update!(user_ctx.x_l, ptr_x_g, PETSc.INSERT_VALUES) - x = PETSc.unsafe_localarray(Float64, user_ctx.x_l.ptr; write=false, read=true) + x = PETSc.unsafe_localarray(Float64, user_ctx.x_l.ptr; write=false) if isnothing(user_ctx.jac) # Compute sparsity pattern of jacobian. This is relatvely slow, but only has to be done once. diff --git a/examples/SNES_ex2.jl b/examples/SNES_ex2.jl index ee105c57..99dff26c 100644 --- a/examples/SNES_ex2.jl +++ b/examples/SNES_ex2.jl @@ -45,12 +45,12 @@ function FormResidual!(cf,cx, args...) if typeof(cx) <: Ptr{Nothing} # When this routine is called from PETSc, cx is a pointer to a global vector # That's why we have to transfer it first to - x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx) + x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx, write=false) else x = cx; end if typeof(cf) <: Ptr{Nothing} - f = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cf) + f = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cf, write=true) else f = cf; end @@ -76,7 +76,7 @@ end function FormJacobian!(cx, args...) if typeof(cx) <: Ptr{Nothing} - x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx) + x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx, write=false) else x = cx; end diff --git a/examples/SNES_ex2b.jl b/examples/SNES_ex2b.jl index 9522ad2b..bdb94184 100644 --- a/examples/SNES_ex2b.jl +++ b/examples/SNES_ex2b.jl @@ -35,12 +35,12 @@ function FormResidual!(cf,cx, args...) if typeof(cx) <: Ptr{Nothing} # When this routine is called from PETSc, cx is a pointer to a global vector # That's why we have to transfer it first to - x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx) + x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx, write=false) else x = cx; end if typeof(cf) <: Ptr{Nothing} - f = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cf) + f = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cf, write=true) else f = cf; end @@ -76,7 +76,7 @@ end function FormJacobian!(cx, args...) if typeof(cx) <: Ptr{Nothing} - x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx) + x = PETSc.unsafe_localarray(PETSc.scalartype(petsclib),cx, write=false) else x = cx; end diff --git a/src/vec.jl b/src/vec.jl index 5337c0ab..07f93761 100644 --- a/src/vec.jl +++ b/src/vec.jl @@ -254,7 +254,7 @@ julia> map_unsafe_localarray(x; write=true) do x end !!! note - `Base.finalize` should is automatically called on the array. + `Base.finalize` is automatically called on the array. """ function map_unsafe_localarray!(f!, v::AbstractVec{T}; kwargs...) where {T} array = unsafe_localarray(T, v.ptr; kwargs...) diff --git a/test/old_test.jl b/test/old_test.jl index 2454504b..944ae1c9 100644 --- a/test/old_test.jl +++ b/test/old_test.jl @@ -1,6 +1,7 @@ using Test using PETSc, MPI, LinearAlgebra, SparseArrays -PETSc.initialize() +#PETSc.initialize() +PETSc.initialize(PETSc.petsclibs[1]) @testset "Tests" begin m,n = 20,20 @@ -28,7 +29,7 @@ PETSc.initialize() @test PETSc.gettype(pc) == "jacobi" # create an extra handle, check ref count is incremented - pc_extra = PETSc.PC(ksp) + pc_extra = PETSc.PC(ksp); @test PETSc.nrefs(pc) == 3 # destroy extra handle, check ptr is set to null, ref count is decremented PETSc.destroy(pc_extra) @@ -71,8 +72,8 @@ PETSc.initialize() function F!(cfx, cx, a) - x = PETSc.unsafe_localarray(Float64,cx) - fx = PETSc.unsafe_localarray(Float64,cfx) + x = PETSc.unsafe_localarray(Float64,cx, write=false) + fx = PETSc.unsafe_localarray(Float64,cfx,write=true) fx[1] = x[1]^2 + x[1]*x[2] - 3 fx[2] = x[1]*x[2] + x[2]^2 - 6 Base.finalize(x) @@ -82,7 +83,7 @@ PETSc.initialize() J = zeros(2,2) PJ = PETSc.MatSeqDense(J) function updateJ!(cx, args...) - x = PETSc.unsafe_localarray(Float64,cx) + x = PETSc.unsafe_localarray(Float64,cx, write=false) J[1,1] = 2x[1] + x[2] J[1,2] = x[1] J[2,1] = x[2] @@ -93,5 +94,6 @@ PETSc.initialize() S = PETSc.SNES{Float64}(PETSc.petsclibs[1],MPI.COMM_SELF; ksp_rtol=1e-4, pc_type="none") PETSc.setfunction!(S, F!, PETSc.VecSeq(zeros(2))) PETSc.setjacobian!(S, updateJ!, PJ, PJ) - @test PETSc.solve!([2.0,3.0], S) ≈ [1.0,2.0] rtol=1e-4 + a = PETSc.VecSeq([2.0,3.0]) + @test PETSc.solve!(a, S) ≈ [1.0,2.0] rtol=1e-4 end diff --git a/test/runtests.jl b/test/runtests.jl index e0450c1f..06baaa08 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -27,7 +27,6 @@ if do_mpi include("mpi_examples.jl") end - include("options.jl") include("dmda.jl") include("old_test.jl") diff --git a/test/test_snes.jl b/test/test_snes.jl index c65b3628..9c93f56d 100644 --- a/test/test_snes.jl +++ b/test/test_snes.jl @@ -30,7 +30,7 @@ MPI.Initialized() || MPI.Init() # We could do Global->Local here on cfx/cx, provided a pointer to the local # vector is available in user_ctx x_in = PETSc.unsafe_localarray(PetscScalar, cx; write=false) # read array - fx_in = PETSc.unsafe_localarray(PetscScalar, cfx; read=false) # write array + fx_in = PETSc.unsafe_localarray(PetscScalar, cfx; write=true) # write array fx_in[1] = x_in[1]^2 + x_in[1]*x_in[2] - 3 fx_in[2] = x_in[1]*x_in[2] + x_in[2]^2 - 6 @@ -76,7 +76,7 @@ MPI.Initialized() || MPI.Init() b = PETSc.VecSeq(PetscScalar.([0.0, 0.0])); PETSc.solve!(x, S, b) - sol = PETSc.unsafe_localarray(PetscScalar, x.ptr; read=false) + sol = PETSc.unsafe_localarray(PetscScalar, x.ptr) @test sol ≈ [1.0,2.0] rtol=1e-4 # cleanup