Skip to content

Commit a6daa66

Browse files
Merge pull request #143 from gridap/fix_issue_142
Fix issue 142
2 parents b30c808 + c2cd9b7 commit a6daa66

File tree

7 files changed

+80
-21
lines changed

7 files changed

+80
-21
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added redistribution for MultiFieldFESpaces. Since PR [#140](https://github.com/gridap/GridapDistributed.jl/pull/140).
1313

14+
### Fixed
15+
16+
- Fixed issue [#142](https://github.com/gridap/GridapDistributed.jl/issues/142). Since PR [#142](https://github.com/gridap/GridapDistributed.jl/pull/142).
17+
1418
## [0.3.5] - 2023-12-04
1519

1620
### Added

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
1717
[compat]
1818
BlockArrays = "0.16.38"
1919
FillArrays = "0.8.4,1"
20-
Gridap = "0.17.21"
20+
Gridap = "0.17.23"
2121
LinearAlgebra = "1.3"
2222
MPI = "0.16, 0.17, 0.18, 0.19, 0.20"
2323
PartitionedArrays = "0.3.3"

src/Algebra.jl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,17 @@ end
507507

508508
function Algebra.create_from_nz(a::DistributedAllocationCOO{<:SubAssembledRows})
509509
f(x) = nothing
510-
A, = _sa_create_from_nz_with_callback(f,f,a)
510+
A, = _sa_create_from_nz_with_callback(f,f,a,nothing)
511511
return A
512512
end
513513

514514
function Algebra.create_from_nz(a::ArrayBlock{<:DistributedAllocationCOO{<:SubAssembledRows}})
515515
f(x) = nothing
516-
A, = _sa_create_from_nz_with_callback(f,f,a)
516+
A, = _sa_create_from_nz_with_callback(f,f,a,nothing)
517517
return A
518518
end
519519

520-
function _sa_create_from_nz_with_callback(callback,async_callback,a)
520+
function _sa_create_from_nz_with_callback(callback,async_callback,a,b)
521521
# Recover some data
522522
I,J,V = get_allocations(a)
523523
test_dofs_gids_prange = get_test_gids(a)
@@ -538,7 +538,10 @@ function _sa_create_from_nz_with_callback(callback,async_callback,a)
538538
# Here we can overlap computations
539539
# This is a good place to overlap since
540540
# sending the matrix rows is a lot of data
541-
b = callback(rows)
541+
if !isa(b,Nothing)
542+
bprange=_setup_prange_from_pvector_allocation(b)
543+
b = callback(bprange)
544+
end
542545

543546
# Wait the transfer to finish
544547
wait(t)
@@ -701,18 +704,18 @@ end
701704

702705
function Algebra.create_from_nz(
703706
a::DistributedAllocationCOO{<:SubAssembledRows},
704-
c_fespace::PVectorAllocationTrackOnlyValues{<:SubAssembledRows})
707+
b::PVectorAllocationTrackTouchedAndValues)
705708

706709
function callback(rows)
707-
_rhs_callback(c_fespace,rows)
710+
_rhs_callback(b,rows)
708711
end
709712

710713
function async_callback(b)
711714
# now we can assemble contributions
712715
assemble!(b)
713716
end
714717

715-
A,b = _sa_create_from_nz_with_callback(callback,async_callback,a)
718+
A,b = _sa_create_from_nz_with_callback(callback,async_callback,a,b)
716719
return A,b
717720
end
718721

@@ -759,32 +762,39 @@ end
759762
nothing
760763
end
761764

765+
766+
function _setup_touched_and_allocations_arrays(values)
767+
touched = map(values) do values
768+
fill!(Vector{Bool}(undef,length(values)),false)
769+
end
770+
allocations = map(values,touched) do values,touched
771+
ArrayAllocationTrackTouchedAndValues(touched,values)
772+
end
773+
touched, allocations
774+
end
775+
762776
function Arrays.nz_allocation(a::DistributedCounterCOO{<:SubAssembledRows},
763777
b::PVectorCounter{<:SubAssembledRows})
764778
A = nz_allocation(a)
765779
dofs = b.test_dofs_gids_prange
766780
values = map(nz_allocation,b.counters)
767-
B = PVectorAllocationTrackOnlyValues(b.par_strategy,values,dofs)
781+
touched,allocations=_setup_touched_and_allocations_arrays(values)
782+
B = PVectorAllocationTrackTouchedAndValues(allocations,values,dofs)
768783
return A,B
769784
end
770785

771786
function Arrays.nz_allocation(a::PVectorCounter{<:SubAssembledRows})
772787
dofs = a.test_dofs_gids_prange
773788
values = map(nz_allocation,a.counters)
774-
touched = map(values) do values
775-
fill!(Vector{Bool}(undef,length(values)),false)
776-
end
777-
allocations = map(values,touched) do values,touched
778-
ArrayAllocationTrackTouchedAndValues(touched,values)
779-
end
789+
touched,allocations=_setup_touched_and_allocations_arrays(values)
780790
return PVectorAllocationTrackTouchedAndValues(allocations,values,dofs)
781791
end
782792

783793
function local_views(a::PVectorAllocationTrackTouchedAndValues)
784794
a.allocations
785795
end
786796

787-
function Algebra.create_from_nz(a::PVectorAllocationTrackTouchedAndValues)
797+
function _setup_prange_from_pvector_allocation(a::PVectorAllocationTrackTouchedAndValues)
788798
test_dofs_prange = a.test_dofs_gids_prange # dof ids of the test space
789799
ngrdofs = length(test_dofs_prange)
790800

@@ -810,20 +820,21 @@ function Algebra.create_from_nz(a::PVectorAllocationTrackTouchedAndValues)
810820
gids_ghost_to_global, gids_ghost_to_owner = map(
811821
find_gid_and_owner,I_ghost_lids_to_dofs_ghost_lids,indices) |> tuple_of_arrays
812822

813-
rows = _setup_prange_impl_(ngrdofs,indices,gids_ghost_to_global,gids_ghost_to_owner)
823+
_setup_prange_impl_(ngrdofs,indices,gids_ghost_to_global,gids_ghost_to_owner)
824+
end
825+
826+
function Algebra.create_from_nz(a::PVectorAllocationTrackTouchedAndValues)
827+
rows = _setup_prange_from_pvector_allocation(a)
814828
b = _rhs_callback(a,rows)
815829
t2 = assemble!(b)
816-
817830
# Wait the transfer to finish
818831
if t2 !== nothing
819832
wait(t2)
820833
end
821834
return b
822835
end
823836

824-
825837
# Common Assembly Utilities
826-
827838
function first_gdof_from_ids(ids)
828839
if own_length(ids) == 0
829840
return 1

src/FESpaces.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,10 @@ end
621621
function FESpaces.symbolic_loop_matrix_and_vector!(A,b,a::DistributedSparseMatrixAssembler,data)
622622
rows = get_rows(a)
623623
cols = get_cols(a)
624-
map(symbolic_loop_matrix_and_vector!,local_views(A,rows,cols),local_views(b,rows),local_views(a),data)
624+
Aviews=local_views(A,rows,cols)
625+
bviews=local_views(b,rows)
626+
aviews=local_views(a)
627+
map(symbolic_loop_matrix_and_vector!,Aviews,bviews,aviews,data)
625628
end
626629

627630
function FESpaces.numeric_loop_matrix_and_vector!(A,b,a::DistributedSparseMatrixAssembler,data)

test/issue_142.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Gridap
2+
using PartitionedArrays
3+
using GridapDistributed
4+
using Test
5+
6+
function main(distribute,rank_partition)
7+
DX = 1000.0
8+
DY = 1000.0
9+
order = 0
10+
n_els_x = 4
11+
n_els_y = 4
12+
dx = DX/n_els_x
13+
domain = (0,DX,0,DY)
14+
cell_partition = (n_els_x,n_els_y)
15+
ranks = distribute(LinearIndices((prod(rank_partition),)))
16+
17+
model = CartesianDiscreteModel(ranks,rank_partition,domain,cell_partition; isperiodic=(false,false))
18+
Ω = Triangulation(model)
19+
= Measure(Ω, 5*(order+1))
20+
Γ = SkeletonTriangulation(model)
21+
= Measure(Γ, 5*(order+1))
22+
23+
Q = FESpace(model, ReferenceFE(lagrangian, Float64, order), conformity=:L2)
24+
P = TrialFESpace(Q)
25+
26+
# initial conditions
27+
ph=FEFunction(P,prand(partition(Q.gids)))
28+
29+
b(q) = (jump(ph)*mean(q))dΓ
30+
m(p,q) = (p*q)dΩ
31+
op = AffineFEOperator(m, b, P, Q)
32+
b=assemble_vector(b(get_fe_basis(Q)),P)
33+
tol=1.0e-12
34+
@test norm(op.op.vector-b)/norm(b) < tol
35+
end

test/sequential/issue_142.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include("../issue_142.jl")
2+
with_debug() do distribute
3+
main(distribute,(2,1))
4+
end

test/sequential/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ using Test
1212

1313
@time @testset "MultiField" begin include("MultiFieldTests.jl") end
1414

15+
@time @testset "issue_142" begin include("issue_142.jl") end
16+
1517
@time @testset "Poisson" begin include("PoissonTests.jl") end
1618

1719
@time @testset "PLaplacian" begin include("PLaplacianTests.jl") end

0 commit comments

Comments
 (0)