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

[RFC] add support for multiple simultaneous progressbars #157

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
13308f8
WIP
MarcMush May 25, 2020
ea86d04
[WIP] working version
MarcMush May 25, 2020
e9e10cf
add test_parallel.jl
MarcMush Jun 25, 2020
5f1bb27
Merge branch 'marc/parallelprogress' into marc/parallel_update
MarcMush Jun 25, 2020
68d4de7
(WIP) add parallel update!
MarcMush Jun 25, 2020
3284c08
first working version
MarcMush Jul 10, 2020
eea66f2
some tidying
MarcMush Aug 12, 2021
7699a87
merge from master
MarcMush Aug 12, 2021
5f2b17c
add parallel support for ProgressTresh and ProgressUnknown
MarcMush Aug 12, 2021
f522aec
add support for no main progressbar in MultipleProgress
MarcMush Aug 12, 2021
f48fb98
fixes
MarcMush Aug 12, 2021
5838982
add tests for MultipleProgress
MarcMush Aug 12, 2021
83123b1
restore tests
MarcMush Aug 12, 2021
fa22215
fixes for julia 0.7
MarcMush Aug 12, 2021
7c64cd2
better error handling and hopefully better codecov
MarcMush Aug 13, 2021
03f8b1c
fix typo
MarcMush Aug 13, 2021
a2a08d9
first working version of multiple progresses from a vector
MarcMush Aug 13, 2021
e90a6a0
on hold
MarcMush Aug 16, 2021
cfa53bc
add support for offset in ProgressUnknown
MarcMush Aug 16, 2021
2c83e23
add support for offset in ProgressUnknown
MarcMush Aug 16, 2021
e27702c
add test for cancel with offset and keep
MarcMush Aug 16, 2021
5023b72
Merge branch 'offsetUnknown' into moremultiple
MarcMush Aug 16, 2021
81608b2
allow any AbstractProgress in MultipleProgress
MarcMush Aug 16, 2021
dac02dd
fixes and doc
MarcMush Aug 16, 2021
191737f
fixes
MarcMush Aug 16, 2021
91a0abf
fix CI hopefully
MarcMush Aug 16, 2021
56827f7
doc changes [skip-ci]
MarcMush Aug 17, 2021
009dd01
merge #216
MarcMush Sep 20, 2021
a5c5b2c
additional sleep time for CI
MarcMush Sep 20, 2021
ce8ff75
fix ParallelProgress example
MarcMush Jun 3, 2023
4cbbf85
change from vector to dict to store and reference progresses
MarcMush Aug 31, 2023
c6721e4
add a test with dicts
MarcMush Aug 31, 2023
5323a17
Merge branch 'master' of https://github.com/timholy/ProgressMeter.jl.…
MarcMush Aug 31, 2023
99df291
add tests for main key error
MarcMush Aug 31, 2023
be0826a
add test for duplicate key
MarcMush Aug 31, 2023
f9ba27a
tweak test
MarcMush Aug 31, 2023
5437ce6
0.7 compat
MarcMush Aug 31, 2023
74f3b95
update README.md
MarcMush Sep 2, 2023
d8977ef
improve codecov
MarcMush Sep 3, 2023
639bceb
fix tests
MarcMush Sep 3, 2023
9a1df84
tests
MarcMush Sep 3, 2023
69b13a1
fix
MarcMush Sep 3, 2023
3156d04
Merge branch 'master'
MarcMush Oct 22, 2023
4330155
Merge branch 'master' into parallelprogress
MarcMush Jul 12, 2024
7094dd3
way too many changes for one commit
MarcMush Jul 13, 2024
5c21f5d
update readme
MarcMush Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 71 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,44 +366,94 @@ remove **all** output from the cell. You can restore previous behavior by callin
`ProgressMeter.ijulia_behavior(:append)`. You can enable it again by calling `ProgressMeter.ijulia_behavior(:clear)`,
which will also disable the warning message.

### Tips for parallel programming
### Parallel programming with `ParallelProgress`

For remote parallelization, when multiple processes or tasks are being used for a computation,
the workers should communicate back to a single task for displaying the progress bar. This
can be accomplished with a `RemoteChannel`:
`ParallelProgress` wraps an `AbstractProgress` to allow updating from other workers,
by going through a `RemoteChannel`

```julia
using ProgressMeter
using Distributed
addprocs(2)
@everywhere using ProgressMeter

n_steps = 20
p = Progress(n_steps)
channel = RemoteChannel(() -> Channel{Bool}(), 1)
p = ParallelProgress(n_steps)

# introduce a long-running dummy task to all workers
@everywhere long_task() = sum([ 1/x for x in 1:100_000_000 ])
@time long_task() # a single execution is about 0.3 seconds

@sync begin # start two tasks which will be synced in the very end
# the first task updates the progress bar
@async while take!(channel)
next!(p)
@distributed (+) for i in 1:n_steps
long_task()
next!(p)
i^2
end

finish!(p)
```

Here, returning some number `i^2` and reducing it somehow `(+)`is necessary to make the distribution happen.
`finish!(p)` or `close(p)` makes sure that the underlying `Channel` is closed

```julia
pu = ParallelProgress(ProgressUnknown(color=:red))
pt = ParallelProgress(ProgressThresh(0.1, desc="Optimizing..."))
close(pu)
close(pt)
```

### Mutliple progressbars across multiple workers with `MutlipleProgress`

`MultipleProgress` combines multiple progressbars, allowing them to update simultaneously across multiple workers

```julia
using Distributed
addprocs(2)
@everywhere using ProgressMeter

progs = [Progress(10; desc="task $i ") for i in 1:5]
mainprog = Progress(50; desc="global ")
p = MultipleProgress(progs, mainprog)
res = pmap(1:5) do i
for _ in 1:10
sleep(rand())
next!(p[i])
end
sleep(0.01)
myid()
end
close(p)
```

# the second task does the computation
@async begin
@distributed (+) for i in 1:n_steps
long_task()
put!(channel, true) # trigger a progress bar update
i^2
end
put!(channel, false) # this tells the printing task to finish
```
global 100%|██████████████████████████████████████████████| Time: 0:00:24
task 4 100%|██████████████████████████████████████████████| Time: 0:00:05
task 5 100%|██████████████████████████████████████████████| Time: 0:00:05
```

the progress bars can be passed in an `Vector` or a `Dict`. In the first case the main progress bar can be
updated with `p[0]`, otherwise `p[:main]` or by specifying the kwarg `main` when building the `MultipleProgress`

If no main progress is given, one will be automatically generated. See `?MultipleProgress` for all available options.

Additional progress bars can be added from another worker:

```julia
p = MultipleProgress(Progress(10; desc="tasks done "); count_finishes=true)
sleep(0.1)
pmap(1:10) do i
N = rand(20:50)
p[i] = Progress(N; desc=" task $i ")
for _ in 1:N
next!(p[i])
sleep(0.05)
end
end
close(p)
```

Here, returning some number `i^2` and reducing it somehow `(+)`
is necessary to make the distribution happen.
the main progress bar can be a `Progress` or a `ProgessUnknown`,
while the other progresses can be any `AbstractProgress`

### `progress_map`

Expand Down
5 changes: 4 additions & 1 deletion src/ProgressMeter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module ProgressMeter
using Printf: @sprintf
using Distributed

export Progress, ProgressThresh, ProgressUnknown, BarGlyphs, next!, update!, cancel, finish!, @showprogress, progress_map, progress_pmap, ijulia_behavior
export Progress, ProgressThresh, ProgressUnknown, BarGlyphs, next!, update!, cancel,
finish!, @showprogress, progress_map, progress_pmap, ijulia_behavior,
MultipleProgress, ParallelProgress

"""
`ProgressMeter` contains a suite of utilities for displaying progress
Expand Down Expand Up @@ -1105,6 +1107,7 @@ function ncalls_map(args...)
return minimum(length, args)
end

include("parallel_progress.jl")
include("deprecated.jl")

end # module
Loading