Skip to content

Commit

Permalink
Add status callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Aug 18, 2023
1 parent dc7dd38 commit ed08673
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ dt_save_restart:
dt_save_to_sol:
help: "Time between saving solution. Examples: [`10days`, `1hours`, `Inf` (do not save)]"
value: "1days"
dt_show_progress:
help: "Time between displaying progress update"
value: "600secs"
moist:
help: "Moisture model [`dry` (default), `equil`, `non_equil`]"
value: "dry"
Expand Down
41 changes: 41 additions & 0 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@ import ClimaCore.Fields: ColumnField

include("callback_helpers.jl")

"""
display_status_callback!(::Type{tType})
Given typeof(dt), returns a callback to display:
- percentage of work completed,
- total wallclock time elapsed,
- estimated wallclock time remaining.
Adapted from ClimaTimeSteppers.jl #89.
"""
function display_status_callback!(::Type{tType}) where {tType}
start_time = Ref{Float64}()
prev_time = Ref{Float64}()
current_time = Ref{Float64}()
prev_t = Ref{tType}()
# milliseconds
speed = Ref{Float64}()
eta = Ref{Float64}()
is_first_step = Ref{Bool}(true)

return function (integrator)
# speed = wallclock time / simulation time
# Print ETA = speed * remaining simulation time
t = integrator.t
t_end = integrator.p.simulation.t_end
current_time[] = round(time_ns()) / 1e9
speed[] = (current_time[] - prev_time[]) / (t - prev_t[])
eta[] = speed[] * (t_end - t)
if is_first_step[]
println("Time Remaining: ...")
is_first_step[] = false
start_time[] = current_time[]
else
println(Dates.now())
println("$(round(t / t_end * 100, digits=2))% complete in $(round(current_time[] - start_time[], digits=2)) seconds")
println("Time Remaining: $(round(eta[], digits=2)) seconds")
end
prev_t[] = t
prev_time[] = current_time[]
end
end

function dss_callback!(integrator)
Y = integrator.u
ghost_buffer = integrator.p.ghost_buffer
Expand Down
12 changes: 12 additions & 0 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,18 @@ function get_callbacks(parsed_args, simulation, atmos, params)
(callbacks..., call_every_dt(save_restart_func, dt_save_restart))
end

dt_show_progress = time_to_seconds(parsed_args["dt_show_progress"])
if !(dt_show_progress == Inf)
callbacks = (
callbacks...,
call_every_dt(
display_status_callback!(typeof(dt)),
dt_show_progress;
skip_first = true,
),
)
end

if is_distributed(simulation.comms_ctx)
callbacks = (
callbacks...,
Expand Down

0 comments on commit ed08673

Please sign in to comment.