Skip to content

Commit 094909c

Browse files
committed
improvement
1 parent 7d96308 commit 094909c

File tree

2 files changed

+19
-32
lines changed

2 files changed

+19
-32
lines changed

src/callbacks/callbacks.jl

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,38 @@ include("callback_helpers.jl")
2222
Returns a callback to display simulation information.
2323
Adapted from ClimaTimeSteppers.jl #89.
2424
"""
25-
function display_status_callback!()
26-
prev_t = 0.0
27-
t = 0.0
28-
t_end = 0.0
29-
30-
start_time = 0.0
31-
prev_time = 0.0
32-
time = 0.0
33-
eta = 0.0
34-
speed = 0.0
25+
function display_status_callback!(::Type{tType}) where {tType}
26+
start_time = UInt64(0.0)
27+
prev_time = UInt64(0.0)
28+
prev_t = tType(0.0)
29+
eta = tType(0.0)
30+
speed = tType(0.0)
3531
is_first_step = true
3632

37-
step = 0
38-
39-
40-
function initialize(_, _, _, integrator)
41-
end
42-
4333
function affect!(integrator)
44-
t_end = integrator.p.simulation.t_end
45-
nsteps = ceil(Int, t_end / integrator.dt)
46-
# speed = wallclock time / simulation time
47-
# Print ETA = speed * remaining simulation time
34+
t_end = maximum(integrator.tstops.valtree)
35+
nsteps = ceil(Int64, t_end / integrator.dt)
4836
t = integrator.t
37+
step = ceil(Int64, t / integrator.dt)
4938
time = time_ns() / 1e9
5039
speed = (time - prev_time) / (t - prev_t)
5140
eta = speed * (t_end - t)
52-
step += 1
41+
eta_string = eta == Inf ? "..." : string(round(Int64, eta)) * "seconds"
42+
5343
if is_first_step
54-
# @info "Time Remaining: ..."
5544
is_first_step = false
5645
start_time = time
57-
else
58-
@info "$(Dates.format(Dates.now(), "HH:MM:SS:ss u-d")) \n\
59-
Timestep: $(step) / $(nsteps); Simulation Time: $(t) seconds \n\
60-
Walltime: $(round(time - start_time, digits=2)) seconds; \
61-
Time/Step: $(round(speed * integrator.dt, digits=2)) seconds"
62-
# Time Remaining: $(Int64(round(eta))) seconds"
6346
end
47+
@info "$(Dates.format(Dates.now(), "HH:MM:SS:ss u d")) \n\
48+
Timestep: $(step) / $(nsteps); Simulation Time: $(t) seconds \n\
49+
Walltime: $(round(time - start_time, digits=2)) seconds; \
50+
Time/Step: $(round(speed * integrator.dt, digits=2)) seconds \n\
51+
Time Remaining: $eta_string"
52+
6453
prev_t = t
6554
prev_time = time
6655
end
67-
return initialize, affect!
56+
return affect!
6857
end
6958

7059
function dss_callback!(integrator)

src/solver/type_getters.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,12 @@ function get_callbacks(parsed_args, simulation, atmos, params)
503503

504504
dt_show_progress = time_to_seconds(parsed_args["dt_show_progress"])
505505
if !(dt_show_progress == Inf)
506-
initialize, affect! = display_status_callback!()
507506
callbacks = (
508507
callbacks...,
509508
call_every_dt(
510-
affect!,
509+
display_status_callback!(typeof(dt)),
511510
dt_show_progress;
512511
skip_first = true,
513-
initialize,
514512
),
515513
)
516514
end

0 commit comments

Comments
 (0)