diff --git a/docs/src/_changelog.md b/docs/src/_changelog.md index f48aba3..5d9207f 100644 --- a/docs/src/_changelog.md +++ b/docs/src/_changelog.md @@ -16,6 +16,8 @@ This documents notable changes in DistributedNext.jl. The format is based on - A watcher mechanism has been added to detect when both the Distributed stdlib and DistributedNext may be active and adding workers. This should help prevent incompatibilities from both libraries being used simultaneously ([#10]). +- [`other_workers()`](@ref) and [`other_procs()`](@ref) were implemented and + exported ([#18]). ## [v1.0.0] - 2024-12-02 diff --git a/docs/src/index.md b/docs/src/index.md index fd88707..41fba38 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -7,7 +7,9 @@ DistributedNext.nprocs DistributedNext.nworkers DistributedNext.procs() DistributedNext.procs(::Integer) +DistributedNext.other_procs() DistributedNext.workers +DistributedNext.other_workers DistributedNext.rmprocs DistributedNext.interrupt DistributedNext.myid diff --git a/src/DistributedNext.jl b/src/DistributedNext.jl index 01e54e3..a9cb4cf 100644 --- a/src/DistributedNext.jl +++ b/src/DistributedNext.jl @@ -48,6 +48,7 @@ export nworkers, pmap, procs, + other_procs, remote, remotecall, remotecall_fetch, @@ -55,6 +56,7 @@ export remote_do, rmprocs, workers, + other_workers, WorkerPool, RemoteChannel, Future, diff --git a/src/cluster.jl b/src/cluster.jl index 0a74dcc..10c53ac 100644 --- a/src/cluster.jl +++ b/src/cluster.jl @@ -937,6 +937,8 @@ end Return a list of all process identifiers, including pid 1 (which is not included by [`workers()`](@ref)). +See also [`other_procs()`](@ref). + # Examples ```julia-repl \$ julia -p 2 @@ -957,6 +959,14 @@ function procs() end end +""" + other_procs([pid::Integer]) + +Identical to [`procs()`](@ref) and [`procs(::Integer)`](@ref), except that the +current worker is filtered out. +""" +other_procs() = filter(!=(myid()), procs()) + function id_in_procs(id) # faster version of `id in procs()` if myid() == 1 || (PGRP.topology === :all_to_all && !isclusterlazy()) for x in PGRP.workers @@ -979,6 +989,8 @@ end Return a list of all process identifiers on the same physical node. Specifically all workers bound to the same ip-address as `pid` are returned. + +See also [`other_procs()`](@ref). """ function procs(pid::Integer) if myid() == 1 @@ -994,11 +1006,15 @@ function procs(pid::Integer) end end +other_procs(pid::Integer) = filter(!=(myid()), procs(pid)) + """ workers() Return a list of all worker process identifiers. +See also [`other_workers()`](@ref). + # Examples ```julia-repl \$ julia -p 2 @@ -1018,6 +1034,13 @@ function workers() end end +""" + other_workers() + +Identical to [`workers()`](@ref) except that the current worker is filtered out. +""" +other_workers() = filter(!=(myid()), workers()) + function cluster_mgmt_from_master_check() if myid() != 1 throw(ErrorException("Only process 1 can add and remove workers")) diff --git a/test/distributed_exec.jl b/test/distributed_exec.jl index c567d92..8bfc462 100644 --- a/test/distributed_exec.jl +++ b/test/distributed_exec.jl @@ -30,8 +30,15 @@ end end @testset "Distributed loading of packages" begin - addprocs_with_testenv(4) + @test isempty(other_workers()) + @test isempty(other_procs()) + + pids = addprocs_with_testenv(4) + @test nprocs() == 5 + @test other_workers() == workers() + @test other_procs() == pids + @test other_procs(1) == pids global id_me = myid() global id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]