From 878860a859bb254c3767d7750dda7d9d54c0abc1 Mon Sep 17 00:00:00 2001 From: Patrick Farrell Date: Wed, 20 Nov 2024 16:17:04 +0000 Subject: [PATCH] Add functionality to print patch statistics in ASMStarPC and friends --- firedrake/preconditioners/asm.py | 26 +++++++++++++++++++++++++- tests/regression/test_star_pc.py | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/firedrake/preconditioners/asm.py b/firedrake/preconditioners/asm.py index 19738fe438..f305495d81 100644 --- a/firedrake/preconditioners/asm.py +++ b/firedrake/preconditioners/asm.py @@ -33,7 +33,7 @@ def initialize(self, pc): # Extract function space and mesh to obtain plex and indexing functions V = get_function_space(dm) - # Obtain patches from user defined funtion + # Obtain patches from user defined function ises = self.get_patches(V) # PCASM expects at least one patch, so we define an empty one on idle processes if len(ises) == 0: @@ -103,6 +103,30 @@ def get_patches(self, V): def view(self, pc, viewer=None): self.asmpc.view(viewer=viewer) + self.prefix = pc.getOptionsPrefix() + self._prefix + + if viewer is not None: + opts = PETSc.Options(self.prefix) + print_statistics = opts.getBool("print_patch_statistics", default=False) + + if print_statistics: + from mpi4py import MPI + + dm = pc.getDM() + V = get_function_space(dm) + + # Obtain patches from user defined function + ises = self.get_patches(V) + # PCASM expects at least one patch, so we define an empty one on idle processes + if len(ises) == 0: + ises = [PETSc.IS().createGeneral(numpy.empty(0, dtype=IntType), comm=PETSc.COMM_SELF)] + + max_local_patch = max(is_.getSize() for is_ in ises) + min_local_patch = min(is_.getSize() for is_ in ises) + max_global_patch = pc.comm.tompi4py().allreduce(max_local_patch, op=MPI.MAX) + min_global_patch = pc.comm.tompi4py().allreduce(min_local_patch, op=MPI.MIN) + + viewer.printfASCII(f"Minimum / maximum patch sizes: {min_global_patch} / {max_global_patch}\n") def update(self, pc): # This is required to update an inplace ILU factorization diff --git a/tests/regression/test_star_pc.py b/tests/regression/test_star_pc.py index ba1f065eca..cd6c05cdc9 100644 --- a/tests/regression/test_star_pc.py +++ b/tests/regression/test_star_pc.py @@ -41,6 +41,7 @@ def test_star_equivalence(problem_type, backend): star_params = {"mat_type": "aij", "snes_type": "ksponly", + "snes_view": None, "ksp_type": "richardson", "pc_type": "mg", "pc_mg_type": "multiplicative", @@ -50,6 +51,7 @@ def test_star_equivalence(problem_type, backend): "mg_levels_ksp_max_it": 1, "mg_levels_pc_type": "python", "mg_levels_pc_python_type": "firedrake.ASMStarPC", + "mg_levels_pc_star_print_patch_statistics": None, "mg_levels_pc_star_construct_dim": 0} comp_params = {"mat_type": "aij",