From 5ac75d0d12342d9a2ecc42180c10ff7a384f9454 Mon Sep 17 00:00:00 2001 From: amartin Date: Wed, 1 Jun 2022 21:30:56 +1000 Subject: [PATCH] Added a new function get_local_array_read --- src/PETScArrays.jl | 10 ++++++++++ src/PartitionedArrays.jl | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PETScArrays.jl b/src/PETScArrays.jl index 58232c8..1f455ba 100644 --- a/src/PETScArrays.jl +++ b/src/PETScArrays.jl @@ -166,6 +166,16 @@ function _get_local_vector(a::PETScVector) return v end +# This function works with either ghosted or non-ghosted MPI vectors. +# In the case of a ghosted vector it solely returns the locally owned +# entries. +function _get_local_vector_read(a::PETScVector) + r_pv = Ref{Ptr{PetscScalar}}() + @check_error_code PETSC.VecGetArrayRead(a.vec[], r_pv) + v = unsafe_wrap(Array, r_pv[], _local_size(a); own = false) + return v +end + function _restore_local_vector!(v::Array,a::PETScVector) @check_error_code PETSC.VecRestoreArray(a.vec[], Ref(pointer(v))) nothing diff --git a/src/PartitionedArrays.jl b/src/PartitionedArrays.jl index 2463dbf..ec5042e 100644 --- a/src/PartitionedArrays.jl +++ b/src/PartitionedArrays.jl @@ -119,7 +119,7 @@ function _copy!(pvec::PVector{T,<:MPIData},petscvec::Vec) where T # convert petscvec into a PVector to avoid extra memory allocation # and copies. @assert pvec.rows.ghost - lx=_get_local_vector(lg) + lx=_get_local_vector_read(lg) vvalues=view(values,indices.oid_to_lid) vvalues .= lx[1:num_oids(indices)] _restore_local_vector!(lx,lg)