From 0522c3774df47e07967377ff3e1696cff8532f74 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Fri, 7 Jun 2024 13:03:26 +0200 Subject: [PATCH 1/3] Move timers and `@trixi_timeit` to TrixiBase.jl --- examples/n_body/n_body_benchmark_trixi.jl | 4 +-- examples/n_body/n_body_solar_system.jl | 4 +-- src/TrixiParticles.jl | 3 +- src/util.jl | 42 ----------------------- 4 files changed, 6 insertions(+), 47 deletions(-) diff --git a/examples/n_body/n_body_benchmark_trixi.jl b/examples/n_body/n_body_benchmark_trixi.jl index 04c1f1af6..b47f689e7 100644 --- a/examples/n_body/n_body_benchmark_trixi.jl +++ b/examples/n_body/n_body_benchmark_trixi.jl @@ -108,7 +108,7 @@ end filename = tempname() open(filename, "w") do f redirect_stderr(f) do - TrixiParticles.TimerOutputs.disable_debug_timings(TrixiParticles) + TrixiParticles.disable_debug_timings() end end @@ -124,6 +124,6 @@ end # Enable timers again open(filename, "w") do f redirect_stderr(f) do - TrixiParticles.TimerOutputs.enable_debug_timings(TrixiParticles) + TrixiParticles.enable_debug_timings() end end diff --git a/examples/n_body/n_body_solar_system.jl b/examples/n_body/n_body_solar_system.jl index 6fa860089..b4da85aeb 100644 --- a/examples/n_body/n_body_solar_system.jl +++ b/examples/n_body/n_body_solar_system.jl @@ -49,7 +49,7 @@ callbacks = CallbackSet(info_callback, saving_callback) filename = tempname() open(filename, "w") do f redirect_stderr(f) do - TrixiParticles.TimerOutputs.disable_debug_timings(TrixiParticles) + TrixiParticles.disable_debug_timings() end end @@ -63,6 +63,6 @@ sol = solve(ode, SymplecticEuler(), # Enable timers again open(filename, "w") do f redirect_stderr(f) do - TrixiParticles.TimerOutputs.enable_debug_timings(TrixiParticles) + TrixiParticles.enable_debug_timings() end end diff --git a/src/TrixiParticles.jl b/src/TrixiParticles.jl index f170e08d8..2fe865d10 100644 --- a/src/TrixiParticles.jl +++ b/src/TrixiParticles.jl @@ -21,7 +21,8 @@ using SciMLBase: CallbackSet, DiscreteCallback, DynamicalODEProblem, u_modified! using StaticArrays: @SMatrix, SMatrix, setindex using StrideArrays: PtrArray, StaticInt using TimerOutputs: TimerOutput, TimerOutputs, print_timer, reset_timer! -using TrixiBase: trixi_include +using TrixiBase: trixi_include, @trixi_timeit, timer, timeit_debug_enabled, + disable_debug_timings, enable_debug_timings @reexport using PointNeighbors: TrivialNeighborhoodSearch, GridNeighborhoodSearch using PointNeighbors: PointNeighbors, for_particle_neighbor using WriteVTK: vtk_grid, MeshCell, VTKCellTypes, paraview_collection, vtk_save diff --git a/src/util.jl b/src/util.jl index 2dc86a267..f04589947 100644 --- a/src/util.jl +++ b/src/util.jl @@ -26,48 +26,6 @@ function print_startup_message() println(s) end -# Enable debug timings `@trixi_timeit timer() "name" stuff...`. -# This allows us to disable timings completely by executing -# `TimerOutputs.disable_debug_timings(TrixiParticles)` -# and to enable them again by executing -# `TimerOutputs.enable_debug_timings(TrixiParticles)` -timeit_debug_enabled() = true - -# Store main timer for global timing of functions -const main_timer = TimerOutput() - -# Always call timer() to hide implementation details -timer() = main_timer - -# @trixi_timeit timer() "some label" expression -# -# Basically the same as a special case of `@timeit_debug` from -# [TimerOutputs.jl](https://github.com/KristofferC/TimerOutputs.jl), -# but without `try ... finally ... end` block. Thus, it's not exception-safe, -# but it also avoids some related performance problems. Since we do not use -# exception handling in TrixiParticles, that's not really an issue. -# -# Copied from [Trixi.jl](https://github.com/trixi-framework/Trixi.jl). -macro trixi_timeit(timer_output, label, expr) - timeit_block = quote - if timeit_debug_enabled() - local to = $(esc(timer_output)) - local enabled = to.enabled - if enabled - local accumulated_data = $(TimerOutputs.push!)(to, $(esc(label))) - end - local b0 = $(TimerOutputs.gc_bytes)() - local t0 = $(TimerOutputs.time_ns)() - end - local val = $(esc(expr)) - if timeit_debug_enabled() && enabled - $(TimerOutputs.do_accumulate!)(accumulated_data, t0, b0) - $(TimerOutputs.pop!)(to) - end - val - end -end - """ @threaded for ... end From ef33e4550401d802ed9022bd9bdda8fb0560e3c6 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:11:27 +0200 Subject: [PATCH 2/3] Require latest version of TrixiBase.jl --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ea1bc9aa5..bff9874c1 100644 --- a/Project.toml +++ b/Project.toml @@ -42,7 +42,7 @@ SciMLBase = "1, 2" StaticArrays = "1" StrideArrays = "0.1" TimerOutputs = "0.5" -TrixiBase = "0.1" +TrixiBase = "0.1.3" PointNeighbors = "0.2" WriteVTK = "1" julia = "1.9" From e3687deddf72ef38bace0e56c1fbce3dcbd5ae80 Mon Sep 17 00:00:00 2001 From: Erik Faulhaber <44124897+efaulhaber@users.noreply.github.com> Date: Tue, 11 Jun 2024 11:16:24 +0200 Subject: [PATCH 3/3] Fix tests --- test/count_allocations.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/count_allocations.jl b/test/count_allocations.jl index 3b5110ba1..1c597f9a0 100644 --- a/test/count_allocations.jl +++ b/test/count_allocations.jl @@ -45,7 +45,7 @@ function count_rhs_allocations(sol, semi) try # Disable timers, which cause extra allocations - TrixiParticles.TimerOutputs.disable_debug_timings(TrixiParticles) + TrixiParticles.disable_debug_timings() # Disable multithreading, which causes extra allocations return disable_polyester_threads() do @@ -57,7 +57,7 @@ function count_rhs_allocations(sol, semi) end finally # Enable timers again - @invokelatest TrixiParticles.TimerOutputs.enable_debug_timings(TrixiParticles) + @invokelatest TrixiParticles.enable_debug_timings() end end