Skip to content

Commit 73de176

Browse files
authored
Merge pull request #40 from gridap/rhs_assembly
Rhs assembly alone
2 parents bfa427b + f9fca06 commit 73de176

File tree

6 files changed

+244
-84
lines changed

6 files changed

+244
-84
lines changed

Manifest.toml

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
1010

1111
[[ArrayInterface]]
1212
deps = ["Compat", "IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
13-
git-tree-sha1 = "b8d49c34c3da35f220e7295659cd0bab8e739fed"
13+
git-tree-sha1 = "1d6835607e9f214cb4210310868f8cf07eb0facc"
1414
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
15-
version = "3.1.33"
15+
version = "3.1.34"
1616

1717
[[ArrayLayouts]]
1818
deps = ["FillArrays", "LinearAlgebra", "SparseArrays"]
19-
git-tree-sha1 = "a745df3fdce8aff885e6f4a3b7427cc27ce5f86c"
19+
git-tree-sha1 = "7a92ea1dd16472d18ca1ffcbb7b3cc67d7e78a3f"
2020
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
21-
version = "0.7.6"
21+
version = "0.7.7"
2222

2323
[[Artifacts]]
2424
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
2525

2626
[[BSON]]
27-
git-tree-sha1 = "92b8a8479128367aaab2620b8e73dff632f5ae69"
27+
git-tree-sha1 = "ebcd6e22d69f21249b7b8668351ebf42d6dc87a1"
2828
uuid = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
29-
version = "0.3.3"
29+
version = "0.3.4"
3030

3131
[[Base64]]
3232
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
3333

3434
[[BlockArrays]]
3535
deps = ["ArrayLayouts", "FillArrays", "LinearAlgebra"]
36-
git-tree-sha1 = "782362509cf50a51092f513e92783c18ab0b6d51"
36+
git-tree-sha1 = "5524e27323cf4c4505699c3fb008c3f772269945"
3737
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
38-
version = "0.16.8"
38+
version = "0.16.9"
3939

4040
[[ChainRulesCore]]
4141
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
42-
git-tree-sha1 = "a325370b9dd0e6bf5656a6f1a7ae80755f8ccc46"
42+
git-tree-sha1 = "d9e40e3e370ee56c5b57e0db651d8f92bce98fea"
4343
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
44-
version = "1.7.2"
44+
version = "1.10.1"
4545

4646
[[CodecZlib]]
4747
deps = ["TranscodingStreams", "Zlib_jll"]
@@ -130,9 +130,9 @@ version = "1.11.1"
130130

131131
[[FillArrays]]
132132
deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"]
133-
git-tree-sha1 = "29890dfbc427afa59598b8cfcc10034719bd7744"
133+
git-tree-sha1 = "8756f9935b7ccc9064c6eef0bff0ad643df733a3"
134134
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
135-
version = "0.12.6"
135+
version = "0.12.7"
136136

137137
[[FiniteDiff]]
138138
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
@@ -141,16 +141,16 @@ uuid = "6a86dc24-6348-571c-b903-95158fe2bd41"
141141
version = "2.8.1"
142142

143143
[[ForwardDiff]]
144-
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "NaNMath", "Printf", "Random", "SpecialFunctions", "StaticArrays"]
145-
git-tree-sha1 = "c4203b60d37059462af370c4f3108fb5d155ff13"
144+
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions", "StaticArrays"]
145+
git-tree-sha1 = "63777916efbcb0ab6173d09a658fb7f2783de485"
146146
uuid = "f6369f11-7733-5829-9624-2563aa707210"
147-
version = "0.10.20"
147+
version = "0.10.21"
148148

149149
[[Gridap]]
150150
deps = ["AbstractTrees", "BSON", "BlockArrays", "Combinatorics", "DocStringExtensions", "FastGaussQuadrature", "FileIO", "FillArrays", "ForwardDiff", "JLD2", "JSON", "LineSearches", "LinearAlgebra", "NLsolve", "NearestNeighbors", "QuadGK", "Random", "SparseArrays", "SparseMatricesCSR", "StaticArrays", "Test", "WriteVTK"]
151151
git-tree-sha1 = "d3bfeb769259b08f7385bdad91681f38c50fc519"
152152
repo-rev = "gridap_distributed"
153-
repo-url = "https://github.com/gridap/Gridap.jl.git"
153+
repo-url = "https://github.com/gridap/Gridap.jl"
154154
uuid = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
155155
version = "0.17.0"
156156

@@ -163,10 +163,16 @@ version = "0.1.0"
163163
deps = ["Markdown"]
164164
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
165165

166+
[[InverseFunctions]]
167+
deps = ["Test"]
168+
git-tree-sha1 = "f0c6489b12d28fb4c2103073ec7452f3423bd308"
169+
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
170+
version = "0.1.1"
171+
166172
[[IrrationalConstants]]
167-
git-tree-sha1 = "f76424439413893a832026ca355fe273e93bce94"
173+
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151"
168174
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
169-
version = "0.1.0"
175+
version = "0.1.1"
170176

171177
[[IterativeSolvers]]
172178
deps = ["LinearAlgebra", "Printf", "Random", "RecipesBase", "SparseArrays"]
@@ -176,9 +182,9 @@ version = "0.9.1"
176182

177183
[[JLD2]]
178184
deps = ["DataStructures", "FileIO", "MacroTools", "Mmap", "Pkg", "Printf", "Reexport", "TranscodingStreams", "UUIDs"]
179-
git-tree-sha1 = "192934b3e2a94e897ce177423fd6cf7bdf464bce"
185+
git-tree-sha1 = "46b7834ec8165c541b0b5d1c8ba63ec940723ffb"
180186
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
181-
version = "0.4.14"
187+
version = "0.4.15"
182188

183189
[[JLLWrappers]]
184190
deps = ["Preferences"]
@@ -234,10 +240,10 @@ deps = ["Libdl"]
234240
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
235241

236242
[[LogExpFunctions]]
237-
deps = ["ChainRulesCore", "DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
238-
git-tree-sha1 = "34dc30f868e368f8a17b728a1238f3fcda43931a"
243+
deps = ["ChainRulesCore", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"]
244+
git-tree-sha1 = "6193c3815f13ba1b78a51ce391db8be016ae9214"
239245
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
240-
version = "0.3.3"
246+
version = "0.3.4"
241247

242248
[[Logging]]
243249
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
@@ -335,13 +341,13 @@ version = "0.12.3"
335341

336342
[[Parsers]]
337343
deps = ["Dates"]
338-
git-tree-sha1 = "a8709b968a1ea6abc2dc1967cb1db6ac9a00dfb6"
344+
git-tree-sha1 = "98f59ff3639b3d9485a03a72f3ab35bab9465720"
339345
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
340-
version = "2.0.5"
346+
version = "2.0.6"
341347

342348
[[PartitionedArrays]]
343349
deps = ["Distances", "IterativeSolvers", "LinearAlgebra", "MPI", "Printf", "SparseArrays", "SparseMatricesCSR"]
344-
git-tree-sha1 = "763146e768b343fec44c521f5c7822116adc24ad"
350+
git-tree-sha1 = "4b79fc86fd30f5063d97d9c40291976ede6fd4d5"
345351
repo-rev = "gridap_distributed"
346352
repo-url = "https://github.com/fverdugo/PartitionedArrays.jl.git"
347353
uuid = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
@@ -409,16 +415,16 @@ deps = ["LinearAlgebra", "Random"]
409415
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
410416

411417
[[SparseMatricesCSR]]
412-
deps = ["LinearAlgebra", "SparseArrays"]
413-
git-tree-sha1 = "dd6dda1484d4031a47d27614ceeb89f511cd9ca4"
418+
deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"]
419+
git-tree-sha1 = "ad906b39ce5e05ec509495dfc7b38d11ce9ab40b"
414420
uuid = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1"
415-
version = "0.6.1"
421+
version = "0.6.5"
416422

417423
[[SpecialFunctions]]
418424
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
419-
git-tree-sha1 = "793793f1df98e3d7d554b65a107e9c9a6399a6ed"
425+
git-tree-sha1 = "2d57e14cd614083f132b6224874296287bfa3979"
420426
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
421-
version = "1.7.0"
427+
version = "1.8.0"
422428

423429
[[Static]]
424430
deps = ["IfElse"]
@@ -441,6 +447,10 @@ git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510"
441447
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
442448
version = "1.0.0"
443449

450+
[[SuiteSparse]]
451+
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
452+
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
453+
444454
[[TOML]]
445455
deps = ["Dates"]
446456
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"
1414

1515
[compat]
16+
FillArrays = "0.8.4, 0.9, 0.10, 0.11, 0.12"
1617
Gridap = "0.17"
18+
MPI = "0.16, 0.17, 0.18, 0.19"
1719
PartitionedArrays = "0.2"
1820
julia = "1.3"
1921

src/Algebra.jl

Lines changed: 145 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,37 +380,47 @@ function local_views(a::PVectorCounter,rows)
380380
a.counters
381381
end
382382

383-
function Arrays.nz_allocation(a::PVectorCounter)
383+
function Arrays.nz_allocation(a::PVectorCounter{<:FullyAssembledRows})
384384
dofs = a.rows
385385
values = map_parts(nz_allocation,a.counters)
386-
PVectorAllocation(a.par_strategy,values,dofs)
386+
PVectorAllocationTrackOnlyValues(a.par_strategy,values,dofs)
387387
end
388388

389-
struct PVectorAllocation{A,B,C}
389+
struct PVectorAllocationTrackOnlyValues{A,B,C}
390390
par_strategy::A
391391
values::B
392392
rows::C
393393
end
394394

395-
function local_views(a::PVectorAllocation)
395+
function local_views(a::PVectorAllocationTrackOnlyValues)
396396
a.values
397397
end
398398

399-
function local_views(a::PVectorAllocation,rows)
399+
function local_views(a::PVectorAllocationTrackOnlyValues,rows)
400400
@check rows === a.rows
401401
a.values
402402
end
403403

404-
function Algebra.create_from_nz(a::PVectorAllocation{<:FullyAssembledRows})
405-
@notimplemented
404+
function Algebra.create_from_nz(a::PVectorAllocationTrackOnlyValues{<:FullyAssembledRows})
405+
# Create PRange for the rows of the linear system
406+
parts = get_part_ids(a.values)
407+
ngdofs = length(a.rows)
408+
nodofs = map_parts(num_oids,a.rows.partition)
409+
first_grdof = map_parts(first_gdof_from_ids,a.rows.partition)
410+
411+
# This one has no ghost rows
412+
rows = PRange(parts,ngdofs,nodofs,first_grdof)
413+
414+
_rhs_callback(a,rows)
406415
end
407416

408-
function Algebra.create_from_nz(a::PVectorAllocation{<:SubAssembledRows})
409-
@notimplemented
417+
function Algebra.create_from_nz(a::PVectorAllocationTrackOnlyValues{<:SubAssembledRows})
418+
# This point MUST NEVER be reached. If reached there is an inconsistency
419+
# in the parallel code in charge of vector assembly
420+
@assert false
410421
end
411422

412423
function _rhs_callback(c_fespace,rows)
413-
414424
# The ghost values in b_fespace are aligned with the FESpace
415425
# but not with the ghost values in the rows of A
416426
b_fespace = PVector(c_fespace.values,c_fespace.rows)
@@ -442,14 +452,14 @@ end
442452

443453
function Algebra.create_from_nz(a::PVector)
444454
# For FullyAssembledRows the underlying Exchanger should
445-
# not have ghost layer making asseble! do nothing (TODO check)
455+
# not have ghost layer making assemble! do nothing (TODO check)
446456
assemble!(a)
447457
a
448458
end
449459

450460
function Algebra.create_from_nz(
451461
a::DistributedAllocationCOO{<:FullyAssembledRows},
452-
c_fespace::PVectorAllocation{<:FullyAssembledRows})
462+
c_fespace::PVectorAllocationTrackOnlyValues{<:FullyAssembledRows})
453463

454464
function callback(rows)
455465
_rhs_callback(c_fespace,rows)
@@ -459,9 +469,15 @@ function Algebra.create_from_nz(
459469
A,b
460470
end
461471

472+
struct PVectorAllocationTrackTouchedAndValues{A,B,C}
473+
allocations::A
474+
values::B
475+
rows::C
476+
end
477+
462478
function Algebra.create_from_nz(
463479
a::DistributedAllocationCOO{<:SubAssembledRows},
464-
c_fespace::PVectorAllocation{<:SubAssembledRows})
480+
c_fespace::PVectorAllocationTrackOnlyValues{<:SubAssembledRows})
465481

466482
function callback(rows)
467483
_rhs_callback(c_fespace,rows)
@@ -476,3 +492,119 @@ function Algebra.create_from_nz(
476492
A,b
477493
end
478494

495+
struct ArrayAllocationTrackTouchedAndValues{A}
496+
touched::Vector{Bool}
497+
values::A
498+
end
499+
500+
Gridap.Algebra.LoopStyle(::Type{<:ArrayAllocationTrackTouchedAndValues}) = Gridap.Algebra.Loop()
501+
502+
503+
function local_views(a::PVectorAllocationTrackTouchedAndValues,rows)
504+
@check rows === a.rows
505+
a.allocations
506+
end
507+
508+
@inline function Arrays.add_entry!(c::Function,a::ArrayAllocationTrackTouchedAndValues,v,i,j)
509+
@notimplemented
510+
end
511+
@inline function Arrays.add_entry!(c::Function,a::ArrayAllocationTrackTouchedAndValues,v,i)
512+
if i>0
513+
if !(a.touched[i])
514+
a.touched[i]=true
515+
end
516+
if v!=nothing
517+
a.values[i]=c(v,a.values[i])
518+
end
519+
end
520+
nothing
521+
end
522+
@inline function Arrays.add_entries!(c::Function,a::ArrayAllocationTrackTouchedAndValues,v,i,j)
523+
@notimplemented
524+
end
525+
@inline function Arrays.add_entries!(c::Function,a::ArrayAllocationTrackTouchedAndValues,v,i)
526+
if v != nothing
527+
for (ve,ie) in zip(v,i)
528+
Arrays.add_entry!(c,a,ve,ie)
529+
end
530+
else
531+
for ie in i
532+
Arrays.add_entry!(c,a,nothing,ie)
533+
end
534+
end
535+
nothing
536+
end
537+
538+
function Arrays.nz_allocation(a::DistributedCounterCOO{<:SubAssembledRows},
539+
b::PVectorCounter{<:SubAssembledRows})
540+
A = nz_allocation(a)
541+
dofs = b.rows
542+
values = map_parts(nz_allocation,b.counters)
543+
B=PVectorAllocationTrackOnlyValues(b.par_strategy,values,dofs)
544+
A,B
545+
end
546+
547+
function Arrays.nz_allocation(a::PVectorCounter{<:SubAssembledRows})
548+
dofs = a.rows
549+
values = map_parts(nz_allocation,a.counters)
550+
touched = map_parts(values) do values
551+
fill!(Vector{Bool}(undef,length(values)),false)
552+
end
553+
allocations=map_parts(values,touched) do values,touched
554+
ArrayAllocationTrackTouchedAndValues(touched,values)
555+
end
556+
PVectorAllocationTrackTouchedAndValues(allocations,values,dofs)
557+
end
558+
559+
function local_views(a::PVectorAllocationTrackTouchedAndValues)
560+
a.allocations
561+
end
562+
563+
function Algebra.create_from_nz(a::PVectorAllocationTrackTouchedAndValues)
564+
parts = get_part_ids(a.values)
565+
rdofs = a.rows # dof ids of the test space
566+
ngrdofs = length(rdofs)
567+
nordofs = map_parts(num_oids,rdofs.partition)
568+
first_grdof = map_parts(first_gdof_from_ids,rdofs.partition)
569+
rneigs_snd = rdofs.exchanger.parts_snd
570+
rneigs_rcv = rdofs.exchanger.parts_rcv
571+
572+
# Find the ghost rows
573+
hrow_to_hrdof=map_parts(local_views(a.allocations),rdofs.partition) do allocation, indices
574+
lids_touched=findall(allocation.touched)
575+
nhlids = count((x)->indices.lid_to_ohid[x]<0,lids_touched)
576+
hlids = Vector{Int32}(undef,nhlids)
577+
cur=1
578+
for lid in lids_touched
579+
hlid=indices.lid_to_ohid[lid]
580+
if hlid<0
581+
hlids[cur]=-hlid
582+
cur=cur+1
583+
end
584+
end
585+
hlids
586+
end
587+
hrow_to_gid, hrow_to_part = map_parts(
588+
find_gid_and_part,hrow_to_hrdof,rdofs.partition)
589+
590+
# Create the range for rows
591+
rows = PRange(
592+
parts,
593+
ngrdofs,
594+
nordofs,
595+
first_grdof,
596+
hrow_to_gid,
597+
hrow_to_part,
598+
rneigs_snd,
599+
rneigs_rcv)
600+
601+
b = _rhs_callback(a,rows)
602+
t2 = async_assemble!(b)
603+
604+
# Wait the transfer to finish
605+
if t2 !== nothing
606+
map_parts(schedule,t2)
607+
map_parts(wait,t2)
608+
end
609+
b
610+
end

0 commit comments

Comments
 (0)