-
Notifications
You must be signed in to change notification settings - Fork 93
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
feature request: allow updating of progress bar from functions launched on separate workers. #125
Comments
I tried
but I get
which dosn't make sense to me. According to the source code,
the line |
The reason for the error is that @everywhere channel = RemoteChannel(()->Channel{Bool}(10), 1) will not work because it will create a new channel for each process. I haven't been able to find documentation on this, but apparently anonymous functions like those created with the addprocs(2)
f(x) = x^2
pmap(f, 1:10) will throw an error, but addprocs(2)
f = x -> x^2
pmap(f, 1:10) will work fine. Anyways, workarounds are to (1) pass the channel as an argument to the function, or (2) use main = s-> begin
for i = 1:100
remotecall(put!(channel, true), 1)
sleep(0.01)
end
end Sorry I don't know more about why anonymous functions work differently. |
This might be a bug.. let's see if someone replies on discourse. You should clarify your post that both functions work fine when |
I'll see if I can figure this out over the next few days. This feature would be great for my workflow. |
I have the same feature request. The code in the readme is basically perfect, it would just be nice if all that boilerplate could be hidden inside a parallel progress bar type like, p = DistributedProgress(100)
pmap(1:10) do i
for j=1:10
...
next!(p)
end
end
finish!(p) and the whole |
Actually, I hacked together the following, which allows struct DistributedProgress <: ProgressMeter.AbstractProgress
channel :: RemoteChannel{Channel{Any}}
pbar :: Progress
end
function DistributedProgress(args...; kwargs...)
pbar = Progress(args...; kwargs...)
channel = RemoteChannel(()->Channel(), 1)
@async begin
while (x = take!(channel)) != nothing
func, args, kwargs = x
func(pbar, args...; kwargs...)
end
finish!(pbar)
end
DistributedProgress(channel, pbar)
end
ProgressMeter.next!(pbar::DistributedProgress, args...; kwargs...) = put!(pbar.channel, (ProgressMeter.next!, args, kwargs))
ProgressMeter.update!(pbar::DistributedProgress, args...; kwargs...) = put!(pbar.channel, (ProgressMeter.update!, args, kwargs))
ProgressMeter.finish!(pbar::DistributedProgress, args...; kwargs...) = (put!(pbar.channel, nothing); close(pbar.channel)) |
Absolutely. Please PR and add tests if you can |
Consider this following MWE which works but not as intended.
The intention: Suppose the
simulation
function is a long-running function that can provide it's progress by utilizing the internal for loop. Further suppose thatsimulation
is independently launched on multiple processes bypmap
. The goal is to have a more granular progress bar that gets updated at each iteration in thefor
loop for eachsimulation
. Thus, by a simple calculation the maximum length of a progress bar is of length1000
where each unit of the progress bar is updated by thefor
loop insimulation
. In other words, 10simulation
processes all updating the progress bar through their internal for loops one unit at a time. This allows monitor progress of long running computations.PmapProgressMeters.jl did this by passing
simulation
a callback function that updated theProgress
bar on the main process.However, I am trying to think of a solution involving
Channels
andRemoteChannel
although I don't have the expertise of how this stuff works yet.The text was updated successfully, but these errors were encountered: