Skip to content

Commit

Permalink
Allow constructing WorkerPool from AbstractRange{Int} (#44376)
Browse files Browse the repository at this point in the history
Co-authored-by: Kristoffer Carlsson <[email protected]>
  • Loading branch information
fredcallaway and KristofferC authored May 12, 2022
1 parent c889fbc commit 89f16e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions stdlib/Distributed/src/workerpool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ function WorkerPool()
end

"""
WorkerPool(workers::Vector{Int})
WorkerPool(workers::Union{Vector{Int},AbstractRange{Int}})
Create a `WorkerPool` from a vector of worker ids.
Create a `WorkerPool` from a vector or range of worker ids.
# Examples
```julia-repl
\$ julia -p 3
julia> WorkerPool([2, 3])
WorkerPool(Channel{Int64}(sz_max:9223372036854775807,sz_curr:2), Set([2, 3]), RemoteChannel{Channel{Any}}(1, 1, 6))
julia> WorkerPool(2:4)
WorkerPool(Channel{Int64}(sz_max:9223372036854775807,sz_curr:2), Set([4, 2, 3]), RemoteChannel{Channel{Any}}(1, 1, 7))
```
"""
function WorkerPool(workers::Vector{Int})
function WorkerPool(workers::Union{Vector{Int},AbstractRange{Int}})
pool = WorkerPool()
foreach(w->push!(pool, w), workers)
return pool
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ pmap(_->myid(), 1:nworkers()) # priming run
wp = WorkerPool(workers())
@test nworkers() == length(unique(pmap(_->myid(), wp, 1:100)))
@test nworkers() == length(unique(remotecall_fetch(wp->pmap(_->myid(), wp, 1:100), id_other, wp)))

wp = WorkerPool(2:3)
@test sort(unique(pmap(_->myid(), wp, 1:100))) == [2,3]

# CachingPool tests
wp = CachingPool(workers())
Expand Down

0 comments on commit 89f16e5

Please sign in to comment.