diff --git a/src/callbacks/callbacks.jl b/src/callbacks/callbacks.jl index deb5606a5cc..9394ffed9ce 100644 --- a/src/callbacks/callbacks.jl +++ b/src/callbacks/callbacks.jl @@ -23,29 +23,33 @@ Returns a callback to display simulation information. Adapted from ClimaTimeSteppers.jl #89. """ function display_status_callback!(::Type{tType}) where {tType} - start_time = UInt64(0.0) - prev_time = UInt64(0.0) - prev_t = tType(0.0) - is_first_step = true + start_time = Ref{UInt64}() + prev_time = Ref{UInt64}() + prev_t = Ref{tType}() + is_not_first_step = Ref{Bool}() function affect!(integrator) - # time = time_ns() / 1e9 - # if is_first_step - # is_first_step = false - # start_time = time - # end - - # t_end = maximum(integrator.tstops.valtree) - # nsteps = floor(Int64, t_end / integrator.dt) - - # @info "$(Dates.format(Dates.now(), "HH:MM:SS:ss u d")) \n\ - # Timestep: $(integrator.step) / $(nsteps); Simulation Time: $(integrator.t) seconds \n\ - # Walltime: $(round(time - start_time, digits=4)) seconds; \ - # Time/Step: $(round((time - start_time) / nsteps, digits=4)) seconds \n" - # # Time Remaining: $(prev_time == 0.0 ? "..." : string(round(Int64, (time - prev_time) / (integrator.t - prev_t) * (t_end - integrator.t))) * " seconds")" - - # prev_t = integrator.t - # prev_time = time + time = round(UInt64, time_ns() / 1e9) + if !(is_not_first_step[]) + is_not_first_step[] = true + start_time[] = time + end + + t_end = maximum(integrator.tstops.valtree) + nsteps = floor(Int64, t_end / integrator.dt) + speed = (time - prev_time[]) / (integrator.t - prev_t[]) + eta = speed * (t_end - integrator.t) + + println("$(Dates.format(Dates.now(), "HH:MM:SS:ss u d")) \n\ + Timestep: $(integrator.step) / $(nsteps); \ + Simulation Time: $(integrator.t) seconds \n\ + Walltime: $(round(time - start_time[], digits=4)) seconds; \ + Time/Step: $(round((time - start_time[]) / nsteps, digits=4)) seconds \n\ + # Time Remaining: $(eta == Inf ? "..." : + string(round((time - prev_time[]) / (integrator.t - prev_t[]) * (t_end - integrator.t))) * " seconds")") + + prev_t[] = integrator.t + prev_time[] = time end return affect! end