Skip to content

Commit

Permalink
Fix: Automatically finalize t8code objects when Trixi.jl shuts down (#…
Browse files Browse the repository at this point in the history
…2172)

* Fixing shutodnwo order issue with t8code.

* Applied formatter.

* Update src/auxiliary/t8code.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/auxiliary/t8code.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Extending to MPI support.

* Outsourcing t8code clean up logic to T8code.jl.

* Bumping t8code.jl version.

* Refining code with new ForestWrapper.

* Adding new tests.

* Applied formatter.

* Fixed typo.

* Fixing type method dispatch error.

* Added dummy variable to test.

* Fixed typo.

* Updating function calls.

* Removed unknown variable.

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/solvers/dgsem_t8code/containers_2d.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/solvers/dgsem_t8code/containers_2d.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/solvers/dgsem_t8code/containers_3d.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/solvers/dgsem_t8code/containers_3d.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: Joshua Lampert <[email protected]>

* Update src/meshes/t8code_mesh.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Disabling test.

* Deleted failing forest wrapper test since it leads to segfaults in the Github CI.

* Removing ForestWrapper test alltogether.

* Update test/runtests.jl

Co-authored-by: Joshua Lampert <[email protected]>

---------

Co-authored-by: Johannes Markert <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Joshua Lampert <[email protected]>
Co-authored-by: Hendrik Ranocha <[email protected]>
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
  • Loading branch information
6 people authored Dec 3, 2024
1 parent 2edf9cd commit 9c69e10
Show file tree
Hide file tree
Showing 34 changed files with 110 additions and 188 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ StaticArrays = "1.5"
StrideArrays = "0.1.26"
StructArrays = "0.6.11"
SummationByPartsOperators = "0.5.41"
T8code = "0.7"
T8code = "0.7.2"
TimerOutputs = "0.5.7"
Triangulate = "2.2"
TriplotBase = "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
save_everystep = false, callback = callbacks);

summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_advection_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
5 changes: 0 additions & 5 deletions examples/t8code_2d_dgsem/elixir_advection_extended.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using OrdinaryDiffEq
using Trixi

Expand Down Expand Up @@ -83,7 +82,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
5 changes: 0 additions & 5 deletions examples/t8code_2d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using OrdinaryDiffEq
using Trixi

Expand Down Expand Up @@ -41,7 +40,3 @@ load_timestep!(integrator, restart_filename)

sol = solve!(integrator)
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
5 changes: 0 additions & 5 deletions examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using OrdinaryDiffEq
using Trixi

Expand Down Expand Up @@ -60,7 +59,3 @@ load_timestep!(integrator, restart_filename)

sol = solve!(integrator)
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary.
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_euler_free_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_euler_sedov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_euler_shockcapturing_ec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
5 changes: 0 additions & 5 deletions examples/t8code_2d_dgsem/elixir_euler_weak_blast_wave_amr.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using OrdinaryDiffEq
using Trixi

Expand Down Expand Up @@ -108,7 +107,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);#, maxiters=4);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_eulergravity_convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
println("Number of gravity subcycles: ", semi.gravity_counter.ncalls_since_readout)

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_mhd_alfven_wave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_mhd_rotor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_2d_dgsem/elixir_shallowwater_source_terms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ callbacks = CallbackSet(summary_callback, analysis_callback, alive_callback, sav
sol = solve(ode, RDPK3SpFSAL49(); abstol = 1.0e-8, reltol = 1.0e-8,
ode_default_options()..., callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_advection_amr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_advection_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_advection_nonconforming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_advection_restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,3 @@ load_timestep!(integrator, restart_filename)

sol = solve!(integrator)
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),

# Print the timer summary
summary_callback()

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_euler_ec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_euler_free_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_euler_free_stream_extruded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false), #maxiters=1
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
4 changes: 0 additions & 4 deletions examples/t8code_3d_dgsem/elixir_euler_sedov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
5 changes: 0 additions & 5 deletions examples/t8code_3d_dgsem/elixir_euler_weak_blast_wave_amr.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using OrdinaryDiffEq
using Trixi

Expand Down Expand Up @@ -110,7 +109,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# Finalize `T8codeMesh` to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh)
5 changes: 0 additions & 5 deletions examples/tree_3d_dgsem/elixir_euler_convergence_pure_fv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,3 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary

# This elixir is also tested with `T8codeMesh` which needs to be finalized
# explicitly. Call finalize to make sure MPI related objects in t8code are
# released before `MPI` finalizes.
!isinteractive() && finalize(mesh);
10 changes: 6 additions & 4 deletions src/auxiliary/t8code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ function init_t8code()
T8code.Libt8.p4est_init(C_NULL, LOG_LEVEL)
end

# Clean up t8code before MPI shuts down.
MPI.add_finalize_hook!() do
T8code.clean_up()
status = T8code.Libt8.sc_finalize_noabort()
if status != 0
@warn("Inconsistent state detected after finalizing t8code. Have you finalized all `T8codeMesh` objects and/or properly freed/un-referenced all t8code related objects?")
@warn("Inconsistent state detected after finalizing t8code.")
end
end

Expand Down Expand Up @@ -96,8 +98,8 @@ end
# \return greater zero if the first entry in `elements` should be refined,
# smaller zero if the family `elements` shall be coarsened,
# zero else.
function adapt_callback(forest,
forest_from,
function adapt_callback(forest::Ptr{t8_forest},
forest_from::Ptr{t8_forest},
which_tree,
lelement_id,
ts,
Expand Down Expand Up @@ -189,7 +191,7 @@ function trixi_t8_adapt!(mesh, indicators)

differences = trixi_t8_get_difference(old_levels, new_levels, 2^ndims(mesh))

mesh.forest = forest_cached
update_forest!(mesh, forest_cached)

return differences
end
Loading

0 comments on commit 9c69e10

Please sign in to comment.