Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 098bcbd

Browse files
committedJun 4, 2024
add parallel timers
1 parent 9f300d6 commit 098bcbd

File tree

7 files changed

+93
-36
lines changed

7 files changed

+93
-36
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ tmp/*
1919
*.nav
2020
*.snm
2121
*.toc
22+
*.jld2

‎src/Distributed.jl

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11

22
function cut(cutter::STLCutter,bgmodel::DistributedDiscreteModel,args...)
33
D = map(num_dims,local_views(bgmodel)) |> PartitionedArrays.getany
4-
cutter = STLCutter(;all_defined=false,cutter.options...)
4+
timers,cutter = setup_distributed_cutter(cutter,bgmodel)
55
cell_gids = get_cell_gids(bgmodel)
66
facet_gids = get_face_gids(bgmodel,D-1)
77

8+
tic!(timers["global"],barrier=true)
89
bcells = map(compute_boundary_cells,local_views(bgmodel),local_views(cell_gids))
910
icells = map(compute_interior_cells,local_views(bgmodel),local_views(cell_gids))
1011

12+
# Setup cutters
13+
tic!(timers["fine"],barrier=true)
14+
cell_to_facets = map(local_views(bgmodel)) do bgmodel
15+
compute_cell_to_facets(bgmodel,args...)
16+
end
17+
toc!(timers["fine"],"setup")
18+
1119
# Cut touched parts (only boundary cells)
20+
tic!(timers["fine"],barrier=true)
1221
cuts = map(
1322
local_views(bgmodel),
14-
local_views(cell_gids),
1523
local_views(facet_gids),
16-
bcells) do bgmodel,cell_gids,facet_gids,bcells
24+
bcells,
25+
cell_to_facets) do bgmodel,facet_gids,bcells,cell_to_facets
1726

18-
# bcells = compute_boundary_cells(bgmodel,cell_gids)
1927
ownmodel = DiscreteModelPortion(bgmodel,bcells)
20-
# ownmodel = remove_ghost_cells(bgmodel,cell_gids)
2128
cell_to_pcell = get_cell_to_parent_cell(ownmodel)
2229
facet_to_pfacet = get_face_to_parent_face(ownmodel,D-1)
23-
cutgeo = cut(cutter,ownmodel,args...)
30+
cell_to_facets = lazy_map(Reindex(cell_to_facets),bcells)
31+
_cutter = STLCutter(;cell_to_facets,cutter.options...)
32+
cutgeo = cut(_cutter,ownmodel,args...)
2433
cutgeo = change_bgmodel(cutgeo,bgmodel,cell_to_pcell,facet_to_pfacet)
2534
remove_ghost_subfacets(cutgeo,facet_gids)
2635
end
36+
toc!(timers["fine"],"interface")
2737

2838
# Setup coarse inout and graph
2939
facet_to_inoutcut = map(compute_bgfacet_to_inoutcut,cuts)
@@ -38,6 +48,8 @@ function cut(cutter::STLCutter,bgmodel::DistributedDiscreteModel,args...)
3848
part_to_lpart_to_ioc = gather(facet_neighbor_to_ioc,destination=root)
3949

4050
# Propagate at coarse level (and complete intersections)
51+
tic!(timers["coarse"],barrier=true)
52+
tic!(timers["fine"],barrier=true)
4153
part_to_ioc = map(
4254
part_to_parts,
4355
part_to_lpart_to_ioc,
@@ -50,22 +62,26 @@ function cut(cutter::STLCutter,bgmodel::DistributedDiscreteModel,args...)
5062
Int8[]
5163
end
5264
end
65+
toc!(timers["coarse"],"coarse")
5366

5467
# Complete cut (interior cells)
5568
icuts = map(
5669
local_views(bgmodel),
57-
local_views(cell_gids),
5870
local_views(facet_gids),
59-
icells) do bgmodel,cell_gids,facet_gids,icells
71+
icells,
72+
cell_to_facets) do bgmodel,facet_gids,icells,cell_to_facets
6073

6174
# icells = compute_interior_cells(bgmodel,cell_gids)
6275
ownmodel = DiscreteModelPortion(bgmodel,icells)
6376
cell_to_pcell = get_cell_to_parent_cell(ownmodel)
6477
facet_to_pfacet = get_face_to_parent_face(ownmodel,D-1)
65-
cutgeo = cut(cutter,ownmodel,args...)
78+
cell_to_facets = lazy_map(Reindex(cell_to_facets),icells)
79+
_cutter = STLCutter(;cell_to_facets,cutter.options...)
80+
cutgeo = cut(_cutter,ownmodel,args...)
6681
cutgeo = change_bgmodel(cutgeo,bgmodel,cell_to_pcell,facet_to_pfacet)
6782
remove_ghost_subfacets(cutgeo,facet_gids)
6883
end
84+
toc!(timers["fine"],"interior")
6985

7086
# Merge discretizations
7187
cuts = map(cuts,icuts,bcells,icells) do bcut,icut,bcells,icells
@@ -87,10 +103,37 @@ function cut(cutter::STLCutter,bgmodel::DistributedDiscreteModel,args...)
87103
# Nearest neighbor communication
88104
consistent_bgcell_to_inoutcut!(cuts,cell_gids)
89105
consistent_bgfacet_to_inoutcut!(cuts,facet_gids)
106+
107+
toc!(timers["global"],"global")
90108
DistributedEmbeddedDiscretization(cuts,bgmodel)
91109
end
92110

93111

112+
function setup_distributed_cutter(a::STLCutter,bgmodel::DistributedDiscreteModel)
113+
parts = map(part_id,get_cell_gids(bgmodel).partition)
114+
timers,options = _setup_distributed_cutter(parts;a.options...)
115+
cutter = STLCutter(;all_defined=false,options...)
116+
timers,cutter
117+
end
118+
119+
function _setup_distributed_cutter(
120+
parts;
121+
verbose=false,
122+
timers=default_timers(parts;verbose),
123+
showprogress=false,
124+
kwargs...)
125+
126+
kwargs = (;showprogress,kwargs...)
127+
timers, kwargs
128+
end
129+
130+
function default_timers(parts;kwargs...)
131+
Dict(
132+
"global" => PTimer(parts;kwargs...),
133+
"coarse" => PTimer(parts;kwargs...),
134+
"fine" => PTimer(parts;kwargs...))
135+
end
136+
94137
"""
95138
find_root_part(cuts::AbstractArray{<:AbstractEmbeddedDiscretization},cells)
96139

‎src/Embedded.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function similar_geometry(a::STLGeometry,tree::Leaf)
3939
STLGeometry(tree)
4040
end
4141

42+
function compute_cell_to_facets(a::DiscreteModel,geo::STLGeometry)
43+
compute_cell_to_facets(get_grid(a),STL(get_stl(geo)))
44+
end
45+
4246
function closest_point(x::AbstractVector,geo::STLGeometry,args...)
4347
closest_point(x,get_stl(geo),args...)
4448
end

‎src/SubTriangulations.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ end
6060
- `:both`: retunrs boths `:interior` and `:exterior` `face_grid`. It must be filtered (only used for debugging purposes).
6161
- `showprogress`: (default `true`) show progress bar
6262
- `all_defined`: (default `true`) if `true` all cells are defined as `IN`, `OUT` or `CUT`. If `false` undefined cells are allowed (only used for distributed meshes)
63+
- `cell_to_facets`: (default [`compute_cell_to_facets`](@ref)) precomputed cell to stl facets mapping.
6364
"""
6465
function subtriangulate(
6566
bgmodel::DiscreteModel,
@@ -68,24 +69,23 @@ function subtriangulate(
6869
tolfactor=DEFAULT_TOL_FACTOR,
6970
surfacesource=:skin,
7071
showprogress=true,
71-
all_defined=true)
72+
all_defined=true,
73+
cell_to_facets=compute_cell_to_facets(bgmodel,STL(stlmodel)))
7274
# cutfacets = false)
7375

7476
grid = get_grid(bgmodel)
75-
grid_topology = get_grid_topology(bgmodel)
7677
p = get_polytope(only(get_reffes(bgmodel)))
7778
node_to_coords = get_node_coordinates(grid)
7879
cell_to_nodes = get_cell_node_ids(grid)
7980
stl = STL(stlmodel)
80-
D = num_dims(grid)
8181
atol = eps(grid)*tolfactor
8282

8383
f_to_isempty = get_facet_to_isempty(stl;atol)
8484
Πf = get_facet_planes(stl)
8585
Πf = correct_small_facets_planes!(stl,Πf,f_to_isempty;atol)
8686
Πr = get_reflex_planes(stl,Πf)
8787

88-
c_to_stlf = compute_cell_to_facets(grid,stl)
88+
c_to_stlf = cell_to_facets
8989

9090
Γ0 = Polyhedron(stl)
9191

‎test/DistributedTests/CutterTests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function main(distribute;
2424
end
2525

2626
ranks = distribute(LinearIndices((prod(np),)))
27+
28+
timers = STLCutters.default_timers(ranks)
29+
2730
geo = STLGeometry(filename)
2831

2932
pmin,pmax = get_bounding_box(geo)
@@ -35,9 +38,13 @@ function main(distribute;
3538
bgmodel = simplexify(bgmodel,positive=true)
3639
end
3740

38-
cutter = STLCutter(;tolfactor)
41+
cutter = STLCutter(;tolfactor,timers)
3942
cutgeo = cut(cutter,bgmodel,geo)
4043

44+
display(timers["coarse"])
45+
display(timers["fine"])
46+
display(timers["global"])
47+
4148
Ωbg = Triangulation(bgmodel)
4249
Ωin = Triangulation(cutgeo,PHYSICAL_IN)
4350
Ωout = Triangulation(cutgeo,PHYSICAL_OUT)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
include("../CutterTests.jl")
3+
include("../Poisson.jl")
4+
5+
function all_tests(distribute,parts)
6+
ranks = distribute(LinearIndices((prod(parts),)))
7+
8+
t = PArrays.PTimer(ranks,verbose=true)
9+
PArrays.tic!(t)
10+
11+
DistributedCutterTests.main(distribute,np=parts,nc=(4,4,4))
12+
DistributedCutterTests.main(distribute,np=parts,nc=(8,8,8))
13+
DistributedCutterTests.main(distribute,np=parts,nc=(4,4,4),simplex=true)
14+
DistributedCutterTests.main(distribute,np=parts,nc=(8,8,8),simplex=true)
15+
PArrays.toc!(t,"MPIDistributedCutter")
16+
17+
DistributedPoissonTests.main(distribute,np=parts,nc=(4,4,4))
18+
DistributedPoissonTests.main(distribute,np=parts,nc=(8,8,8))
19+
DistributedPoissonTests.main(distribute,np=parts,nc=(8,8,8),geoname="Bunny-LowPoly")
20+
PArrays.toc!(t,"MPIDistributedPoisson")
21+
22+
display(t)
23+
end

‎test/DistributedTests/mpi/runtests_body.jl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,12 @@ using PartitionedArrays
44
const PArrays = PartitionedArrays
55
using MPI
66

7-
include("../CutterTests.jl")
8-
include("../Poisson.jl")
7+
include("all_tests.jl")
98

109
if ! MPI.Initialized()
1110
MPI.Init()
1211
end
1312

14-
function all_tests(distribute,parts)
15-
ranks = distribute(LinearIndices((prod(parts),)))
16-
17-
t = PArrays.PTimer(ranks,verbose=true)
18-
PArrays.tic!(t)
19-
20-
DistributedCutterTests.main(distribute,np=parts,nc=(4,4,4))
21-
DistributedCutterTests.main(distribute,np=parts,nc=(8,8,8))
22-
DistributedCutterTests.main(distribute,np=parts,nc=(4,4,4),simplex=true)
23-
DistributedCutterTests.main(distribute,np=parts,nc=(8,8,8),simplex=true)
24-
PArrays.toc!(t,"MPIDistributedCutter")
25-
26-
DistributedPoissonTests.main(distribute,np=parts,nc=(4,4,4))
27-
DistributedPoissonTests.main(distribute,np=parts,nc=(8,8,8))
28-
DistributedPoissonTests.main(distribute,np=parts,nc=(8,8,8),geoname="Bunny-LowPoly")
29-
PArrays.toc!(t,"MPIDistributedPoisson")
30-
31-
display(t)
32-
end
33-
3413
if MPI.Comm_size(MPI.COMM_WORLD) == 8
3514
with_mpi() do distribute
3615
all_tests(distribute,(2,2,2))

0 commit comments

Comments
 (0)