Hi Barry, On 15/02/18 04:43, Smith, Barry F. wrote: > > https://bitbucket.org/petsc/petsc/pull-requests/858/add-support-for-selecting-different-down/diff
Great, thanks! That was simpler than I was envisaging. I note it does the wrong thing if I say both -pc_mg_distinct_smoothup and -pc_mg_smoothup/down n. I proposed a fix in the PR, but have attached the git format-patch output to this mail too. Cheers, Lawrence
>From 29d273c1b71ff249c65fe03e74089a837305f230 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell <[email protected]> Date: Thu, 15 Feb 2018 16:16:24 +0000 Subject: [PATCH] PCMG: ensure distinct options prefix for PCMGSetDistinctSmoothUp --- src/ksp/ksp/examples/tutorials/ex29.c | 4 + src/ksp/ksp/examples/tutorials/output/ex29_4.out | 163 +++++++++++++++++++++++ src/ksp/pc/impls/mg/mg.c | 6 +- 3 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 src/ksp/ksp/examples/tutorials/output/ex29_4.out diff --git a/src/ksp/ksp/examples/tutorials/ex29.c b/src/ksp/ksp/examples/tutorials/ex29.c index a403982..f7afc60 100644 --- a/src/ksp/ksp/examples/tutorials/ex29.c +++ b/src/ksp/ksp/examples/tutorials/ex29.c @@ -227,4 +227,8 @@ PetscErrorCode ComputeMatrix(KSP ksp,Mat J,Mat jac,void *ctx) suffix: 3 args: -ksp_view -da_refine 2 -pc_type mg -pc_mg_distinct_smoothup -mg_levels_up_pc_type jacobi + test: + suffix: 4 + args: -ksp_view -da_refine 2 -pc_type mg -pc_mg_smoothdown 3 -pc_mg_distinct_smoothup -mg_levels_up_pc_type jacobi + TEST*/ diff --git a/src/ksp/ksp/examples/tutorials/output/ex29_4.out b/src/ksp/ksp/examples/tutorials/output/ex29_4.out new file mode 100644 index 0000000..c9a9001 --- /dev/null +++ b/src/ksp/ksp/examples/tutorials/output/ex29_4.out @@ -0,0 +1,163 @@ +KSP Object: 1 MPI processes + type: gmres + restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement + happy breakdown tolerance 1e-30 + maximum iterations=10000, initial guess is zero + tolerances: relative=1e-05, absolute=1e-50, divergence=10000. + left preconditioning + using PRECONDITIONED norm type for convergence test +PC Object: 1 MPI processes + type: mg + type is MULTIPLICATIVE, levels=3 cycles=v + Cycles per PCApply=1 + Not using Galerkin computed coarse grid matrices + Coarse grid solver -- level ------------------------------- + KSP Object: (mg_coarse_) 1 MPI processes + type: preonly + maximum iterations=10000, initial guess is zero + tolerances: relative=1e-05, absolute=1e-50, divergence=10000. + left preconditioning + using NONE norm type for convergence test + PC Object: (mg_coarse_) 1 MPI processes + type: lu + out-of-place factorization + tolerance for zero pivot 2.22045e-14 + using diagonal shift on blocks to prevent zero pivot [INBLOCKS] + matrix ordering: nd + factor fill ratio given 5., needed 1.54545 + Factored matrix follows: + Mat Object: 1 MPI processes + type: seqaij + rows=9, cols=9 + package used to perform factorization: petsc + total: nonzeros=51, allocated nonzeros=51 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines + linear system matrix = precond matrix: + Mat Object: 1 MPI processes + type: seqaij + rows=9, cols=9 + total: nonzeros=33, allocated nonzeros=33 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines + Down solver (pre-smoother) on level 1 ------------------------------- + KSP Object: (mg_levels_1_) 1 MPI processes + type: chebyshev + eigenvalue estimates used: min = 0.1, max = 1.1 + eigenvalues estimate via gmres min 0.642839, max 1. + eigenvalues estimated using gmres with translations [0. 0.1; 0. 1.1] + KSP Object: (mg_levels_1_esteig_) 1 MPI processes + type: gmres + restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement + happy breakdown tolerance 1e-30 + maximum iterations=10, initial guess is zero + tolerances: relative=1e-12, absolute=1e-50, divergence=10000. + left preconditioning + using PRECONDITIONED norm type for convergence test + estimating eigenvalues using noisy right hand side + maximum iterations=3, initial guess is zero + tolerances: relative=1e-05, absolute=1e-50, divergence=10000. + left preconditioning + using NONE norm type for convergence test + PC Object: (mg_levels_1_) 1 MPI processes + type: sor + type = local_symmetric, iterations = 1, local iterations = 1, omega = 1. + linear system matrix = precond matrix: + Mat Object: 1 MPI processes + type: seqaij + rows=25, cols=25 + total: nonzeros=105, allocated nonzeros=105 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines + Up solver (post-smoother) on level 1 ------------------------------- + KSP Object: (mg_levels_1_up_) 1 MPI processes + type: chebyshev + eigenvalue estimates used: min = 0.170711, max = 1.87782 + eigenvalues estimate via gmres min 0.292893, max 1.70711 + eigenvalues estimated using gmres with translations [0. 0.1; 0. 1.1] + KSP Object: (mg_levels_1_up_esteig_) 1 MPI processes + type: gmres + restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement + happy breakdown tolerance 1e-30 + maximum iterations=10, initial guess is zero + tolerances: relative=1e-12, absolute=1e-50, divergence=10000. + left preconditioning + using PRECONDITIONED norm type for convergence test + estimating eigenvalues using noisy right hand side + maximum iterations=2, nonzero initial guess + tolerances: relative=1e-05, absolute=1e-50, divergence=10000. + left preconditioning + using NONE norm type for convergence test + PC Object: (mg_levels_1_up_) 1 MPI processes + type: jacobi + linear system matrix = precond matrix: + Mat Object: 1 MPI processes + type: seqaij + rows=25, cols=25 + total: nonzeros=105, allocated nonzeros=105 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines + Down solver (pre-smoother) on level 2 ------------------------------- + KSP Object: (mg_levels_2_) 1 MPI processes + type: chebyshev + eigenvalue estimates used: min = 0.100018, max = 1.1002 + eigenvalues estimate via gmres min 0.250619, max 1.00018 + eigenvalues estimated using gmres with translations [0. 0.1; 0. 1.1] + KSP Object: (mg_levels_2_esteig_) 1 MPI processes + type: gmres + restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement + happy breakdown tolerance 1e-30 + maximum iterations=10, initial guess is zero + tolerances: relative=1e-12, absolute=1e-50, divergence=10000. + left preconditioning + using PRECONDITIONED norm type for convergence test + estimating eigenvalues using noisy right hand side + maximum iterations=3, initial guess is zero + tolerances: relative=1e-05, absolute=1e-50, divergence=10000. + left preconditioning + using NONE norm type for convergence test + PC Object: (mg_levels_2_) 1 MPI processes + type: sor + type = local_symmetric, iterations = 1, local iterations = 1, omega = 1. + linear system matrix = precond matrix: + Mat Object: 1 MPI processes + type: seqaij + rows=81, cols=81 + total: nonzeros=369, allocated nonzeros=369 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines + Up solver (post-smoother) on level 2 ------------------------------- + KSP Object: (mg_levels_2_up_) 1 MPI processes + type: chebyshev + eigenvalue estimates used: min = 0.192344, max = 2.11578 + eigenvalues estimate via gmres min 0.0875558, max 1.92344 + eigenvalues estimated using gmres with translations [0. 0.1; 0. 1.1] + KSP Object: (mg_levels_2_up_esteig_) 1 MPI processes + type: gmres + restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement + happy breakdown tolerance 1e-30 + maximum iterations=10, initial guess is zero + tolerances: relative=1e-12, absolute=1e-50, divergence=10000. + left preconditioning + using PRECONDITIONED norm type for convergence test + estimating eigenvalues using noisy right hand side + maximum iterations=2, nonzero initial guess + tolerances: relative=1e-05, absolute=1e-50, divergence=10000. + left preconditioning + using NONE norm type for convergence test + PC Object: (mg_levels_2_up_) 1 MPI processes + type: jacobi + linear system matrix = precond matrix: + Mat Object: 1 MPI processes + type: seqaij + rows=81, cols=81 + total: nonzeros=369, allocated nonzeros=369 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines + linear system matrix = precond matrix: + Mat Object: 1 MPI processes + type: seqaij + rows=81, cols=81 + total: nonzeros=369, allocated nonzeros=369 + total number of mallocs used during MatSetValues calls =0 + not using I-node routines diff --git a/src/ksp/pc/impls/mg/mg.c b/src/ksp/pc/impls/mg/mg.c index 1451985..477cca6 100644 --- a/src/ksp/pc/impls/mg/mg.c +++ b/src/ksp/pc/impls/mg/mg.c @@ -1283,10 +1283,12 @@ PetscErrorCode PCMGSetDistinctSmoothUp(PC pc) levels = mglevels[0]->levels; for (i=1; i<levels; i++) { - if (mglevels[i]->smoothu != mglevels[i]->smoothd) continue; - + const char *prefix = NULL; /* make sure smoother up and down are different */ ierr = PCMGGetSmootherUp(pc,i,&subksp);CHKERRQ(ierr); + /* Avoid repeated concatenation if called more than once. */ + ierr = KSPGetOptionsPrefix(mglevels[i]->smoothd,&prefix);CHKERRQ(ierr); + ierr = KSPSetOptionsPrefix(subksp,prefix);CHKERRQ(ierr); ierr = KSPAppendOptionsPrefix(subksp,"up_");CHKERRQ(ierr); } PetscFunctionReturn(0); -- 2.7.0.297.g563e384
