ProgressLogging.jl
ProgressLogging.jl copied to clipboard
Incremental progress logging
Would be nice to support logging progress increments, so that e.g. something like
@withprogress name="threaded iteration" begin
Threads.@threads for i in 1:12
sleep(2)
@logprogress increment = 1/12
end
end
works.
Here's what I do to make this work:
mutable struct Prog
N::Int
@atomic count::Int
end
Prog(N) = Prog(N, 0)
inc!(p::Prog) = @atomic p.count += 1
macro inc(p)
quote
local M = $inc!($p) # It seems to be important to separate this out from the `@logprogress` step since `@logprogress` can double-evaluate
$ProgressLogging.@logprogress M / $p.N
end |> esc
end
and then
using OhMyThreads: tforeach
p = Prog(N)
@withprogress tforeach(1:N) do i
sleep(2)
@inc p
end