Skip to content

Commit

Permalink
Add some PETSc destroy to avoid MPICH leak messages (#3036)
Browse files Browse the repository at this point in the history
* Add some PETSc `destroy` to avoid MPICH leak messages

* Tidy up

* Syntax fix

* Re-enable test
  • Loading branch information
garth-wells authored Feb 5, 2024
1 parent 9e967f2 commit 6b7a5a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 7 additions & 6 deletions python/test/unit/fem/test_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ def nested_solve():
ksp_p.setType("preonly")

def monitor(ksp, its, rnorm):
# print("Num it, rnorm:", its, rnorm)
pass

ksp.setTolerances(rtol=1.0e-8, max_it=50)
Expand All @@ -603,8 +602,11 @@ def monitor(ksp, its, rnorm):
x = b.copy()
ksp.solve(b, x)
assert ksp.getConvergedReason() > 0
ksp.destroy()
return b.norm(), x.norm(), nest_matrix_norm(A), nest_matrix_norm(P)
norms = (b.norm(), x.norm(), nest_matrix_norm(A), nest_matrix_norm(P))
pc.destroy(), ksp.destroy()
A.destroy()
b.destroy(), x.destroy()
return norms

def blocked_solve():
"""Blocked (monolithic) solver"""
Expand Down Expand Up @@ -800,11 +802,10 @@ def bc(V):
@pytest.mark.parametrize("mode", [GhostMode.none, GhostMode.shared_facet])
@pytest.mark.parametrize("dtype", [np.float32, np.float64, np.complex64, np.complex128])
def test_basic_assembly_constant(mode, dtype):
"""Tests assembly with Constant
"""Tests assembly with Constant.
The following test should be sensitive to order of flattening the
matrix-valued constant.
"""
xtype = dtype(0).real.dtype
mesh = create_unit_square(MPI.COMM_WORLD, 5, 5, ghost_mode=mode, dtype=xtype)
Expand Down Expand Up @@ -867,7 +868,7 @@ def mat_insert(rows, cols, vals):


def test_pack_coefficients():
"""Test packing of form coefficients ahead of main assembly call"""
"""Test packing of form coefficients ahead of main assembly call."""
mesh = create_unit_square(MPI.COMM_WORLD, 12, 15)
V = functionspace(mesh, ("Lagrange", 1))

Expand Down
4 changes: 2 additions & 2 deletions python/test/unit/fem/test_nonlinear_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ def nested():
Jnorm = nest_matrix_norm(Jmat)
Fnorm = Fvec.norm()
xnorm = x.norm()
Jmat.destroy()
Fvec.destroy()
Jmat.destroy(), Fvec.destroy()
x.destroy()
Pmat.destroy()
return Jnorm, Fnorm, xnorm

def monolithic():
Expand Down
4 changes: 4 additions & 0 deletions python/test/unit/la/test_nullspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def test_nullspace_orthogonal(mesh, degree):
assert not la.is_orthonormal(nullspace, eps=1.0e-4)
la.orthonormalize(nullspace)
assert la.is_orthonormal(nullspace, eps=1.0e-3)
for x in nullspace:
x.destroy()


@pytest.mark.parametrize("mesh", [
Expand Down Expand Up @@ -144,3 +146,5 @@ def sigma(w, gdim):
la.orthonormalize(nullspace)
ns = PETSc.NullSpace().create(vectors=nullspace)
assert not ns.test(A)
for x in nullspace:
x.destroy()

0 comments on commit 6b7a5a4

Please sign in to comment.