Skip to content

Commit fde4674

Browse files
committed
Implemented a first repartition strategy
1 parent 9c0d62e commit fde4674

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

extensions/PartitionedSolvers/src/amg.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,33 @@ function omega_for_1d_laplace(invD,A)
260260
2/3
261261
end
262262

263+
function enhance_coarse_partition(A,Ac,Bc,R,P,cache,repartition_threshold)
264+
Ac,Bc,R,P,cache,repartition_threshold
265+
end
266+
267+
function enhance_coarse_partition(A::PSparseMatrix,Ac,Bc,R,P,cache,repartition_threshold)
268+
# TODO now we redistribute to a single proc when the threshold is reached
269+
# We need to redistributed to fewer but several processors
270+
# TODO a way of avoiding the extra rap ?
271+
n_coarse = size(Ac,1)
272+
if n_coarse <= repartition_threshold
273+
repartition_threshold = 0 # do not repartition again
274+
parts = linear_indices(partition(Ac))
275+
coarse_partition = trivial_partition(parts,n_coarse)
276+
P = repartition(P,partition(axes(P,1)),coarse_partition) |> fetch
277+
Bc = map(b->repartition(b,partition(axes(P,2)))|>fetch,Bc)
278+
R = transpose(P)
279+
Ac,cache = rap(R,A,P;reuse=true)
280+
end
281+
Ac,Bc,R,P,cache,repartition_threshold
282+
end
283+
263284
function smoothed_aggregation(;
264285
epsilon = 0,
265286
approximate_omega = omega_for_1d_laplace,
266-
tentative_prolongator = tentative_prolongator_for_laplace)
287+
tentative_prolongator = tentative_prolongator_for_laplace,
288+
repartition_threshold = 2000,
289+
)
267290
function coarsen(operator)
268291
A = matrix(operator)
269292
B = nullspace(operator)
@@ -275,7 +298,7 @@ function smoothed_aggregation(;
275298
P = smoothed_prolongator(A,P0,diagA;approximate_omega)
276299
R = transpose(P)
277300
Ac,cache = rap(R,A,P;reuse=true)
278-
# TODO enhance partitioning for Ac,R,P
301+
Ac,Bc,R,P,cache,repartition_threshold = enhance_coarse_partition(A,Ac,Bc,R,P,cache,repartition_threshold)
279302
coarse_operator = attach_nullspace(Ac,Bc)
280303
coarse_operator,R,P,cache
281304
end
@@ -289,7 +312,7 @@ function smoothed_aggregation(;
289312
end
290313

291314
function amg_level_params(;
292-
pre_smoother = additive_schwarz(gauss_seidel(;iters=1)),
315+
pre_smoother = richardson(additive_schwarz(gauss_seidel(;iters=1));iters=1),
293316
coarsening = smoothed_aggregation(;),
294317
cycle = v_cycle,
295318
pos_smoother = pre_smoother,
@@ -345,7 +368,7 @@ function amg_setup(x,operator,b,amg_params)
345368
done = true
346369
end
347370
r = similar(b)
348-
rc = similar(r,axes(Ac,1))
371+
rc = similar(r,axes(Ac,2)) # we need ghost ids for the mul!(rc,R,r)
349372
e = similar(x)
350373
ec = similar(e,axes(Ac,2))
351374
level_setup = (;R,P,r,rc,e,ec,operator,coarse_operator,pre_setup,pos_setup,coarse_operator_setup)

extensions/PartitionedSolvers/test/amg_tests.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cg!(y,A,b;Pl,verbose=true)
6969

7070
# Now in parallel
7171

72-
parts_per_dir = (4,4)
72+
parts_per_dir = (1,2)
7373
np = prod(parts_per_dir)
7474
parts = DebugArray(LinearIndices((np,)))
7575

@@ -100,6 +100,7 @@ finalize!(solver)(S)
100100

101101
level_params = amg_level_params(;
102102
pre_smoother = jacobi(;iters=1,omega=2/3),
103+
coarsening = smoothed_aggregation(;repartition_threshold=10000000)
103104
)
104105

105106
fine_params = amg_fine_params(;
@@ -112,15 +113,8 @@ Pl = preconditioner(solver,y,A,b)
112113
y .= 0
113114
cg!(y,A,b;Pl,verbose=true)
114115

115-
level_params = amg_level_params(;
116-
pre_smoother = richardson(additive_schwarz(gauss_seidel(;iters=1)),iters=1),
117-
)
118-
119-
fine_params = amg_fine_params(;
120-
level_params,
121-
n_fine_levels=5)
122116

123-
solver = amg(;fine_params)
117+
solver = amg()
124118

125119
Pl = preconditioner(solver,y,A,b)
126120
y .= 0

src/p_sparse_matrix.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,7 @@ function LinearAlgebra.mul!(c::PVector,at::Transpose{T,<:PSparseMatrix} where T,
18171817
a = at.parent
18181818
@assert a.assembled
18191819
map(ghost_values(c),own_ghost_values(a),own_values(b)) do ch,aoh,bo
1820+
fill!(ch,zero(eltype(ch)))
18201821
atoh = transpose(aoh)
18211822
mul!(ch,atoh,bo,α,1)
18221823
end

0 commit comments

Comments
 (0)