Skip to content

Commit 14adebf

Browse files
authored
Improve docs (#301)
* improve example printing * add external links to docs * split doc pages
1 parent 3dcefb6 commit 14adebf

File tree

11 files changed

+146
-54
lines changed

11 files changed

+146
-54
lines changed

docs/examples/02-broadcast.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import MPI
2-
32
MPI.Init()
43

54
comm = MPI.COMM_WORLD
65
N = 5
76
root = 0
87

98
if MPI.Comm_rank(comm) == root
10-
println(" Running on $(MPI.Comm_size(comm)) processes")
9+
print(" Running on $(MPI.Comm_size(comm)) processes\n")
1110
end
1211
MPI.Barrier(comm)
1312

@@ -19,7 +18,7 @@ end
1918

2019
MPI.Bcast!(A, root, comm)
2120

22-
println("rank = $(MPI.Comm_rank(comm)), A = $A")
21+
print("rank = $(MPI.Comm_rank(comm)), A = $A\n")
2322

2423
if MPI.Comm_rank(comm) == root
2524
B = Dict("foo" => "bar")
@@ -28,7 +27,7 @@ else
2827
end
2928

3029
B = MPI.bcast(B, root, comm)
31-
println("rank = $(MPI.Comm_rank(comm)), B = $B")
30+
print("rank = $(MPI.Comm_rank(comm)), B = $B\n")
3231

3332
if MPI.Comm_rank(comm) == root
3433
f = x -> x^2 + 2x - 1
@@ -37,4 +36,4 @@ else
3736
end
3837

3938
f = MPI.bcast(f, root, comm)
40-
println("rank = $(MPI.Comm_rank(comm)), f(3) = $(f(3))")
39+
print("rank = $(MPI.Comm_rank(comm)), f(3) = $(f(3))\n")

docs/examples/03-reduce.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using MPI
2-
32
MPI.Init()
43

54
comm = MPI.COMM_WORLD

docs/examples/04-sendrecv.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using MPI
2-
32
MPI.Init()
43

54
comm = MPI.COMM_WORLD
@@ -18,11 +17,11 @@ fill!(send_mesg, Float64(rank))
1817

1918
rreq = MPI.Irecv!(recv_mesg, src, src+32, comm)
2019

21-
println("$rank: Sending $rank -> $dst = $send_mesg")
20+
print("$rank: Sending $rank -> $dst = $send_mesg\n")
2221
sreq = MPI.Isend(send_mesg, dst, rank+32, comm)
2322

2423
stats = MPI.Waitall!([rreq, sreq])
2524

26-
println("$rank: Received $src -> $rank = $recv_mesg")
25+
print("$rank: Received $src -> $rank = $recv_mesg\n")
2726

2827
MPI.Barrier(comm)

docs/make.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ isdir(examples_md_dir) || mkdir(examples_md_dir)
1414

1515
for (example_title, example_md) in EXAMPLES
1616
example_jl = example_md[1:end-2]*"jl"
17+
@info "Building $example_md"
1718
open(joinpath(@__DIR__, "src", example_md), "w") do mdfile
1819
println(mdfile, "# $example_title")
1920
println(mdfile)
20-
println(mdfile, "`$example_jl`")
2121
println(mdfile, "```julia")
22+
println(mdfile, "# $example_jl")
2223
write(mdfile, read(joinpath(@__DIR__,example_jl)))
2324
println(mdfile, "```")
2425
println(mdfile)
@@ -41,9 +42,13 @@ makedocs(
4142
modules = [MPI],
4243
pages = Any[
4344
"index.md",
44-
"installing.md",
45+
"installation.md",
4546
"usage.md",
4647
"Examples" => EXAMPLES,
48+
"Reference" => [
49+
"environment.md",
50+
"comm.md",
51+
],
4752
"functions.md",
4853
]
4954
)

docs/src/comm.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Communicators
2+
3+
An MPI communicator specifies the communication context for a communication operation. In
4+
particular, it specifies the set of processes which share the context, and assigns each
5+
each process a unique *rank* (see [`MPI.Comm_rank`](@ref)) taking an integer value in
6+
`0:n-1`, where `n` is the number of processes in the communicator (see
7+
[`MPI.Comm_size`](@ref).
8+
9+
## Constants
10+
11+
```@docs
12+
MPI.COMM_WORLD
13+
MPI.COMM_SELF
14+
```
15+
16+
## Functions
17+
18+
```@docs
19+
MPI.Comm_dup
20+
MPI.Comm_get_parent
21+
MPI.Comm_rank
22+
MPI.Comm_size
23+
MPI.Comm_spawn
24+
MPI.Comm_split
25+
MPI.Comm_split_type
26+
MPI.Intercomm_merge
27+
MPI.universe_size
28+
```

docs/src/environment.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Environment
2+
3+
## Functions
4+
5+
```@docs
6+
MPI.Abort
7+
MPI.Init
8+
MPI.Initialized
9+
MPI.Finalize
10+
MPI.Finalized
11+
MPI.refcount_inc
12+
MPI.refcount_dec
13+
```
14+
15+

docs/src/functions.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,11 @@ Constants like `MPI_SUM` are wrapped as `MPI.SUM`. Note also that
66
arbitrary Julia functions `f(x,y)` can be passed as reduction operations
77
to the MPI `Allreduce` and `Reduce` functions.
88

9-
## Communicators
10-
Julia interfaces to the Fortran versions of the MPI functions. Since the C and
11-
Fortran communicators are different, if a C communicator is required (e.g., to
12-
interface with a C library), this can be achieved with the Fortran to C
13-
communicator conversion:
14-
15-
```julia
16-
juliacomm = MPI.COMM_WORLD
17-
ccomm = MPI.CComm(juliacomm)
18-
```
19-
20-
## Administrative functions
9+
## Datatype functions
2110

2211
Julia Function (assuming `import MPI`) | Fortran Function
2312
---------------------------------------|--------------------------------------------------------
24-
[`MPI.Abort`](@ref) | [`MPI_Abort`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Abort.3.php)
25-
[`MPI.Comm_dup`](@ref) | [`MPI_Comm_dup`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Comm_dup.3.php)
26-
[`MPI.Comm_free`](@ref) | [`MPI_Comm_free`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Comm_free.3.php)
27-
[`MPI.Comm_get_parent`](@ref) | [`MPI_Comm_get_parent`](https://www.open-mpi.org/doc/v3.0/man3/MPI_Comm_get_parent.3.php)
28-
[`MPI.Comm_rank`](@ref) | [`MPI_Comm_rank`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Comm_rank.3.php)
29-
[`MPI.Comm_size`](@ref) | [`MPI_Comm_size`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Comm_size.3.php)
30-
[`MPI.Comm_spawn`](@ref) | [`MPI_Comm_spawn`](https://www.open-mpi.org/doc/v3.0/man3/MPI_Comm_spawn.3.php)
31-
[`MPI.Finalize`](@ref) | [`MPI_Finalize`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Finalize.3.php)
32-
[`MPI.Finalized`](@ref) | [`MPI_Finalized`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Finalized.3.php)
3313
[`MPI.Get_address`](@ref) | [`MPI_Get_address`](https://www.open-mpi.org/doc/v3.0/man3/MPI_Get_address.3.php)
34-
[`MPI.Init`](@ref) | [`MPI_Init`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Init.3.php)
35-
[`MPI.Initialized`](@ref) | [`MPI_Initialized`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Initialized.3.php)
36-
[`MPI.Intercomm_merge`](@ref) | [`MPI_Intercomm_merge`](https://www.open-mpi.org/doc/v3.0/man3/MPI_Intercomm_merge.3.php)
3714
[`MPI.mpitype`](@ref) | [`MPI_Type_create_struct`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Type_create_struct.3.php)/[`MPI_Type_commit`](https://www.open-mpi.org/doc/v1.10/man3/MPI_Type_commit.3.php)
3815

3916
!!! note
@@ -43,22 +20,8 @@ Julia Function (assuming `import MPI`) | Fortran Function
4320

4421

4522
```@docs
46-
MPI.Abort
47-
MPI.Comm_dup
48-
MPI.Comm_free
49-
MPI.Comm_get_parent
50-
MPI.Comm_rank
51-
MPI.Comm_size
52-
MPI.Comm_spawn
53-
MPI.Finalize
54-
MPI.Finalized
5523
MPI.Get_address
56-
MPI.Init
57-
MPI.Initialized
58-
MPI.Intercomm_merge
5924
MPI.mpitype
60-
MPI.refcount_inc()
61-
MPI.refcount_dec()
6225
```
6326

6427
## Point-to-point communication

docs/src/installing.md renamed to docs/src/installation.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Setup
1+
# Installation
22

33
## Requirements
44

@@ -10,13 +10,16 @@ MPI.jl requires:
1010
- A C compiler available via the `mpicc` command: this is required as part of the build
1111
process to determine the necessary type definitions and constants.
1212

13-
This has been tested with [Open MPI](http://www.open-mpi.org/) and [MPICH](http://www.mpich.org/)).
13+
This has been tested with:
14+
- [Open MPI](http://www.open-mpi.org/)
15+
- [MPICH](http://www.mpich.org/)
16+
- [Intel MPI](https://software.intel.com/en-us/mpi-library)
1417

1518
### Windows
1619

1720
MPI.jl requires the [Microsoft MPI (MS-MPI)](https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi) runtime to be installed.
1821

19-
## Installation
22+
## Building
2023

2124
The MPI.jl package can be installed via `add MPI` in the [Julia package manager](https://docs.julialang.org/en/v1/stdlib/Pkg/index.html).
2225

src/MPI.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ primitive type SentinelPtr
2626
end
2727
Base.cconvert(::Type{Ptr{T}}, sptr::SentinelPtr) where {T} = reinterpret(Ptr{T}, sptr)
2828

29+
function _doc_external(fname)
30+
"""
31+
- `$fname` man page: [OpenMPI](https://www.open-mpi.org/doc/current/man3/$fname.3.php), [MPICH](https://www.mpich.org/static/docs/latest/www3/$fname.html)
32+
"""
33+
end
34+
2935
include(joinpath(@__DIR__, "..", "deps", "deps.jl"))
3036
include("handle.jl")
3137
include("info.jl")

src/comm.jl

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
@mpi_handle Comm
22

33
const COMM_NULL = _Comm(MPI_COMM_NULL)
4+
5+
"""
6+
MPI.COMM_WORLD
7+
8+
A communicator containing all processes with which the local rank can communicate at
9+
initialization. In a typical "static-process" model, this will be all processes.
10+
"""
411
const COMM_WORLD = _Comm(MPI_COMM_WORLD)
12+
13+
"""
14+
MPI.COMM_SELF
15+
16+
A communicator containing only the local process.
17+
"""
518
const COMM_SELF = _Comm(MPI_COMM_SELF)
619

720
Comm() = Comm(COMM_NULL.val)
@@ -16,11 +29,17 @@ end
1629

1730

1831
"""
19-
Comm_rank(comm:Comm)
32+
Comm_rank(comm::Comm)
2033
2134
The rank of the process in the particular communicator's group.
2235
2336
Returns an integer in the range `0:MPI.Comm_size()-1`.
37+
38+
# See also
39+
- [`MPI.Comm_size`](@ref).
40+
41+
# External links
42+
$(_doc_external("MPI_Comm_rank"))
2443
"""
2544
function Comm_rank(comm::Comm)
2645
rank = Ref{Cint}()
@@ -29,16 +48,28 @@ function Comm_rank(comm::Comm)
2948
end
3049

3150
"""
32-
Comm_size(comm:Comm)
51+
Comm_size(comm::Comm)
3352
3453
The number of processes involved in communicator.
54+
55+
# See also
56+
- [`MPI.Comm_rank`](@ref).
57+
58+
# External links
59+
$(_doc_external("MPI_Comm_size"))
3560
"""
3661
function Comm_size(comm::Comm)
3762
size = Ref{Cint}()
3863
@mpichk ccall((:MPI_Comm_size, libmpi), Cint, (MPI_Comm, Ptr{Cint}), comm, size)
3964
Int(size[])
4065
end
4166

67+
"""
68+
Comm_dup(comm::Comm)
69+
70+
# External links
71+
$(_doc_external("MPI_Comm_dup"))
72+
"""
4273
function Comm_dup(comm::Comm)
4374
newcomm = Comm()
4475
@mpichk ccall((:MPI_Comm_dup, libmpi), Cint, (MPI_Comm, Ptr{MPI_Comm}), comm, newcomm)
@@ -47,6 +78,12 @@ function Comm_dup(comm::Comm)
4778
newcomm
4879
end
4980

81+
"""
82+
Comm_split(comm::Comm, color::Integer, key::Integer)
83+
84+
# External links
85+
$(_doc_external("MPI_Comm_split"))
86+
"""
5087
function Comm_split(comm::Comm, color::Integer, key::Integer)
5188
newcomm = Comm()
5289
@mpichk ccall((:MPI_Comm_split, libmpi), Cint,
@@ -56,6 +93,12 @@ function Comm_split(comm::Comm, color::Integer, key::Integer)
5693
newcomm
5794
end
5895

96+
"""
97+
Comm_split_type(comm::Comm, split_type::Integer, key::Integer; kwargs...)
98+
99+
# External links
100+
$(_doc_external("MPI_Comm_split_type"))
101+
"""
59102
function Comm_split_type(comm::Comm,split_type::Integer,key::Integer; kwargs...)
60103
newcomm = Comm()
61104
@mpichk ccall((:MPI_Comm_split_type, libmpi), Cint,
@@ -66,12 +109,24 @@ function Comm_split_type(comm::Comm,split_type::Integer,key::Integer; kwargs...)
66109
newcomm
67110
end
68111

112+
"""
113+
Comm_get_parent()
114+
115+
# External links
116+
$(_doc_external("MPI_Comm_get_parent"))
117+
"""
69118
function Comm_get_parent()
70119
comm = Comm()
71120
@mpichk ccall((:MPI_Comm_get_parent, libmpi), Cint, (Ptr{MPI_Comm},), comm)
72121
comm
73122
end
74123

124+
"""
125+
Comm_spawn(command, argv::Vector{String}, nprocs::Integer, comm::Comm[, errors::Vector{Cint}]; kwargs...)
126+
127+
# External links
128+
$(_doc_external("MPI_Comm_spawn"))
129+
"""
75130
function Comm_spawn(command::String, argv::Vector{String}, nprocs::Integer,
76131
comm::Comm, errors = Vector{Cint}(undef, nprocs); kwargs...)
77132
intercomm = Comm()
@@ -86,6 +141,12 @@ function Comm_spawn(command::String, argv::Vector{String}, nprocs::Integer,
86141
return intercomm
87142
end
88143

144+
"""
145+
Intercomm_merge(intercomm::Comm, flag::Bool)
146+
147+
# External links
148+
$(_doc_external("MPI_Intercomm_merge"))
149+
"""
89150
function Intercomm_merge(intercomm::Comm, flag::Bool)
90151
newcomm = Comm()
91152
@mpichk ccall((:MPI_Intercomm_merge, libmpi), Cint,

0 commit comments

Comments
 (0)