Skip to content

Commit 1205f96

Browse files
committed
Added global_to_owner
1 parent 46ae438 commit 1205f96

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/p_range.jl

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ function find_owner(indices,global_ids)
347347
find_owner(indices,global_ids,eltype(indices))
348348
end
349349

350+
function global_to_owner(indices)
351+
global_to_owner(indices,eltype(indices))
352+
end
353+
350354
struct AssemblyCache
351355
neighbors_snd::Base.RefValue{Vector{Int32}}
352356
neighbors_rcv::Base.RefValue{Vector{Int32}}
@@ -1268,7 +1272,15 @@ function find_owner(indices,global_ids,::Type{<:OwnAndGhostIndices{T}}) where T
12681272
end
12691273
end
12701274

1271-
function map_global_to_owner(I,global_to_owner)
1275+
function global_to_owner(a::OwnAndGhostIndices)
1276+
a.global_to_owner
1277+
end
1278+
1279+
function global_to_owner(indices,::Type{<:OwnAndGhostIndices{T}}) where T
1280+
map(global_to_owner,indices) |> getany
1281+
end
1282+
1283+
function map_global_to_owner(I,global_to_owner::AbstractArray)
12721284
Ti = eltype(global_to_owner)
12731285
owners = Vector{Ti}(undef,length(I))
12741286
for k in 1:length(I)
@@ -1282,6 +1294,20 @@ function map_global_to_owner(I,global_to_owner)
12821294
owners
12831295
end
12841296

1297+
function map_global_to_owner(I,global_to_owner::Function)
1298+
Ti = Int32
1299+
owners = Vector{Ti}(undef,length(I))
1300+
for k in 1:length(I)
1301+
i = I[k]
1302+
if i<1
1303+
owners[k] = zero(Ti)
1304+
continue
1305+
end
1306+
owners[k] = global_to_owner(i)
1307+
end
1308+
owners
1309+
end
1310+
12851311
part_id(a::OwnAndGhostIndices) = a.own.owner
12861312

12871313
function own_to_global(a::OwnAndGhostIndices)
@@ -1449,6 +1475,11 @@ function find_owner(indices,global_ids,::Type{<:PermutedLocalIndices})
14491475
find_owner(inner_parts,global_ids)
14501476
end
14511477

1478+
function global_to_owner(indices,::Type{<:PermutedLocalIndices})
1479+
inner_parts = map(i->i.indices,indices)
1480+
global_to_owner(inner_parts)
1481+
end
1482+
14521483
struct BlockPartitionOwnToGlobal{N} <: AbstractVector{Int}
14531484
n::NTuple{N,Int}
14541485
ranges::NTuple{N,UnitRange{Int}}
@@ -1599,6 +1630,17 @@ function find_owner(indices,global_ids,::Type{<:LocalIndicesWithConstantBlockSiz
15991630
end
16001631
end
16011632

1633+
function global_to_owner(indices,::Type{<:LocalIndicesWithConstantBlockSize})
1634+
map(indices) do indices
1635+
start2 = map(indices.np,indices.n) do np,n
1636+
start = [ first(local_range(p,np,n)) for p in 1:np ]
1637+
push!(start,n+1)
1638+
start
1639+
end
1640+
global_to_owner = BlockPartitionGlobalToOwner(start2)
1641+
end |> getany
1642+
end
1643+
16021644
struct LocalIndicesWithVariableBlockSize{N} <: AbstractLocalIndices
16031645
p::CartesianIndex{N}
16041646
np::NTuple{N,Int}
@@ -1632,6 +1674,16 @@ function find_owner(indices,global_ids,::Type{<:LocalIndicesWithVariableBlockSiz
16321674
end
16331675
end
16341676

1677+
function global_to_owner(indices,::Type{<:LocalIndicesWithVariableBlockSize})
1678+
initial = map(indices->map(first,indices.ranges),indices) |> collect |> tuple_of_arrays
1679+
map(indices) do indices
1680+
start = map(indices.n,initial) do n,initial
1681+
start = vcat(initial,[n+1])
1682+
end
1683+
global_to_owner = BlockPartitionGlobalToOwner(start)
1684+
end |> getany
1685+
end
1686+
16351687
const LocalIndicesInBlockPartition = Union{LocalIndicesWithConstantBlockSize,LocalIndicesWithVariableBlockSize}
16361688

16371689
local_permutation(a::LocalIndicesInBlockPartition) = Int32(1):Int32(local_length(a))

0 commit comments

Comments
 (0)