Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the FormSum memory leak #3897

Merged
merged 12 commits into from
Dec 6, 2024
11 changes: 9 additions & 2 deletions firedrake/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import itertools
from itertools import product
import numbers
import numpy as np

import cachetools
import finat
Expand Down Expand Up @@ -469,8 +470,14 @@ def base_form_assembly_visitor(self, expr, tensor, *args):
return sum(weight * arg for weight, arg in zip(expr.weights(), args))
elif all(isinstance(op, firedrake.Cofunction) for op in args):
V, = set(a.function_space() for a in args)
res = sum([w*op.dat for (op, w) in zip(args, expr.weights())])
return firedrake.Cofunction(V, res)
result = firedrake.Cofunction(V)
for op, w in zip(args, expr.weights()):
for dat_result, dat_op in zip(result.dat.split, op.dat.split):
np.add(
dat_result.data_ro_with_halos,
w * dat_op.data_ro_with_halos,
out=dat_result.data_wo_with_halos)
Ig-dolci marked this conversation as resolved.
Show resolved Hide resolved
Ig-dolci marked this conversation as resolved.
Show resolved Hide resolved
return result
elif all(isinstance(op, ufl.Matrix) for op in args):
res = tensor.petscmat if tensor else PETSc.Mat()
is_set = False
Expand Down