Skip to content

Commit 98bc85a

Browse files
author
Jeremy E Kozdon
committed
Update matshell and with_localarray name
1 parent f0e0012 commit 98bc85a

5 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/matshell.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ function (::MatOp{PetscLib, PetscInt, LibPETSc.MATOP_MULT})(
4040
mat = unsafe_pointer_to_objref(ptr)
4141

4242
PetscScalar = PetscLib.PetscScalar
43-
x = unsafe_localarray(VecPtr(PetscLib, cx); write = false)
44-
y = unsafe_localarray(VecPtr(PetscLib, cy); read = false)
43+
x = VecPtr(PetscLib, cx)
44+
y = VecPtr(PetscLib, cy)
4545

4646
_mul!(y, mat, x)
4747

48-
Base.finalize(y)
49-
Base.finalize(x)
5048
return PetscInt(0)
5149
end
5250

src/vec.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,9 @@ function unsafe_localarray(
406406
end
407407

408408
"""
409-
with_unsafe_localarray!(
410-
f!,
411-
x::AbstractVec;
412-
read=true,
413-
write=true,
414-
)
409+
with_localarray!(f!, x::AbstractVec; read=true, write=true)
410+
with_localarray!(f!, xs...; read=true, write=true)
411+
with_localarray!(f!, xs::NTuple{N, AbstractVec}...; read=true, write=true)
415412
416413
Convert `x` to an `Array{PetscScalar}` using [`unsafe_localarray`](@ref) and
417414
apply the function `f!`.
@@ -427,11 +424,16 @@ end
427424
!!! note
428425
`Base.finalize` is automatically called on the array.
429426
"""
430-
function with_unsafe_localarray!(f!, v::AbstractVec; kwargs...)
431-
array = unsafe_localarray(v; kwargs...)
432-
f!(array)
433-
Base.finalize(array)
427+
function with_localarray!(f!, vecs::NTuple{N, AbstractVec}; kwargs...) where N
428+
arrays = map(vecs) do v
429+
unsafe_localarray(v; kwargs...)
430+
end
431+
f!(arrays...)
432+
map(arrays) do array
433+
Base.finalize(array)
434+
end
434435
end
436+
with_localarray!(f!, vecs...; kwargs...) = with_localarray!(f!, vecs; kwargs...)
435437

436438
"""
437439
assemblybegin!(vec::AbstractVec)

test/matshell.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ using MPI
99

1010
local_rows = 10
1111
local_cols = 5
12-
f!(x, y) = x .= [2y; 3y]
12+
function f!(p_x, p_y)
13+
PETSc.with_localarray!((p_x, p_y)) do x, y
14+
x .= [2y; 3y]
15+
end
16+
end
1317
x_jl = collect
1418

1519
matshell =

test/mpivec.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using LinearAlgebra: norm
5959
# 1-based
6060
@test petsc_x[rng .+ 1] == julia_x
6161

62-
PETSc.with_unsafe_localarray!(petsc_x) do x
62+
PETSc.with_localarray!(petsc_x) do x
6363
@test x == julia_x
6464
end
6565

test/vec.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using LinearAlgebra: norm
3030
@test PETSc.ownershiprange(petsc_x) == 1:N
3131
@test PETSc.ownershiprange(petsc_x, false) == 0:(N - 1)
3232

33-
PETSc.with_unsafe_localarray!(petsc_x) do x2
33+
PETSc.with_localarray!(petsc_x) do x2
3434
@test x2 == x
3535
end
3636

@@ -51,7 +51,7 @@ end
5151
@test PETSc.ownershiprange(petsc_x, false) == 0:(N - 1)
5252

5353
x = rand(PetscScalar, N)
54-
PETSc.with_unsafe_localarray!(petsc_x) do x2
54+
PETSc.with_localarray!(petsc_x) do x2
5555
x2 .= x
5656
end
5757
@test norm(petsc_x) norm(x)

0 commit comments

Comments
 (0)