Skip to content

Commit b98d909

Browse files
committed
Added psparse_from_split_blocks
1 parent 503ca6b commit b98d909

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/PartitionedArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ include("p_vector.jl")
143143
export SplitMatrix
144144
export split_matrix
145145
export split_matrix_blocks
146+
export psparse_from_split_blocks
146147
export PSparseMatrix
147148
export psparse
148149
export psparse!

src/p_sparse_matrix.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,16 @@ function split_matrix(
637637
SplitMatrix(blocks,row_permutation,col_permutation)
638638
end
639639

640+
function split_matrix(
641+
own_own::AbstractMatrix,
642+
own_ghost::AbstractMatrix,
643+
ghost_own::AbstractMatrix,
644+
ghost_ghost::AbstractMatrix,
645+
row_permutation,
646+
col_permutation)
647+
blocks = split_matrix_blocks(own_own,own_ghost,ghost_own,ghost_ghost)
648+
split_matrix(blocks,row_permutation,col_permutation)
649+
end
640650

641651
Base.size(a::AbstractSplitMatrix) = (length(a.row_permutation),length(a.col_permutation))
642652
Base.IndexStyle(::Type{<:AbstractSplitMatrix}) = IndexCartesian()
@@ -1294,6 +1304,33 @@ function psparse!(C,V,cache)
12941304
end
12951305
end
12961306

1307+
function psparse_from_split_blocks(oo,oh,ho,hh,rowp,colp;assembled=false)
1308+
rperms = map(local_permutation,rowp)
1309+
cperms = map(local_permutation,colp)
1310+
values = map(split_matrix,oo,oh,ho,hh,rperms,cperms)
1311+
PSparseMatrix(values,rowp,colp,assembled)
1312+
end
1313+
1314+
function psparse_from_split_blocks(oo,oh,rowp,colp;assembled=true)
1315+
ho = map(oo,rowp,colp) do oo, rows, cols
1316+
T = typeof(oo)
1317+
Tv = eltype(oo)
1318+
Ti = indextype(oo)
1319+
n_ghost_rows = ghost_length(rows)
1320+
n_own_cols = own_length(cols)
1321+
sparse_matrix(T,Ti[],Ti[],Tv[],n_ghost_rows,n_own_cols)
1322+
end
1323+
hh = map(oo,rowp,colp) do oo, rows, cols
1324+
T = typeof(oo)
1325+
Tv = eltype(oo)
1326+
Ti = indextype(oo)
1327+
n_ghost_rows = ghost_length(rows)
1328+
n_ghost_cols = ghost_length(cols)
1329+
sparse_matrix(T,Ti[],Ti[],Tv[],n_ghost_rows,n_ghost_cols)
1330+
end
1331+
psparse_from_split_blocks(oo,oh,ho,hh,rowp,colp;assembled)
1332+
end
1333+
12971334
function assemble(A::PSparseMatrix;kwargs...)
12981335
rows = map(remove_ghost,partition(axes(A,1)))
12991336
assemble(A,rows;kwargs...)

test/p_sparse_matrix_tests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ function p_sparse_matrix_tests(distribute)
198198
@test all( values .== 6 )
199199
end
200200

201+
A = psparse_from_split_blocks(own_own_values(A),own_ghost_values(A),row_partition,col_partition)
202+
x = pfill(3.0,axes(A,2);split_format=true)
203+
b = similar(x,axes(A,1))
204+
mul!(b,A,x)
205+
map(own_values(b)) do values
206+
@test all( values .== 6 )
207+
end
208+
consistent!(b) |> wait
209+
map(partition(b)) do values
210+
@test all( values .== 6 )
211+
end
212+
201213
A = psparse(I,J,V,row_partition,col_partition) |> fetch
202214
x = pfill(3.0,axes(A,2))
203215
b = similar(x,axes(A,1))

0 commit comments

Comments
 (0)