Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental progress logging #44

Open
pfitzseb opened this issue Sep 3, 2021 · 1 comment
Open

Incremental progress logging #44

pfitzseb opened this issue Sep 3, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@pfitzseb
Copy link
Member

pfitzseb commented Sep 3, 2021

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.

@pfitzseb pfitzseb added the enhancement New feature or request label Sep 3, 2021
@MasonProtter
Copy link

MasonProtter commented Feb 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants