From 486b68429adc4f0457776ea4fae350edae10cc92 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Wed, 10 Jan 2024 18:22:50 +0100 Subject: [PATCH] Moving code to p_vector.jl --- src/PartitionedArrays.jl | 12 ++----- src/p_sparse_matrix.jl | 77 --------------------------------------- src/p_vector.jl | 78 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 86 deletions(-) diff --git a/src/PartitionedArrays.jl b/src/PartitionedArrays.jl index 107c8575..27b4665e 100644 --- a/src/PartitionedArrays.jl +++ b/src/PartitionedArrays.jl @@ -111,6 +111,8 @@ export OwnAndGhostVectors export PVector export pvector export pvector! +export pvector_new +export pvector_new! export pfill export pzeros export pones @@ -124,18 +126,12 @@ export repartition! include("p_vector.jl") export PSparseMatrix +export PSparseMatrixNew export psparse export psparse_new export psparse_new! export split_values export split_values! -export compress_values -export compress_values! -export subassemble -export subassemble! -export Disassembled -export Subassembled -export Assembled export psparse! export own_ghost_values export ghost_own_values @@ -143,8 +139,6 @@ export own_own_values export ghost_ghost_values export psystem export psystem! -export pvector_new -export pvector_new! include("p_sparse_matrix.jl") export PTimer diff --git a/src/p_sparse_matrix.jl b/src/p_sparse_matrix.jl index bfb0a214..4807dfa0 100644 --- a/src/p_sparse_matrix.jl +++ b/src/p_sparse_matrix.jl @@ -1686,83 +1686,6 @@ function repartition!(B::PSparseMatrixNew,c::PVector,A::PSparseMatrixNew,b::PVec end end -function dense_vector(I,V,n) - T = eltype(V) - a = zeros(T,n) - for (i,v) in zip(I,V) - a[i] += v - end - a -end - -function pvector_new(I,V,rows;kwargs...) - pvector_new(dense_vector,I,V,rows;kwargs...) -end - -function pvector_new(f,I,V,rows; - assembled=false, - assemble=true, - discover_rows=true, - restore_ids = true, - reuse=Val(false) - ) - - if assembled || assemble - @boundscheck @assert all(i->ghost_length(i)==0,rows) - end - - if !assembled && discover_rows - I_owner = find_owner(rows,I) - rows_sa = map(union_ghost,rows,I,I_owner) - else - rows_sa = rows - end - map(map_global_to_local!,I,rows_sa) - values_sa = map(f,I,V,map(local_length,rows_sa)) - if val_parameter(reuse) - K = map(copy,I) - end - if restore_ids - map(map_local_to_global!,I,rows_sa) - end - A = PVector(values_sa,rows_sa) - if assemble - t = PartitionedArrays.assemble(A,rows;reuse=true) - else - t = @async A,nothing - end - if val_parameter(reuse) == false - return @async begin - B, cacheB = fetch(t) - B - end - else - return @async begin - B, cacheB = fetch(t) - cache = (A,cacheB,assemble,assembled,K) - (B, cache) - end - end -end - -function pvector_new!(B,V,cache) - function update!(A,K,V) - fill!(A,0) - for (k,v) in zip(K,V) - A[k] += v - end - end - (A,cacheB,assemble,assembled,K) = cache - rows_sa = partition(axes(A,1)) - values_sa = partition(A) - map(update!,values_sa,K,V) - if !assembled && assembled - t = PartitionedArrays.assemble!(B,A,cacheB) - else - t = @async B - end -end - function psystem(I,J,V,I2,V2,rows,cols; split_matrix=true, assembled=false, diff --git a/src/p_vector.jl b/src/p_vector.jl index 5c3976ec..27a8a3f3 100644 --- a/src/p_vector.jl +++ b/src/p_vector.jl @@ -556,6 +556,84 @@ function pvector!(f,I,V,index_partition;discover_rows=true) assemble!(v) end +function dense_vector(I,V,n) + T = eltype(V) + a = zeros(T,n) + for (i,v) in zip(I,V) + a[i] += v + end + a +end + +function pvector_new(I,V,rows;kwargs...) + pvector_new(dense_vector,I,V,rows;kwargs...) +end + +function pvector_new(f,I,V,rows; + assembled=false, + assemble=true, + discover_rows=true, + restore_ids = true, + reuse=Val(false) + ) + + if assembled || assemble + @boundscheck @assert all(i->ghost_length(i)==0,rows) + end + + if !assembled && discover_rows + I_owner = find_owner(rows,I) + rows_sa = map(union_ghost,rows,I,I_owner) + else + rows_sa = rows + end + map(map_global_to_local!,I,rows_sa) + values_sa = map(f,I,V,map(local_length,rows_sa)) + if val_parameter(reuse) + K = map(copy,I) + end + if restore_ids + map(map_local_to_global!,I,rows_sa) + end + A = PVector(values_sa,rows_sa) + if assemble + t = PartitionedArrays.assemble(A,rows;reuse=true) + else + t = @async A,nothing + end + if val_parameter(reuse) == false + return @async begin + B, cacheB = fetch(t) + B + end + else + return @async begin + B, cacheB = fetch(t) + cache = (A,cacheB,assemble,assembled,K) + (B, cache) + end + end +end + +function pvector_new!(B,V,cache) + function update!(A,K,V) + fill!(A,0) + for (k,v) in zip(K,V) + A[k] += v + end + end + (A,cacheB,assemble,assembled,K) = cache + rows_sa = partition(axes(A,1)) + values_sa = partition(A) + map(update!,values_sa,K,V) + if !assembled && assembled + t = PartitionedArrays.assemble!(B,A,cacheB) + else + t = @async B + end +end + + function pvector!(I,V,index_partition;kwargs...) pvector!(default_local_values,I,V,index_partition;kwargs...) end