Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move timers and @trixi_timeit to TrixiBase.jl #543

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions examples/n_body/n_body_benchmark_trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions examples/n_body/n_body_solar_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
3 changes: 2 additions & 1 deletion src/TrixiParticles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 0 additions & 42 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/count_allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down