Skip to content

Commit 188a0c1

Browse files
committed
Misc changes in docs/usage.md
1 parent b0a209c commit 188a0c1

File tree

2 files changed

+75
-81
lines changed

2 files changed

+75
-81
lines changed

docs/Manifest.toml

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.7.1"
3+
julia_version = "1.7.3"
44
manifest_format = "2.0"
55

66
[[deps.ANSIColoredPrinters]]
77
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
88
uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
99
version = "0.0.1"
1010

11-
[[deps.AbstractTrees]]
12-
git-tree-sha1 = "03e0550477d86222521d254b741d470ba17ea0b5"
13-
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
14-
version = "0.3.4"
15-
1611
[[deps.ArgTools]]
1712
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
1813

@@ -52,31 +47,13 @@ git-tree-sha1 = "75c6cf9d99e0efc79b724f5566726ad3ad010a01"
5247
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5348
version = "0.27.12"
5449

55-
[[deps.DocumenterTools]]
56-
deps = ["AbstractTrees", "Base64", "DocStringExtensions", "Documenter", "FileWatching", "Gumbo", "LibGit2", "Sass"]
57-
git-tree-sha1 = "d0574a2a4950fdcde104b7f3d1b34f0417fa9f10"
58-
uuid = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
59-
version = "0.1.13"
60-
6150
[[deps.Downloads]]
62-
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
51+
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
6352
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
6453

6554
[[deps.FileWatching]]
6655
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
6756

68-
[[deps.Gumbo]]
69-
deps = ["AbstractTrees", "Gumbo_jll", "Libdl"]
70-
git-tree-sha1 = "e711d08d896018037d6ff0ad4ebe675ca67119d4"
71-
uuid = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
72-
version = "0.8.0"
73-
74-
[[deps.Gumbo_jll]]
75-
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
76-
git-tree-sha1 = "29070dee9df18d9565276d68a596854b1764aa38"
77-
uuid = "528830af-5a63-567c-a44a-034ed33b8444"
78-
version = "0.10.2+0"
79-
8057
[[deps.IOCapture]]
8158
deps = ["Logging", "Random"]
8259
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a"
@@ -187,10 +164,10 @@ uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
187164
version = "2.2.1"
188165

189166
[[deps.PartitionedArrays]]
190-
deps = ["Distances", "DocumenterTools", "IterativeSolvers", "LinearAlgebra", "MPI", "Printf", "SparseArrays", "SparseMatricesCSR"]
167+
deps = ["Distances", "IterativeSolvers", "LinearAlgebra", "MPI", "Printf", "SparseArrays", "SparseMatricesCSR"]
191168
path = ".."
192169
uuid = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
193-
version = "0.2.9"
170+
version = "0.2.10"
194171

195172
[[deps.Pkg]]
196173
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
@@ -228,12 +205,6 @@ version = "1.3.0"
228205
[[deps.SHA]]
229206
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
230207

231-
[[deps.Sass]]
232-
deps = ["libsass_jll"]
233-
git-tree-sha1 = "aa841c3738cec78b5dbccd56dda332710f35f6a5"
234-
uuid = "322a6be2-4ae8-5d68-aaf1-3e960788d1d9"
235-
version = "0.2.0"
236-
237208
[[deps.Serialization]]
238209
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
239210

@@ -290,12 +261,6 @@ uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
290261
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
291262
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
292263

293-
[[deps.libsass_jll]]
294-
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
295-
git-tree-sha1 = "663428b7ebaf60c60ee147f0f9466430e9959ad6"
296-
uuid = "47bcb7c8-5119-555a-9eeb-0afcc36cd728"
297-
version = "3.5.5+0"
298-
299264
[[deps.nghttp2_jll]]
300265
deps = ["Artifacts", "Libdl"]
301266
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

docs/src/usage.md

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -57,79 +57,93 @@ using PartitionedArrays, SparseArrays, IterativeSolvers
5757
```
5858

5959
We want a partitioning into 2 pieces and chose the sequential backend to handle
60-
the task sequentially to simplify debugging.
60+
the task sequentially so that the code can be executed in a standard Julia REPL (e.g., to simplify debugging).
6161
```julia
6262
np = 2
6363
backend = SequentialBackend()
6464
```
6565

66-
We enter the execution environment
66+
Most of the codes using `PartitionedArrays` start creating a distributed object that for each part contains its part id. We call it `parts`.
6767
```julia
68-
prun(backend,np) do parts
68+
parts = get_part_id(backend,np)
6969
```
7070

71-
Generate a partitioning of rows and columns. Note that the entry in row 3
71+
Now, we generate a partitioning of rows and columns. Note that the entry in row 3
7272
column 4 is visible to the first worker
7373
```julia
74-
neighbors, row_partitioning, col_partitioning = map_parts(parts) do part
75-
if part == 1
76-
Int32[2], IndexSet(part, [1,2,3], Int32[1,1,1]), IndexSet(part, [1,2,3,4], Int32[1,1,1,2])
77-
else
78-
Int32[1], IndexSet(part, [3,4,5], Int32[1,2,2]), IndexSet(part, [3,4,5], Int32[1,2,2])
79-
end
74+
neighbors, row_partitioning, col_partitioning = map_parts(parts) do part
75+
if part == 1
76+
(
77+
Int32[2],
78+
IndexSet(part, [1,2,3], Int32[1,1,1]),
79+
IndexSet(part, [1,2,3,4], Int32[1,1,1,2])
80+
)
81+
else
82+
(
83+
Int32[1],
84+
IndexSet(part, [3,4,5], Int32[1,2,2]),
85+
IndexSet(part, [3,4,5], Int32[1,2,2])
86+
)
8087
end
88+
end
8189
```
8290

8391
We create information exchangers to manage the synchronization of visible
8492
shared portions of the sparse matrix and the actual row/col
8593
```julia
86-
global_number_of_dofs = 5
87-
row_exchanger = Exchanger(row_partitioning,neighbors)
88-
rows = PRange(global_number_of_dofs,row_partitioning,row_exchanger)
94+
global_number_of_dofs = 5
95+
row_exchanger = Exchanger(row_partitioning,neighbors)
96+
rows = PRange(global_number_of_dofs,row_partitioning,row_exchanger)
8997

90-
col_exchanger = Exchanger(col_partitioning,neighbors)
91-
cols = PRange(global_number_of_dofs,col_partitioning,col_exchanger)
98+
col_exchanger = Exchanger(col_partitioning,neighbors)
99+
cols = PRange(global_number_of_dofs,col_partitioning,col_exchanger)
92100
```
93101

94102
Next we create the sparse matrix entries in COO format in their worker-local
95103
numbering. A note about the exact values of the sparse matrices can be found
96104
in the subsection below.
97105
```julia
98-
I, J, V = map_parts(parts) do part
99-
if part == 1
100-
return [ 1, 1, 2, 2, 2, 3, 3, 3], [ 1, 2, 1, 2, 3, 2, 3, 4], 0.25*Float64[1, 0, 0,-2, 1, 1,-1, 0]
101-
else
102-
return [ 1, 1, 2, 2, 2, 3, 3], [ 1, 2, 1, 2, 3, 2, 3], 0.25*Float64[-1, 1, 1,-2, 1, 1,-1]
103-
end
106+
I, J, V = map_parts(parts) do part
107+
if part == 1
108+
(
109+
[ 1, 1, 2, 2, 2, 3, 3, 3],
110+
[ 1, 2, 1, 2, 3, 2, 3, 4],
111+
0.25*Float64[1, 0, 0,-2, 1, 1,-1, 0]
112+
)
113+
else
114+
(
115+
[ 1, 1, 2, 2, 2, 3, 3],
116+
[ 1, 2, 1, 2, 3, 2, 3],
117+
0.25*Float64[-1, 1, 1,-2, 1, 1,-1])
104118
end
105-
A = PSparseMatrix(I, J, V, rows, cols, ids=:local)
119+
end
120+
A = PSparseMatrix(I, J, V, rows, cols, ids=:local)
106121
```
107122

108123
Since the previous lines created the local prtions we have to trigger sync
109124
between the workers.
110125
```julia
111-
assemble!(A)
126+
assemble!(A)
112127
```
113128

114129
Construct the right hand side. Note that the first entry of the rhs of worker 2
115130
is shared with worker 1.
116131
```julia
117-
b = PVector{Float64}(undef, A.rows)
118-
map_parts(parts,local_view(b, b.rows)) do part, b_local
119-
if part == 1
120-
b_local .= [1.0, -1.0, 0.0]
121-
else
122-
b_local .= [0.0, 0.0, 0.0]
123-
end
132+
b = PVector{Float64}(undef, A.rows)
133+
map_parts(parts,local_view(b, b.rows)) do part, b_local
134+
if part == 1
135+
b_local .= [1.0, -1.0, 0.0]
136+
else
137+
b_local .= [0.0, 0.0, 0.0]
124138
end
139+
end
125140
```
126141

127142
Now the sparse matrix and right hand side of the linear system are assembled
128143
globally and we can solve problem with cg. With the end in the last line we
129144
close the parallel environment.
130145
```julia
131-
u = IterativeSolvers.cg(A,b)
132-
end
146+
u = IterativeSolvers.cg(A,b)
133147
```
134148

135149
### Parallel Code
@@ -143,15 +157,15 @@ to
143157
```julia
144158
backend = MPIBackend()
145159
```
146-
and including MPI. Now launching the script with MPI makes the run parallel
160+
and including and initializing MPI. Now launching the script with MPI makes the run parallel.
147161

148162
```sh
149163
$ mpirun -n 2 julia my-script.jl
150164
```
151165

152-
Hence the full MPI code looks like this
166+
Hence the full MPI code is given in the next code box. Note that we have used the `prun` function that automatically includes and initializes MPI for us.
153167
```julia
154-
using PartitionedArrays, SparseArrays, IterativeSolvers, MPI
168+
using PartitionedArrays, SparseArrays, IterativeSolvers
155169

156170
np = 2
157171
backend = MPIBackend()
@@ -160,9 +174,17 @@ prun(backend,np) do parts
160174
# Construct the partitioning
161175
neighbors, row_partitioning, col_partitioning = map_parts(parts) do part
162176
if part == 1
163-
Int32[2], IndexSet(part, [1,2,3], Int32[1,1,1]), IndexSet(part, [1,2,3,4], Int32[1,1,1,2])
177+
(
178+
Int32[2],
179+
IndexSet(part, [1,2,3], Int32[1,1,1]),
180+
IndexSet(part, [1,2,3,4], Int32[1,1,1,2])
181+
)
164182
else
165-
Int32[1], IndexSet(part, [3,4,5], Int32[1,2,2]), IndexSet(part, [3,4,5], Int32[1,2,2])
183+
(
184+
Int32[1],
185+
IndexSet(part, [3,4,5], Int32[1,2,2]),
186+
IndexSet(part, [3,4,5], Int32[1,2,2])
187+
)
166188
end
167189
end
168190

@@ -176,11 +198,18 @@ prun(backend,np) do parts
176198

177199
# Construct the sparse matrix
178200
I, J, V = map_parts(parts) do part
179-
if part == 1
180-
return [ 1, 1, 2, 2, 2, 3, 3, 3], [ 1, 2, 1, 2, 3, 2, 3, 4], 0.25*Float64[1, 0, 0,-2, 1, 1,-1, 0]
181-
else
182-
return [ 1, 1, 2, 2, 2, 3, 3], [ 1, 2, 1, 2, 3, 2, 3], 0.25*Float64[-1, 1, 1,-2, 1, 1,-1]
183-
end
201+
if part == 1
202+
(
203+
[ 1, 1, 2, 2, 2, 3, 3, 3],
204+
[ 1, 2, 1, 2, 3, 2, 3, 4],
205+
0.25*Float64[1, 0, 0,-2, 1, 1,-1, 0]
206+
)
207+
else
208+
(
209+
[ 1, 1, 2, 2, 2, 3, 3],
210+
[ 1, 2, 1, 2, 3, 2, 3],
211+
0.25*Float64[-1, 1, 1,-2, 1, 1,-1])
212+
end
184213
end
185214
A = PSparseMatrix(I, J, V, rows, cols, ids=:local)
186215
assemble!(A)

0 commit comments

Comments
 (0)