Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more examples/formatting/xrefs for Distributed docs #29011

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 77 additions & 9 deletions stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,33 @@ const map_del_wrkr = Set{Int}()
myid()

Get the id of the current process.

# Examples
```julia-repl
julia> myid()
1

julia> remotecall_fetch(() -> myid(), 4)
4
```
"""
myid() = LPROC.id

"""
nprocs()

Get the number of available processes.

# Examples
```julia-repl
julia> nprocs()
3

julia> workers()
5-element Array{Int64,1}:
2
3
```
"""
function nprocs()
if myid() == 1 || (PGRP.topology == :all_to_all && !isclusterlazy())
Expand All @@ -746,8 +766,19 @@ end
"""
nworkers()

Get the number of available worker processes. This is one less than `nprocs()`. Equal to
Get the number of available worker processes. This is one less than [`nprocs()`](@ref). Equal to
`nprocs()` if `nprocs() == 1`.

# Examples
```julia-repl
\$ julia -p 5

julia> nprocs()
6

julia> nworkers()
5
```
"""
function nworkers()
n = nprocs()
Expand All @@ -757,7 +788,18 @@ end
"""
procs()

Return a list of all process identifiers.
Return a list of all process identifiers, including pid 1 (which is not included by [`workers()`](@ref)).

# Examples
```julia-repl
\$ julia -p 5

julia> procs()
3-element Array{Int64,1}:
1
2
3
```
"""
function procs()
if myid() == 1 || (PGRP.topology == :all_to_all && !isclusterlazy())
Expand Down Expand Up @@ -809,6 +851,16 @@ end
workers()

Return a list of all worker process identifiers.

# Examples
```julia-repl
\$ julia -p 5

julia> workers()
2-element Array{Int64,1}:
2
3
```
"""
function workers()
allp = procs()
Expand All @@ -832,13 +884,29 @@ Remove the specified workers. Note that only process 1 can add or remove
workers.

Argument `waitfor` specifies how long to wait for the workers to shut down:
- If unspecified, `rmprocs` will wait until all requested `pids` are removed.
- An `ErrorException` is raised if all workers cannot be terminated before
the requested `waitfor` seconds.
- With a `waitfor` value of 0, the call returns immediately with the workers
scheduled for removal in a different task. The scheduled `Task` object is
returned. The user should call `wait` on the task before invoking any other
parallel calls.
- If unspecified, `rmprocs` will wait until all requested `pids` are removed.
- An [`ErrorException`](@ref) is raised if all workers cannot be terminated before
the requested `waitfor` seconds.
- With a `waitfor` value of 0, the call returns immediately with the workers
scheduled for removal in a different task. The scheduled [`Task`](@ref) object is
returned. The user should call [`wait`](@ref) on the task before invoking any other
parallel calls.

# Examples
```julia-repl
\$ julia -p 5

julia> t = rmprocs(2, 3, waitfor=0)
Task (runnable) @0x0000000107c718d0

julia> wait(t)

julia> workers()
3-element Array{Int64,1}:
4
5
6
```
"""
function rmprocs(pids...; waitfor=typemax(Int))
cluster_mgmt_from_master_check()
Expand Down