Skip to content

Commit a6f82d6

Browse files
committed
Some more examples/formatting/xrefs for Distributed docs
1 parent f77c36b commit a6f82d6

File tree

1 file changed

+77
-9
lines changed

1 file changed

+77
-9
lines changed

stdlib/Distributed/src/cluster.jl

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,33 @@ const map_del_wrkr = Set{Int}()
720720
myid()
721721
722722
Get the id of the current process.
723+
724+
# Examples
725+
```julia-repl
726+
julia> myid()
727+
1
728+
729+
julia> remotecall_fetch(() -> myid(), 4)
730+
4
731+
```
723732
"""
724733
myid() = LPROC.id
725734

726735
"""
727736
nprocs()
728737
729738
Get the number of available processes.
739+
740+
# Examples
741+
```julia-repl
742+
julia> nprocs()
743+
3
744+
745+
julia> workers()
746+
5-element Array{Int64,1}:
747+
2
748+
3
749+
```
730750
"""
731751
function nprocs()
732752
if myid() == 1 || (PGRP.topology == :all_to_all && !isclusterlazy())
@@ -746,8 +766,19 @@ end
746766
"""
747767
nworkers()
748768
749-
Get the number of available worker processes. This is one less than `nprocs()`. Equal to
769+
Get the number of available worker processes. This is one less than [`nprocs()`](@ref). Equal to
750770
`nprocs()` if `nprocs() == 1`.
771+
772+
# Examples
773+
```julia-repl
774+
\$ julia -p 5
775+
776+
julia> nprocs()
777+
6
778+
779+
julia> nworkers()
780+
5
781+
```
751782
"""
752783
function nworkers()
753784
n = nprocs()
@@ -757,7 +788,18 @@ end
757788
"""
758789
procs()
759790
760-
Return a list of all process identifiers.
791+
Return a list of all process identifiers, including pid 1 (which is not included by [`workers()`](@ref)).
792+
793+
# Examples
794+
```julia-repl
795+
\$ julia -p 5
796+
797+
julia> procs()
798+
3-element Array{Int64,1}:
799+
1
800+
2
801+
3
802+
```
761803
"""
762804
function procs()
763805
if myid() == 1 || (PGRP.topology == :all_to_all && !isclusterlazy())
@@ -809,6 +851,16 @@ end
809851
workers()
810852
811853
Return a list of all worker process identifiers.
854+
855+
# Examples
856+
```julia-repl
857+
\$ julia -p 5
858+
859+
julia> workers()
860+
2-element Array{Int64,1}:
861+
2
862+
3
863+
```
812864
"""
813865
function workers()
814866
allp = procs()
@@ -832,13 +884,29 @@ Remove the specified workers. Note that only process 1 can add or remove
832884
workers.
833885
834886
Argument `waitfor` specifies how long to wait for the workers to shut down:
835-
- If unspecified, `rmprocs` will wait until all requested `pids` are removed.
836-
- An `ErrorException` is raised if all workers cannot be terminated before
837-
the requested `waitfor` seconds.
838-
- With a `waitfor` value of 0, the call returns immediately with the workers
839-
scheduled for removal in a different task. The scheduled `Task` object is
840-
returned. The user should call `wait` on the task before invoking any other
841-
parallel calls.
887+
- If unspecified, `rmprocs` will wait until all requested `pids` are removed.
888+
- An [`ErrorException`](@ref) is raised if all workers cannot be terminated before
889+
the requested `waitfor` seconds.
890+
- With a `waitfor` value of 0, the call returns immediately with the workers
891+
scheduled for removal in a different task. The scheduled [`Task`](@ref) object is
892+
returned. The user should call [`wait`](@ref) on the task before invoking any other
893+
parallel calls.
894+
895+
# Examples
896+
```julia-repl
897+
\$ julia -p 5
898+
899+
julia> t = rmprocs(2, 3, waitfor=0)
900+
Task (runnable) @0x0000000107c718d0
901+
902+
julia> wait(t)
903+
904+
julia> workers()
905+
3-element Array{Int64,1}:
906+
4
907+
5
908+
6
909+
```
842910
"""
843911
function rmprocs(pids...; waitfor=typemax(Int))
844912
cluster_mgmt_from_master_check()

0 commit comments

Comments
 (0)