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

Make @showprogress update on inner loop when using nested loops #239

Open
nbsmokee opened this issue May 19, 2022 · 4 comments
Open

Make @showprogress update on inner loop when using nested loops #239

nbsmokee opened this issue May 19, 2022 · 4 comments

Comments

@nbsmokee
Copy link

I like the @showprogress macro very much, though I think it does not work well with nested loops. What I mean: I would expect the progress bar created with

@showprogress for j in 1:10, i in 1:10
    sleep(.1)
end

to behave exactly like

@showprogress for ij in 1:100
    sleep(.1)
end

, ie filling up with 1-percent increments. Instead, the progress bar from the first example fills up with 10-percent increments, ie is analogous to

@showprogress for j in 1:10
    for i in 1:10
        sleep(.1)
    end
end

I am not sure if this is possible, but I think in such cases it would be very nice to have the macro determine the overall number of iterations of the innermost loop in order to have less waiting time between updates.

@axsk
Copy link

axsk commented Mar 27, 2023

While this would certainly be nice to have, this can be solved manually by setting up aProgress(10*10) and calling next! in the inner loop.

@affans
Copy link

affans commented Aug 11, 2024

Has their been any update on this? One key usage here is the ability of long-running tasks on parallel workers report their progress, something like

n_steps = 4
    p = Progress(n_steps)
    progress_pmap(1:4; progress=p) do x
        sumval = 0 
        for x in 1:100
            sleep(0.1)
            sumval += x
            # update the progress meter here
        end 
        sumval^2
    end

Looking at the source code, this is not currently possible since

 # map task
        @sync begin
            vals = mapfun(other_args...; kwargs...) do x...
                val = f(x...)
                put!(channel, true)
                yield()
                return val
            end
            put!(channel, false)
        end

the put!() happens outside the function f. If I manually add put! inside f, it errors:

julia> runpmap()
ERROR: On worker 4:
UndefVarError: `channel` not defined

@MarcMush
Copy link
Collaborator

MarcMush commented Aug 12, 2024

By using the example in the readme and using put! in the inner loop:

p = Progress(4*100)
channel = RemoteChannel(() -> Channel{Bool}(), 1)

@async while take!(channel) next!(p) end

pmap(1:4) do x
    sumval = 0 
    for i in 1:100
        sleep(0.1)
        sumval += i
        put!(channel, true)
    end 
    sumval^2
end
put!(channel, false)

@MarcMush
Copy link
Collaborator

alternatively, with #157 (not yet merged)

]add ProgressMeter#5c21f5d

using Distributed
addprocs(4)
@everywhere using ProgressMeter
p = ParallelProgress(4*100)

pmap(1:4) do x
    sumval = 0 
    for i in 1:100
        sleep(0.1)
        sumval += i
        next!(p)
    end 
    sumval^2
end

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

No branches or pull requests

4 participants