You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/examples.jl
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -208,7 +208,40 @@ psparse!(A,V,cacheA) |> wait
208
208
r = A*x - b
209
209
norm(r)
210
210
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
211
240
241
+
x .=0
242
+
Pl =preconditioner(amg(),x,A,b)
243
+
_, history = IterativeSolvers.cg!(x,A,b;Pl,log=true)
0 commit comments