Skip to content

Commit bbf44ce

Browse files
authored
Merge pull request #134 from fverdugo/vanilla_amg
Add smoothed aggregation solver
2 parents ea04326 + 11a8947 commit bbf44ce

File tree

17 files changed

+1459
-22
lines changed

17 files changed

+1459
-22
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
name: CI
22
on:
3-
- push
4-
- pull_request
3+
push:
4+
branches:
5+
- main
6+
tags: '*'
7+
pull_request:
8+
concurrency:
9+
# Skip intermediate builds: always.
10+
# Cancel intermediate builds: only if it is a pull request build.
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
513
jobs:
614
test:
7-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
15+
name: PartitionedArrays / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
816
runs-on: ${{ matrix.os }}
917
strategy:
1018
fail-fast: false
1119
matrix:
1220
version:
1321
- '1.6'
14-
- '1' # Latest 1.X
22+
- '1'
1523
os:
1624
- ubuntu-latest
1725
arch:
@@ -26,22 +34,55 @@ jobs:
2634
- uses: julia-actions/julia-buildpkg@v1
2735
- uses: julia-actions/julia-runtest@v1
2836
- uses: julia-actions/julia-processcoverage@v1
29-
- uses: codecov/codecov-action@v1
37+
- uses: codecov/codecov-action@v2
3038
with:
31-
file: lcov.info
39+
files: lcov.info
40+
PartitionedSolvers:
41+
name: PartitionedSolvers / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
42+
runs-on: ${{ matrix.os }}
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
version:
47+
- '1'
48+
os:
49+
- ubuntu-latest
50+
arch:
51+
- x64
52+
steps:
53+
- uses: actions/checkout@v2
54+
- uses: julia-actions/setup-julia@v1
55+
with:
56+
version: ${{ matrix.version }}
57+
arch: ${{ matrix.arch }}
58+
- uses: julia-actions/cache@v1
59+
- uses: julia-actions/julia-buildpkg@v1
60+
- run: |
61+
julia --project=extensions/PartitionedSolvers -e '
62+
using Pkg
63+
Pkg.develop(path=".")
64+
Pkg.test("PartitionedSolvers")'
3265
docs:
3366
name: Documentation
3467
runs-on: ubuntu-latest
68+
permissions:
69+
contents: write
3570
steps:
3671
- uses: actions/checkout@v2
3772
- uses: julia-actions/setup-julia@v1
3873
with:
3974
version: '1'
40-
- uses: julia-actions/cache@v1
41-
- name: Install dependencies
42-
run: julia --project=docs -e 'using Pkg; Pkg.instantiate()'
43-
- name: Build and deploy
75+
- uses: julia-actions/julia-buildpkg@v1
76+
- run: |
77+
julia --project=docs -e '
78+
using Pkg
79+
Pkg.develop(path="extensions/PartitionedSolvers")'
80+
- uses: julia-actions/julia-docdeploy@v1
4481
env:
4582
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
47-
run: julia --project=docs docs/make.jl
83+
- run: |
84+
julia --project=docs -e '
85+
using Documenter: DocMeta, doctest
86+
using PartitionedArrays
87+
DocMeta.setdocmeta!(PartitionedArrays, :DocTestSetup, :(using PartitionedArrays); recursive=true)
88+
doctest(PartitionedArrays)'

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name = "PartitionedSolvers"
2+
uuid = "11b65f7f-80ac-401b-9ef2-3db765482d62"
3+
authors = ["Francesc Verdugo <f.verdugo.rojano@vu.nl>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
8+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
9+
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
10+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
11+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
12+
13+
[extras]
14+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
15+
16+
[targets]
17+
test = ["Test"]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module PartitionedSolvers
2+
3+
using PartitionedArrays
4+
using SparseArrays
5+
using LinearAlgebra
6+
7+
export setup
8+
export solve!
9+
export setup!
10+
export finalize!
11+
export AbstractLinearSolver
12+
export linear_solver
13+
export attach_nullspace
14+
export default_nullspace
15+
export preconditioner
16+
export matrix
17+
export nullspace
18+
include("interfaces.jl")
19+
20+
export lu_solver
21+
export jacobi_correction
22+
export richardson
23+
export jacobi
24+
export gauss_seidel
25+
export additive_schwarz_correction
26+
export additive_schwarz
27+
include("smoothers.jl")
28+
29+
export amg
30+
export smoothed_aggregation
31+
export v_cycle
32+
export w_cycle
33+
export amg_level_params
34+
export amg_fine_params
35+
export amg_coarse_params
36+
export amg_statistics
37+
include("amg.jl")
38+
39+
end # module

0 commit comments

Comments
 (0)