Skip to content

Commit 9b8ffc1

Browse files
committed
renumber_partition and other minor changes
1 parent 997ac6e commit 9b8ffc1

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The previous "monolithic" storage is not implemented anymore for the new version
2626
- Efficient re-construction of `PSparseMatrix` and `PVector` objects.
2727
- Functions `assemble` and `consistent` (allocating versions of `assemble!` and `consistent!` with a slightly different
2828
treatment of the ghost rows).
29-
- Function `consitent` for `PSparseMatrix`.
29+
- Function `consistent` for `PSparseMatrix`.
3030
- Functions `repartition` and `repartition!` used to change the data partition of `PSparseMatrix` and `PVector` objects.
3131
- Functions `psystem` and `psystem!` for generating a system matrix and vector at once.
3232
- Function `trivial_partition`.

src/PartitionedArrays.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export uniform_partition
6666
export variable_partition
6767
export partition_from_color
6868
export trivial_partition
69+
export renumber_partition
6970
export AbstractLocalIndices
7071
export OwnAndGhostIndices
7172
export LocalIndices
@@ -102,6 +103,12 @@ export partition
102103
export assembly_graph
103104
export assembly_neighbors
104105
export assembly_local_indices
106+
export map_local_to_global!
107+
export map_global_to_local!
108+
export map_ghost_to_global!
109+
export map_global_to_ghost!
110+
export map_own_to_global!
111+
export map_global_to_own!
105112
include("p_range.jl")
106113

107114
export local_values
@@ -126,6 +133,7 @@ export repartition!
126133
include("p_vector.jl")
127134

128135
export OldPSparseMatrix
136+
export SplitMatrix
129137
export PSparseMatrix
130138
export old_psparse
131139
export psparse

src/p_range.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,27 @@ function trivial_partition(ranks,n;destination=MAIN)
771771
partition_in_main
772772
end
773773

774+
function renumber_partition(partition_in)
775+
own_ids = map(own_to_global,partition_in)
776+
if eltype(own_ids) <: BlockPartitionOwnToGlobal{1}
777+
return partition_in
778+
end
779+
n_global = PartitionedArrays.getany(map(global_length,partition_in))
780+
n_own = map(own_length,partition_in)
781+
new_gids = variable_partition(n_own,n_global)
782+
v = PVector{Vector{Int}}(undef,partition_in)
783+
map(own_values(v),new_gids) do own_v, new_gids
784+
own_v .= own_to_global(new_gids)
785+
end
786+
consistent!(v) |> wait
787+
I = ghost_values(v)
788+
I_owner = map(ghost_to_owner,partition_in)
789+
new_ids2 = map(union_ghost,new_gids,I,I_owner)
790+
perm = map(PartitionedArrays.local_permutation,partition_in)
791+
partition_out = map(permute_indices,new_ids2,perm)
792+
partition_out
793+
end
794+
774795
function local_range(p,np,n,ghost=false,periodic=false)
775796
l = n ÷ np
776797
offset = l * (p-1)
@@ -1223,7 +1244,7 @@ assembly_cache(a::OwnAndGhostIndices) = a.assembly_cache
12231244
local_permutation(a::OwnAndGhostIndices) = Int32(1):Int32(local_length(a))
12241245

12251246
function replace_ghost(a::OwnAndGhostIndices,ghost::GhostIndices)
1226-
OwnAndGhostIndices(a.own,ghost)
1247+
OwnAndGhostIndices(a.own,ghost,a.global_to_owner)
12271248
end
12281249

12291250
function find_owner(indices,global_ids,::Type{<:OwnAndGhostIndices{T}}) where T

src/p_sparse_matrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,8 @@ function psparse_assemble_impl(
12721272
blocks = split_matrix_blocks(own_own,own_ghost,ghost_own,ghost_ghost)
12731273
values = split_matrix(blocks,local_permutation(rows_fa),local_permutation(rows_fa))
12741274
nnz_own_own = nnz(own_own)
1275-
k_own_sa = precompute_nzindex(own_own,nz_own_own[1:2]...)
1276-
k_ghost_sa = precompute_nzindex(own_ghost,nz_own_ghost[1:2]...)
1275+
k_own_sa = precompute_nzindex(own_own,own_own_triplet[1:2]...)
1276+
k_ghost_sa = precompute_nzindex(own_ghost,own_ghost_triplet[1:2]...)
12771277
for p in 1:length(I_rcv_own)
12781278
i = I_rcv_own[p]
12791279
j = J_rcv_own[p]

test/p_range_tests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ function p_range_tests(distribute)
143143
LocalIndices(n,part,[1,3,7,9,10],Int32[1,1,3,4,4])
144144
end
145145
end
146+
@test renumber_partition(ids) !== ids
146147

147148
ids = uniform_partition(parts,n)
149+
@test renumber_partition(ids) === ids
148150
@test length(ids) == length(parts)
149151

150152
gids = map(parts) do part
@@ -176,6 +178,7 @@ function p_range_tests(distribute)
176178
end
177179
end
178180
ids5 = variable_partition(a,sum(a))
181+
@test renumber_partition(ids5) === ids5
179182
map(parts,ids5) do part, local_to_global
180183
if part == 1
181184
@test local_to_global == [1, 2, 3, 4]

0 commit comments

Comments
 (0)