diff --git a/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl b/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl index 6ef227d882b..92abc0b765c 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_amr_unstructured_flag.jl b/examples/t8code_2d_dgsem/elixir_advection_amr_unstructured_flag.jl index d19b9230c5c..97250074e31 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_amr_unstructured_flag.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_amr_unstructured_flag.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_basic.jl b/examples/t8code_2d_dgsem/elixir_advection_basic.jl index 648661898ec..36fececcc7a 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_basic.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_basic.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_extended.jl b/examples/t8code_2d_dgsem/elixir_advection_extended.jl index 27f271e9870..95793a309ef 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_extended.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_extended.jl @@ -1,4 +1,3 @@ - using OrdinaryDiffEq using Trixi @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_nonconforming_flag.jl b/examples/t8code_2d_dgsem/elixir_advection_nonconforming_flag.jl index 66e38555d75..76b82a3a712 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_nonconforming_flag.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_nonconforming_flag.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_restart.jl b/examples/t8code_2d_dgsem/elixir_advection_restart.jl index 4f5d29de318..bd6f4c663de 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_restart.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_restart.jl @@ -1,4 +1,3 @@ - using OrdinaryDiffEq using Trixi @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl b/examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl index 56a2e5b2abc..3e1a35581d5 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_restart_amr.jl @@ -1,4 +1,3 @@ - using OrdinaryDiffEq using Trixi @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_advection_unstructured_flag.jl b/examples/t8code_2d_dgsem/elixir_advection_unstructured_flag.jl index f13f0fae05a..aed6c755d5c 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_unstructured_flag.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_unstructured_flag.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_euler_free_stream.jl b/examples/t8code_2d_dgsem/elixir_euler_free_stream.jl index 349678f1637..b2d49e3ccfe 100644 --- a/examples/t8code_2d_dgsem/elixir_euler_free_stream.jl +++ b/examples/t8code_2d_dgsem/elixir_euler_free_stream.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_euler_sedov.jl b/examples/t8code_2d_dgsem/elixir_euler_sedov.jl index e8ec3a7a9e6..fae7d818ad8 100644 --- a/examples/t8code_2d_dgsem/elixir_euler_sedov.jl +++ b/examples/t8code_2d_dgsem/elixir_euler_sedov.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_euler_shockcapturing_ec.jl b/examples/t8code_2d_dgsem/elixir_euler_shockcapturing_ec.jl index a7d10006593..2a0c4a6ee20 100644 --- a/examples/t8code_2d_dgsem/elixir_euler_shockcapturing_ec.jl +++ b/examples/t8code_2d_dgsem/elixir_euler_shockcapturing_ec.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_flag.jl b/examples/t8code_2d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_flag.jl index 9f9ad16dc9b..19502f1ce0e 100644 --- a/examples/t8code_2d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_flag.jl +++ b/examples/t8code_2d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_flag.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_euler_weak_blast_wave_amr.jl b/examples/t8code_2d_dgsem/elixir_euler_weak_blast_wave_amr.jl index a3366caa317..b8dbf94ac0c 100644 --- a/examples/t8code_2d_dgsem/elixir_euler_weak_blast_wave_amr.jl +++ b/examples/t8code_2d_dgsem/elixir_euler_weak_blast_wave_amr.jl @@ -1,4 +1,3 @@ - using OrdinaryDiffEq using Trixi @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_eulergravity_convergence.jl b/examples/t8code_2d_dgsem/elixir_eulergravity_convergence.jl index 2fdb624593c..0fe308701b5 100644 --- a/examples/t8code_2d_dgsem/elixir_eulergravity_convergence.jl +++ b/examples/t8code_2d_dgsem/elixir_eulergravity_convergence.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_mhd_alfven_wave.jl b/examples/t8code_2d_dgsem/elixir_mhd_alfven_wave.jl index 04c36dd8642..e184cb3fd05 100644 --- a/examples/t8code_2d_dgsem/elixir_mhd_alfven_wave.jl +++ b/examples/t8code_2d_dgsem/elixir_mhd_alfven_wave.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_mhd_rotor.jl b/examples/t8code_2d_dgsem/elixir_mhd_rotor.jl index fa8d27a01b4..5dcea4d3150 100644 --- a/examples/t8code_2d_dgsem/elixir_mhd_rotor.jl +++ b/examples/t8code_2d_dgsem/elixir_mhd_rotor.jl @@ -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) diff --git a/examples/t8code_2d_dgsem/elixir_shallowwater_source_terms.jl b/examples/t8code_2d_dgsem/elixir_shallowwater_source_terms.jl index 0a937664493..688ddb2dbb5 100644 --- a/examples/t8code_2d_dgsem/elixir_shallowwater_source_terms.jl +++ b/examples/t8code_2d_dgsem/elixir_shallowwater_source_terms.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_advection_amr.jl b/examples/t8code_3d_dgsem/elixir_advection_amr.jl index 7db6bbc3366..44c796163c1 100644 --- a/examples/t8code_3d_dgsem/elixir_advection_amr.jl +++ b/examples/t8code_3d_dgsem/elixir_advection_amr.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_advection_amr_unstructured_curved.jl b/examples/t8code_3d_dgsem/elixir_advection_amr_unstructured_curved.jl index 45daaf0fbb2..fdea156e222 100644 --- a/examples/t8code_3d_dgsem/elixir_advection_amr_unstructured_curved.jl +++ b/examples/t8code_3d_dgsem/elixir_advection_amr_unstructured_curved.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_advection_basic.jl b/examples/t8code_3d_dgsem/elixir_advection_basic.jl index 415a9e78ba2..ae97a73d182 100644 --- a/examples/t8code_3d_dgsem/elixir_advection_basic.jl +++ b/examples/t8code_3d_dgsem/elixir_advection_basic.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_advection_nonconforming.jl b/examples/t8code_3d_dgsem/elixir_advection_nonconforming.jl index f12c760bb1b..0755a76ef45 100644 --- a/examples/t8code_3d_dgsem/elixir_advection_nonconforming.jl +++ b/examples/t8code_3d_dgsem/elixir_advection_nonconforming.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_advection_restart.jl b/examples/t8code_3d_dgsem/elixir_advection_restart.jl index 83290c6014a..4c72a0b3ee3 100644 --- a/examples/t8code_3d_dgsem/elixir_advection_restart.jl +++ b/examples/t8code_3d_dgsem/elixir_advection_restart.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_advection_unstructured_curved.jl b/examples/t8code_3d_dgsem/elixir_advection_unstructured_curved.jl index 9b8e8825672..400a3cca9c0 100644 --- a/examples/t8code_3d_dgsem/elixir_advection_unstructured_curved.jl +++ b/examples/t8code_3d_dgsem/elixir_advection_unstructured_curved.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_ec.jl b/examples/t8code_3d_dgsem/elixir_euler_ec.jl index 2e13f7edd57..e75b0f69636 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_ec.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_ec.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_free_stream.jl b/examples/t8code_3d_dgsem/elixir_euler_free_stream.jl index daf431a86ef..d45de658cc0 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_free_stream.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_free_stream.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_free_stream_extruded.jl b/examples/t8code_3d_dgsem/elixir_euler_free_stream_extruded.jl index 19cdea7ee3c..d24512a4cdd 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_free_stream_extruded.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_free_stream_extruded.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_sedov.jl b/examples/t8code_3d_dgsem/elixir_euler_sedov.jl index 9f42ad24ac7..f897249ed2e 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_sedov.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_sedov.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_curved.jl b/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_curved.jl index 1346f603608..4b87b646df9 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_curved.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonconforming_unstructured_curved.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonperiodic.jl b/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonperiodic.jl index 612b1640239..ce1662c8e50 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonperiodic.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_source_terms_nonperiodic.jl @@ -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) diff --git a/examples/t8code_3d_dgsem/elixir_euler_weak_blast_wave_amr.jl b/examples/t8code_3d_dgsem/elixir_euler_weak_blast_wave_amr.jl index 106b4821144..83641f085c1 100644 --- a/examples/t8code_3d_dgsem/elixir_euler_weak_blast_wave_amr.jl +++ b/examples/t8code_3d_dgsem/elixir_euler_weak_blast_wave_amr.jl @@ -1,4 +1,3 @@ - using OrdinaryDiffEq using Trixi @@ -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) diff --git a/examples/tree_3d_dgsem/elixir_euler_convergence_pure_fv.jl b/examples/tree_3d_dgsem/elixir_euler_convergence_pure_fv.jl index 063053c1255..4789b46dacc 100644 --- a/examples/tree_3d_dgsem/elixir_euler_convergence_pure_fv.jl +++ b/examples/tree_3d_dgsem/elixir_euler_convergence_pure_fv.jl @@ -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); diff --git a/src/auxiliary/t8code.jl b/src/auxiliary/t8code.jl index ddc0a2f1399..7b7d0bd2f78 100644 --- a/src/auxiliary/t8code.jl +++ b/src/auxiliary/t8code.jl @@ -1,3 +1,10 @@ +# Minimal reference tracker holding active t8code related objects +# created throughout the life time of a Julia session. t8code objects +# should remove themselves from the tracker when they get finalized. +if !@isdefined(__T8CODE_OBJECT_TRACKER) + __T8CODE_OBJECT_TRACKER = Set() +end + """ init_t8code() @@ -33,9 +40,14 @@ function init_t8code() end MPI.add_finalize_hook!() do + # Finalize all registered t8code objects before MPI shuts down. + for obj in __T8CODE_OBJECT_TRACKER + finalize(unsafe_pointer_to_objref(obj)) + end + 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 diff --git a/src/meshes/t8code_mesh.jl b/src/meshes/t8code_mesh.jl index 0d16101257f..5bd9cee5b61 100644 --- a/src/meshes/t8code_mesh.jl +++ b/src/meshes/t8code_mesh.jl @@ -52,8 +52,16 @@ mutable struct T8codeMesh{NDIMS, RealT <: Real, IsParallel, NDIMSP2, NNODES} <: # necessary in order to avoid MPI-related error output when closing # the Julia program/session. t8_forest_unref(Ref(mesh.forest)) + + # Remove this mesh object from the object tracker. + delete!(__T8CODE_OBJECT_TRACKER, pointer_from_objref(mesh)) end + # Get the memory address of the mesh object as a `Ptr`. + # The existence of the resulting `Ptr` will not protect + # the object from garbage collection, which is intentional. + push!(__T8CODE_OBJECT_TRACKER, pointer_from_objref(mesh)) + return mesh end end