Skip to content

Commit 0951257

Browse files
committed
is @info broken???
1 parent cb6815f commit 0951257

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/callbacks/callbacks.jl

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,33 @@ Returns a callback to display simulation information.
2323
Adapted from ClimaTimeSteppers.jl #89.
2424
"""
2525
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-
is_first_step = true
26+
start_time = Ref{UInt64}()
27+
prev_time = Ref{UInt64}()
28+
prev_t = Ref{tType}()
29+
is_not_first_step = Ref{Bool}()
3030

3131
function affect!(integrator)
32-
# time = time_ns() / 1e9
33-
# if is_first_step
34-
# is_first_step = false
35-
# start_time = time
36-
# end
37-
38-
# t_end = maximum(integrator.tstops.valtree)
39-
# nsteps = floor(Int64, t_end / integrator.dt)
40-
41-
# @info "$(Dates.format(Dates.now(), "HH:MM:SS:ss u d")) \n\
42-
# Timestep: $(integrator.step) / $(nsteps); Simulation Time: $(integrator.t) seconds \n\
43-
# Walltime: $(round(time - start_time, digits=4)) seconds; \
44-
# Time/Step: $(round((time - start_time) / nsteps, digits=4)) seconds \n"
45-
# # Time Remaining: $(prev_time == 0.0 ? "..." : string(round(Int64, (time - prev_time) / (integrator.t - prev_t) * (t_end - integrator.t))) * " seconds")"
46-
47-
# prev_t = integrator.t
48-
# prev_time = time
32+
time = round(UInt64, time_ns() / 1e9)
33+
if !(is_not_first_step[])
34+
is_not_first_step[] = true
35+
start_time[] = time
36+
end
37+
38+
t_end = maximum(integrator.tstops.valtree)
39+
nsteps = floor(Int64, t_end / integrator.dt)
40+
speed = (time - prev_time[]) / (integrator.t - prev_t[])
41+
eta = speed * (t_end - integrator.t)
42+
43+
println("$(Dates.format(Dates.now(), "HH:MM:SS:ss u d")) \n\
44+
Timestep: $(integrator.step) / $(nsteps); \
45+
Simulation Time: $(integrator.t) seconds \n\
46+
Walltime: $(round(time - start_time[], digits=4)) seconds; \
47+
Time/Step: $(round((time - start_time[]) / nsteps, digits=4)) seconds \n\
48+
# Time Remaining: $(eta == Inf ? "..." :
49+
string(round((time - prev_time[]) / (integrator.t - prev_t[]) * (t_end - integrator.t))) * " seconds")")
50+
51+
prev_t[] = integrator.t
52+
prev_time[] = time
4953
end
5054
return affect!
5155
end

0 commit comments

Comments
 (0)