Skip to content

Commit

Permalink
Merge #482
Browse files Browse the repository at this point in the history
482: Use integrator interface, add flame script r=charleskawczynski a=charleskawczynski

This PR adds a flame script to the repo, and changes the monitored drivers to use OrdinaryDiffEq.jl's integrator interface. This should help make the analysis a bit more streamlined.

Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Jan 27, 2022
2 parents d1e76c7 + ba9848c commit 4a69113
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ docs/src/tutorials/


*.gif
*.gz
*.mp4
*.png
12 changes: 7 additions & 5 deletions examples/3dsphere/baroclinic_wave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,7 @@ end
dt = 5
prob = ODEProblem(rhs!, Y, (0.0, time_end))

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev solve(
integrator = OrdinaryDiffEq.init(
prob,
SSPRK33(),
dt = dt,
Expand All @@ -330,6 +326,12 @@ sol = @timev solve(
progress_message = (dt, u, p, t) -> t,
)

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev OrdinaryDiffEq.solve!(integrator)

# visualization artifacts
if test_name == "baroclinic_wave"
@info "Solution L₂ norm at time t = 0: ", norm(Y.Yc.ρe)
Expand Down
14 changes: 8 additions & 6 deletions examples/3dsphere/solid_body_rotation_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,7 @@ T = 3600
dt = 5
prob = ODEProblem(rhs!, Y, (0.0, T))

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

# solve ode
sol = solve(
integrator = OrdinaryDiffEq.init(
prob,
SSPRK33(),
dt = dt,
Expand All @@ -279,6 +274,13 @@ sol = solve(
progress_message = (dt, u, p, t) -> t,
)

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

# solve ode
sol = @timev OrdinaryDiffEq.solve!(integrator)

uₕ_phy = Geometry.transform.(Ref(Geometry.UVAxis()), sol.u[end].uₕ)
w_phy = Geometry.transform.(Ref(Geometry.WAxis()), sol.u[end].w)

Expand Down
12 changes: 7 additions & 5 deletions examples/hybrid/bubble_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ using OrdinaryDiffEq
Δt = 0.03
prob = ODEProblem(rhs!, Y, (0.0, 500.0))

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev solve(
integrator = OrdinaryDiffEq.init(
prob,
SSPRK33(),
dt = Δt,
Expand All @@ -308,6 +304,12 @@ sol = @timev solve(
progress_message = (dt, u, p, t) -> t,
);

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev OrdinaryDiffEq.solve!(integrator)

ENV["GKSwstype"] = "nul"
using ClimaCorePlots, Plots
Plots.GRBackend()
Expand Down
13 changes: 7 additions & 6 deletions examples/hybrid/bubble_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,7 @@ rhs!(dYdt, Y, nothing, 0.0);
using OrdinaryDiffEq
Δt = 0.05
prob = ODEProblem(rhs!, Y, (0.0, 1.0))

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev solve(
integrator = OrdinaryDiffEq.init(
prob,
SSPRK33(),
dt = Δt,
Expand All @@ -317,6 +312,12 @@ sol = @timev solve(
progress_message = (dt, u, p, t) -> t,
);

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev OrdinaryDiffEq.solve!(integrator)

ENV["GKSwstype"] = "nul"
import Plots
Plots.GRBackend()
Expand Down
14 changes: 8 additions & 6 deletions examples/sphere/shallow_water.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ClimaCore:
Domains, Fields, Geometry, Meshes, Operators, Spaces, Topologies

import QuadGK
import OrdinaryDiffEq
using OrdinaryDiffEq: ODEProblem, solve, SSPRK33

import Logging
Expand Down Expand Up @@ -401,12 +402,7 @@ dt = 9 * 60
T = 86400 * 2

prob = ODEProblem(rhs!, Y, (0.0, T), parameters)

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev solve(
integrator = OrdinaryDiffEq.init(
prob,
SSPRK33(),
dt = dt,
Expand All @@ -416,6 +412,12 @@ sol = @timev solve(
progress_message = (dt, u, p, t) -> t,
)

if haskey(ENV, "CI_PERF_SKIP_RUN") # for performance analysis
throw(:exit_profile)
end

sol = @timev OrdinaryDiffEq.solve!(integrator)

@info "Test case: $(test_name)"
@info " with α: $(test_angle_name)"
@info "Solution L₂ norm at time t = 0: ", norm(Y.h)
Expand Down
24 changes: 3 additions & 21 deletions perf/allocs_per_case.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,6 @@ catch err
end
end

if @isdefined integrator
OrdinaryDiffEq.step!(integrator) # compile first
Profile.clear_malloc_data()
OrdinaryDiffEq.step!(integrator)
else
if @isdefined parameters
rhs!(dYdt, Y, parameters, 0.0) # compile first
Profile.clear_malloc_data()
rhs!(dYdt, Y, parameters, 0.0)
else
rhs!(dYdt, Y, nothing, 0.0) # compile first
Profile.clear_malloc_data()
rhs!(dYdt, Y, nothing, 0.0)
end
end

# Quit julia (which generates .mem files), then call
#=
import Coverage
allocs = Coverage.analyze_malloc("src")
=#
OrdinaryDiffEq.step!(integrator) # compile first
Profile.clear_malloc_data()
OrdinaryDiffEq.step!(integrator)
33 changes: 33 additions & 0 deletions perf/flame.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Pkg
Pkg.develop(path = ".")

mod_dir(x) = dirname(dirname(pathof(x)))
import Profile

ENV["CI_PERF_SKIP_RUN"] = true # we only need haskey(ENV, "CI_PERF_SKIP_RUN") == true

import ClimaCore
pkg_dir = mod_dir(ClimaCore)

filename = joinpath(pkg_dir, "examples", "hybrid", "bubble_2d.jl")
# filename = joinpath(pkg_dir, "examples", "3dsphere", "baroclinic_wave_rho_etot.jl")

try
include(filename)
catch err
if err.error !== :exit_profile
rethrow(err.error)
end
end

OrdinaryDiffEq.step!(integrator) # compile first
Profile.clear_malloc_data()
prof = Profile.@profile begin
for _ in 1:5
OrdinaryDiffEq.step!(integrator)
end
end

import PProf
PProf.pprof()
# http://localhost:57599/ui/flamegraph?tf

0 comments on commit 4a69113

Please sign in to comment.