Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrubeck committed Jan 10, 2025
1 parent 7ec4160 commit 8699c3c
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions firedrake/preconditioners/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from firedrake.dmhooks import get_function_space
from firedrake.logging import warning
from tinyasm import _tinyasm as tinyasm
from mpi4py import MPI
import numpy


Expand Down Expand Up @@ -90,6 +91,16 @@ def initialize(self, pc):
asmpc.setFromOptions()
self.asmpc = asmpc

self._patch_statistics = []
if opts.getBool("print_patch_statistics", default=False):
# Compute and stash patch statistics
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)
msg = f"Minimum / maximum patch sizes: {min_global_patch} / {max_global_patch}\n"
self._patch_statistics.append(msg)

@abc.abstractmethod
def get_patches(self, V):
''' Get the patches used for PETSc PCASM
Expand All @@ -103,30 +114,9 @@ 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")
for msg in self._patch_statistics:
viewer.printfASCII(msg)

def update(self, pc):
# This is required to update an inplace ILU factorization
Expand Down

0 comments on commit 8699c3c

Please sign in to comment.