Skip to content

Commit 1475515

Browse files
committed
Save weak references to all fields built on a distributor, to help track fields and memory usage
1 parent 5d7a1e9 commit 1475515

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

dedalus/core/distributor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections import OrderedDict
1010
from math import prod
1111
import numbers
12+
from weakref import WeakSet
1213

1314
from .coords import CoordinateSystem, DirectProduct
1415
from ..tools.array import reshape_vector
@@ -112,6 +113,8 @@ def __init__(self, coordsystems, comm=None, mesh=None, dtype=None):
112113
self.comm_coords = np.array(self.comm_cart.coords, dtype=int)
113114
# Build layout objects
114115
self._build_layouts()
116+
# Keep set of weak field references
117+
self.fields = WeakSet()
115118

116119
@CachedAttribute
117120
def cs_by_axis(self):

dedalus/core/field.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ def __init__(self, dist, bases=None, name=None, tensorsig=None, dtype=None):
572572
self.layout = self.dist.get_layout_object('c')
573573
# Change scales to build buffer and data
574574
self.preset_scales((1,) * self.dist.dim)
575+
# Add weak reference to distributor
576+
dist.fields.add(self)
575577

576578
def __getitem__(self, layout):
577579
"""Return data viewed in specified layout."""

0 commit comments

Comments
 (0)