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

Tidying #569

Merged
merged 7 commits into from
May 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Firedrake backend: Cache local indices
jrmaddison committed May 29, 2024
commit 97a38a996b90c1d7b2fb0b78f78987afce633ad7
19 changes: 15 additions & 4 deletions tlm_adjoint/firedrake/backend_patches.py
Original file line number Diff line number Diff line change
@@ -252,14 +252,26 @@ def new_space_id_cached(space):
return space_ids[key]


def space_local_indices_cached(space, cls):
if not hasattr(space, "_tlm_adjoint__local_indices"):
space._tlm_adjoint__local_indices = {}
local_indices = space._tlm_adjoint__local_indices

# Work around Firedrake issue #3130
key = (space, ufl.duals.is_primal(space))
if key not in local_indices:
with cls(space).dat.vec_ro as x_v:
local_indices[key] = x_v.getOwnershipRange()
return local_indices[key]


@patch_method(backend_FunctionSpace, "__init__")
def FunctionSpace__init__(self, orig, orig_args, *args, **kwargs):
orig_args()
add_interface(self, FunctionSpaceInterface,
{"space": self, "comm": comm_dup_cached(self.comm),
"id": new_space_id_cached(self)})
with backend_Function(self).dat.vec_ro as x_v:
n0, n1 = x_v.getOwnershipRange()
n0, n1 = space_local_indices_cached(self, backend_Function)
self._tlm_adjoint__space_interface_attrs["local_indices"] = (n0, n1)


@@ -279,8 +291,7 @@ def CofunctionSpace__init__(self, orig, orig_args, *args, **kwargs):
add_interface(self, FunctionSpaceInterface,
{"space_dual": self, "comm": comm_dup_cached(self.comm),
"id": new_space_id_cached(self)})
with backend_Cofunction(self).dat.vec_ro as x_v:
n0, n1 = x_v.getOwnershipRange()
n0, n1 = space_local_indices_cached(self, backend_Cofunction)
self._tlm_adjoint__space_interface_attrs["local_indices"] = (n0, n1)