Skip to content

Commit 0cca4d3

Browse files
authored
Merge pull request #18 from JuliaParallel/other-workers
Implement other_workers() and other_procs()
2 parents 09533a9 + 5141f58 commit 0cca4d3

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

docs/src/_changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This documents notable changes in DistributedNext.jl. The format is based on
1616
- A watcher mechanism has been added to detect when both the Distributed stdlib
1717
and DistributedNext may be active and adding workers. This should help prevent
1818
incompatibilities from both libraries being used simultaneously ([#10]).
19+
- [`other_workers()`](@ref) and [`other_procs()`](@ref) were implemented and
20+
exported ([#18]).
1921

2022
## [v1.0.0] - 2024-12-02
2123

docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ DistributedNext.nprocs
77
DistributedNext.nworkers
88
DistributedNext.procs()
99
DistributedNext.procs(::Integer)
10+
DistributedNext.other_procs()
1011
DistributedNext.workers
12+
DistributedNext.other_workers
1113
DistributedNext.rmprocs
1214
DistributedNext.interrupt
1315
DistributedNext.myid

src/DistributedNext.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ export
4848
nworkers,
4949
pmap,
5050
procs,
51+
other_procs,
5152
remote,
5253
remotecall,
5354
remotecall_fetch,
5455
remotecall_wait,
5556
remote_do,
5657
rmprocs,
5758
workers,
59+
other_workers,
5860
WorkerPool,
5961
RemoteChannel,
6062
Future,

src/cluster.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,8 @@ end
937937
938938
Return a list of all process identifiers, including pid 1 (which is not included by [`workers()`](@ref)).
939939
940+
See also [`other_procs()`](@ref).
941+
940942
# Examples
941943
```julia-repl
942944
\$ julia -p 2
@@ -957,6 +959,14 @@ function procs()
957959
end
958960
end
959961

962+
"""
963+
other_procs([pid::Integer])
964+
965+
Identical to [`procs()`](@ref) and [`procs(::Integer)`](@ref), except that the
966+
current worker is filtered out.
967+
"""
968+
other_procs() = filter(!=(myid()), procs())
969+
960970
function id_in_procs(id) # faster version of `id in procs()`
961971
if myid() == 1 || (PGRP.topology === :all_to_all && !isclusterlazy())
962972
for x in PGRP.workers
@@ -979,6 +989,8 @@ end
979989
980990
Return a list of all process identifiers on the same physical node.
981991
Specifically all workers bound to the same ip-address as `pid` are returned.
992+
993+
See also [`other_procs()`](@ref).
982994
"""
983995
function procs(pid::Integer)
984996
if myid() == 1
@@ -994,11 +1006,15 @@ function procs(pid::Integer)
9941006
end
9951007
end
9961008

1009+
other_procs(pid::Integer) = filter(!=(myid()), procs(pid))
1010+
9971011
"""
9981012
workers()
9991013
10001014
Return a list of all worker process identifiers.
10011015
1016+
See also [`other_workers()`](@ref).
1017+
10021018
# Examples
10031019
```julia-repl
10041020
\$ julia -p 2
@@ -1018,6 +1034,13 @@ function workers()
10181034
end
10191035
end
10201036

1037+
"""
1038+
other_workers()
1039+
1040+
Identical to [`workers()`](@ref) except that the current worker is filtered out.
1041+
"""
1042+
other_workers() = filter(!=(myid()), workers())
1043+
10211044
function cluster_mgmt_from_master_check()
10221045
if myid() != 1
10231046
throw(ErrorException("Only process 1 can add and remove workers"))

test/distributed_exec.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ end
3030
end
3131

3232
@testset "Distributed loading of packages" begin
33-
addprocs_with_testenv(4)
33+
@test isempty(other_workers())
34+
@test isempty(other_procs())
35+
36+
pids = addprocs_with_testenv(4)
37+
3438
@test nprocs() == 5
39+
@test other_workers() == workers()
40+
@test other_procs() == pids
41+
@test other_procs(1) == pids
3542

3643
global id_me = myid()
3744
global id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]

0 commit comments

Comments
 (0)