Skip to content

Commit ed08673

Browse files
committed
Add status callback
1 parent dc7dd38 commit ed08673

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

config/default_configs/default_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ dt_save_restart:
153153
dt_save_to_sol:
154154
help: "Time between saving solution. Examples: [`10days`, `1hours`, `Inf` (do not save)]"
155155
value: "1days"
156+
dt_show_progress:
157+
help: "Time between displaying progress update"
158+
value: "600secs"
156159
moist:
157160
help: "Moisture model [`dry` (default), `equil`, `non_equil`]"
158161
value: "dry"

src/callbacks/callbacks.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,47 @@ import ClimaCore.Fields: ColumnField
1616

1717
include("callback_helpers.jl")
1818

19+
"""
20+
display_status_callback!(::Type{tType})
21+
22+
Given typeof(dt), returns a callback to display:
23+
- percentage of work completed,
24+
- total wallclock time elapsed,
25+
- estimated wallclock time remaining.
26+
Adapted from ClimaTimeSteppers.jl #89.
27+
"""
28+
function display_status_callback!(::Type{tType}) where {tType}
29+
start_time = Ref{Float64}()
30+
prev_time = Ref{Float64}()
31+
current_time = Ref{Float64}()
32+
prev_t = Ref{tType}()
33+
# milliseconds
34+
speed = Ref{Float64}()
35+
eta = Ref{Float64}()
36+
is_first_step = Ref{Bool}(true)
37+
38+
return function (integrator)
39+
# speed = wallclock time / simulation time
40+
# Print ETA = speed * remaining simulation time
41+
t = integrator.t
42+
t_end = integrator.p.simulation.t_end
43+
current_time[] = round(time_ns()) / 1e9
44+
speed[] = (current_time[] - prev_time[]) / (t - prev_t[])
45+
eta[] = speed[] * (t_end - t)
46+
if is_first_step[]
47+
println("Time Remaining: ...")
48+
is_first_step[] = false
49+
start_time[] = current_time[]
50+
else
51+
println(Dates.now())
52+
println("$(round(t / t_end * 100, digits=2))% complete in $(round(current_time[] - start_time[], digits=2)) seconds")
53+
println("Time Remaining: $(round(eta[], digits=2)) seconds")
54+
end
55+
prev_t[] = t
56+
prev_time[] = current_time[]
57+
end
58+
end
59+
1960
function dss_callback!(integrator)
2061
Y = integrator.u
2162
ghost_buffer = integrator.p.ghost_buffer

src/solver/type_getters.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,18 @@ function get_callbacks(parsed_args, simulation, atmos, params)
491491
(callbacks..., call_every_dt(save_restart_func, dt_save_restart))
492492
end
493493

494+
dt_show_progress = time_to_seconds(parsed_args["dt_show_progress"])
495+
if !(dt_show_progress == Inf)
496+
callbacks = (
497+
callbacks...,
498+
call_every_dt(
499+
display_status_callback!(typeof(dt)),
500+
dt_show_progress;
501+
skip_first = true,
502+
),
503+
)
504+
end
505+
494506
if is_distributed(simulation.comms_ctx)
495507
callbacks = (
496508
callbacks...,

0 commit comments

Comments
 (0)