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

use SnoopPrecompile #1234

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StartUpDG = "472ebc20-7c99-4d4b-9470-8fde4e9faa0f"
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
Expand Down Expand Up @@ -62,6 +63,7 @@ Reexport = "1.0"
Requires = "1.1"
SciMLBase = "1.65"
Setfield = "0.8, 1"
SnoopPrecompile = "1"
StartUpDG = "0.14"
Static = "0.3, 0.4, 0.5, 0.6, 0.7, 0.8"
StaticArrays = "1"
Expand Down
9 changes: 7 additions & 2 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,13 @@ function __init__()
end


include("auxiliary/precompile.jl")
_precompile_manual_()
# Use the old precompile statements on Julia v1.7 and only switch to the newer
# ones based on SnoopPrecompile.jl for Julia v1.8 and newer.
@static if VERSION < v"1.8"
include("auxiliary/precompile_old.jl")
else
include("auxiliary/precompile_new.jl")
end


end
90 changes: 90 additions & 0 deletions src/auxiliary/precompile_new.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This file is used to generate precompile statements. This increases the
# precompilation time but decreases the time to first simulation - at least
# when precompiled methods can be reused.
# See https://timholy.github.io/SnoopCompile.jl/stable/snoop_pc/

using SnoopPrecompile: @precompile_all_calls

@precompile_all_calls begin
# 2D
let
equations = CompressibleEulerEquations2D(1.4)
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)

coordinates_min = (0.0, 0.0)
coordinates_max = (2.0, 2.0)
refinement_patches = (
(type="box", coordinates_min=(0.0, 0.0), coordinates_max=(1.0, 1.0)),
)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level=1,
refinement_patches=refinement_patches,
n_cells_max=100)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test, solver,
source_terms=source_terms_convergence_test)

tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)

du_ode = similar(ode.u0)
Trixi.rhs!(du_ode, ode.u0, semi, tspan[1])

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval)
let u_ode = ode.u0
GC.@preserve u_ode du_ode begin
u = Trixi.wrap_array(u_ode, semi)
du = Trixi.wrap_array(du_ode, semi)
redirect_stdout(devnull) do
analysis_callback.affect!(devnull, du, u, u_ode, first(tspan), semi)
end
end
end

alive_callback = AliveCallback(analysis_interval=analysis_interval)
end

# 3D
let
equations = CompressibleEulerEquations3D(1.4)
solver = DGSEM(polydeg=3, surface_flux=flux_lax_friedrichs)

coordinates_min = (0.0, 0.0, 0.0)
coordinates_max = (2.0, 2.0, 2.0)
refinement_patches = (
(type="box", coordinates_min=(0.0, 0.0, 0.0), coordinates_max=(1.0, 1.0, 1.0)),
)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level=1,
refinement_patches=refinement_patches,
n_cells_max=100)

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition_convergence_test, solver,
source_terms=source_terms_convergence_test)

tspan = (0.0, 2.0)
ode = semidiscretize(semi, tspan)

du_ode = similar(ode.u0)
Trixi.rhs!(du_ode, ode.u0, semi, tspan[1])

summary_callback = SummaryCallback()

analysis_interval = 100
analysis_callback = AnalysisCallback(semi, interval=analysis_interval)
let u_ode = ode.u0
GC.@preserve u_ode du_ode begin
u = Trixi.wrap_array(u_ode, semi)
du = Trixi.wrap_array(du_ode, semi)
redirect_stdout(devnull) do
analysis_callback.affect!(devnull, du, u, u_ode, first(tspan), semi)
end
end
end

alive_callback = AliveCallback(analysis_interval=analysis_interval)
end
end
10 changes: 0 additions & 10 deletions src/auxiliary/precompile.jl → src/auxiliary/precompile_old.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
# Since these FMAs can increase the performance of many numerical algorithms,
# we need to opt-in explicitly.
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
@muladd begin


#=
The code contained in this file is inspired by an analysis performed
using SnoopCompile, although most of it is written manually.
Expand Down Expand Up @@ -476,6 +469,3 @@ function _precompile_manual_()

return nothing
end


end # @muladd