Skip to content

Commit

Permalink
Added a new function get_local_array_read
Browse files Browse the repository at this point in the history
  • Loading branch information
amartinhuertas committed Jun 1, 2022
1 parent 119a9d0 commit 5ac75d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/PETScArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PartitionedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5ac75d0

Please sign in to comment.