Skip to content

Commit 44a62a9

Browse files
committed
Added example for the amg preconditioner
1 parent 8e7ebf1 commit 44a62a9

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

docs/Manifest.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.10.0"
44
manifest_format = "2.0"
5-
project_hash = "e37729e95710f39fa1cd840707ef95d2e3bbf22c"
5+
project_hash = "6cb04e0444d1618368044337280d73d6270dffbd"
66

77
[[deps.ANSIColoredPrinters]]
88
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
@@ -313,7 +313,13 @@ version = "2.8.1"
313313
deps = ["CircularArrays", "Distances", "FillArrays", "IterativeSolvers", "LinearAlgebra", "MPI", "Printf", "Random", "SparseArrays", "SparseMatricesCSR"]
314314
path = ".."
315315
uuid = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
316-
version = "0.3.4"
316+
version = "0.4.3"
317+
318+
[[deps.PartitionedSolvers]]
319+
deps = ["IterativeSolvers", "LinearAlgebra", "PartitionedArrays", "Random", "SparseArrays"]
320+
path = "../extensions/PartitionedSolvers"
321+
uuid = "11b65f7f-80ac-401b-9ef2-3db765482d62"
322+
version = "0.1.0"
317323

318324
[[deps.Pkg]]
319325
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
44
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
55
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
6+
PartitionedSolvers = "11b65f7f-80ac-401b-9ef2-3db765482d62"

docs/examples.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,40 @@ psparse!(A,V,cacheA) |> wait
208208
r = A*x - b
209209
norm(r)
210210

211+
# # Distributed algebraic multigrid (AMG)
212+
#
213+
# So far, we have use a conjugate gradient method to solve the linear system. However, this is approach does not scale well
214+
# to larger problems and one needs to consider a preconditioner. A distributed algebraic multigrid (AMG) preconditioner is available in `PartitonedSolvers`, an extension
215+
# package of `PartitionedArrays` that provides parallel solvers for systems built with matrices and vectors from `PartitionedArrays`.
216+
#
217+
# First, let us solve a larger problem without a preconditioner. To this end we use function `laplace_matrix` that builds a Laplace matrix of
218+
# arbitrary size.
219+
220+
using PartitionedArrays: laplace_matrix
221+
222+
nodes_per_dir = (40,40,40)
223+
parts_per_dir = (2,2,1)
224+
nparts = prod(parts_per_dir)
225+
parts = LinearIndices((nparts,))
226+
A = laplace_matrix(nodes_per_dir,parts_per_dir,parts)
227+
x_exact = pones(partition(axes(A,2)))
228+
b = A*x_exact
229+
230+
# Now, we have a matrix and a rhs vector. Let us solve the system:
231+
232+
x = similar(b,axes(A,2))
233+
x .= 0
234+
_, history = IterativeSolvers.cg!(x,A,b;log=true)
235+
history
236+
237+
# Now solve the system while using an AMG preconditioner.
238+
239+
using PartitionedSolvers: amg, preconditioner
211240

241+
x .= 0
242+
Pl = preconditioner(amg(),x,A,b)
243+
_, history = IterativeSolvers.cg!(x,A,b;Pl,log=true)
244+
history
212245

213246

214247

0 commit comments

Comments
 (0)