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

Update to PETSc 3.22 #202

Merged
merged 4 commits into from
Oct 28, 2024
Merged
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 @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion examples/DMSTAG_Stokes_2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/DMSTAG_porwave_1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions examples/SNES_ex2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/SNES_ex2b.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
14 changes: 8 additions & 6 deletions test/old_test.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand All @@ -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
1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ if do_mpi
include("mpi_examples.jl")
end


include("options.jl")
include("dmda.jl")
include("old_test.jl")
Expand Down
4 changes: 2 additions & 2 deletions test/test_snes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down