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

Added a new function get_local_array_read #82

Merged
merged 1 commit into from
Jun 1, 2022
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
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