@@ -260,10 +260,33 @@ function omega_for_1d_laplace(invD,A)
260260 2 / 3
261261end
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+
263284function 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(;
289312end
290313
291314function 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)
0 commit comments