Skip to content

Commit a36f6dd

Browse files
Allow constructing WorkerPool from AbstractRange{Int} (JuliaLang/julia#44376)
Co-authored-by: Kristoffer Carlsson <[email protected]>
1 parent 3078250 commit a36f6dd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/workerpool.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,22 @@ function WorkerPool()
3333
end
3434

3535
"""
36-
WorkerPool(workers::Vector{Int})
36+
WorkerPool(workers::Union{Vector{Int},AbstractRange{Int}})
3737
38-
Create a `WorkerPool` from a vector of worker ids.
38+
Create a `WorkerPool` from a vector or range of worker ids.
3939
4040
# Examples
4141
```julia-repl
4242
\$ julia -p 3
4343
4444
julia> WorkerPool([2, 3])
4545
WorkerPool(Channel{Int64}(sz_max:9223372036854775807,sz_curr:2), Set([2, 3]), RemoteChannel{Channel{Any}}(1, 1, 6))
46+
47+
julia> WorkerPool(2:4)
48+
WorkerPool(Channel{Int64}(sz_max:9223372036854775807,sz_curr:2), Set([4, 2, 3]), RemoteChannel{Channel{Any}}(1, 1, 7))
4649
```
4750
"""
48-
function WorkerPool(workers::Vector{Int})
51+
function WorkerPool(workers::Union{Vector{Int},AbstractRange{Int}})
4952
pool = WorkerPool()
5053
foreach(w->push!(pool, w), workers)
5154
return pool

test/distributed_exec.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ pmap(_->myid(), 1:nworkers()) # priming run
665665
wp = WorkerPool(workers())
666666
@test nworkers() == length(unique(pmap(_->myid(), wp, 1:100)))
667667
@test nworkers() == length(unique(remotecall_fetch(wp->pmap(_->myid(), wp, 1:100), id_other, wp)))
668-
668+
wp = WorkerPool(2:3)
669+
@test sort(unique(pmap(_->myid(), wp, 1:100))) == [2,3]
669670

670671
# CachingPool tests
671672
wp = CachingPool(workers())

0 commit comments

Comments
 (0)