Skip to content

Commit

Permalink
misc: Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
EdCaunt committed Feb 2, 2024
1 parent c4cf704 commit 588c25e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 48 deletions.
45 changes: 24 additions & 21 deletions devito/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,6 @@ def _dist_dimensions(self):
if self._distributor is None:
return ()
else:
# NOTE: changed some stuff here. May need reverting
return tuple(d for d in self.dimensions if d in self._distributor.dimensions)

@cached_property
Expand Down Expand Up @@ -1294,23 +1293,9 @@ def _offset_owned(self):

return DimensionTuple(*offsets, getters=self.dimensions, left=left, right=right)

@property
def _data_alignment(self):
"""
The base virtual address of the data carried by the object is a multiple
of the alignment.
"""
return default_allocator().guaranteed_alignment

def indexify(self, indices=None, subs=None):
"""Create a types.Indexed from the current object."""
if indices is not None:
return Indexed(self.indexed, *indices)

# Substitution for each index (spacing only used in own dimension)
subs = subs or {}
subs = [{**{d.spacing: 1, -d.spacing: -1}, **subs} for d in self.dimensions]

@cached_property
def _offset_subdomain(self):
"""Offset of subdomain incides versus the global index."""
# If defined on a SubDomain, then need to offset indices accordingly
if self.grid and self.grid.is_SubDomain:
# Symbolic offsets to avoid potential issues with user overrides
Expand All @@ -1329,13 +1314,31 @@ def indexify(self, indices=None, subs=None):
offsets.append(l_sym)
else:
offsets.append(0)
offsets = tuple(offsets)
return tuple(offsets)
else:
offsets = (0,)*len(self.dimensions)
return (0,)*len(self.dimensions)

@property
def _data_alignment(self):
"""
The base virtual address of the data carried by the object is a multiple
of the alignment.
"""
return default_allocator().guaranteed_alignment

def indexify(self, indices=None, subs=None):
"""Create a types.Indexed from the current object."""
if indices is not None:
return Indexed(self.indexed, *indices)

# Substitution for each index (spacing only used in own dimension)
subs = subs or {}
subs = [{**{d.spacing: 1, -d.spacing: -1}, **subs} for d in self.dimensions]

# Indices after substitutions
indices = []
for a, d, o, s, of in zip(self.args, self.dimensions, self.origin, subs, offsets):
for a, d, o, of, s in zip(self.args, self.dimensions, self.origin,
self._offset_subdomain, subs):
if d in a.free_symbols:
# Shift by origin and offset d -> d - o - of.
indices.append(sympy.sympify(a.subs(d, d - o - of).xreplace(s)))
Expand Down
27 changes: 1 addition & 26 deletions devito/types/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,6 @@ def _size_outhalo(self):
right = [max(i.loc_abs_max+j-i.glb_max, 0) if i and not i.loc_empty else 0
for i, j in zip(self._decomposition, self._size_inhalo.right)]

# TODO: Establish if the following is required
# If defined on a SubDomain then need to adjust halo sizes if the subdomain is
# entirely contained within this rank or is not present on this rank
# if self.grid and self.grid.is_SubDomain:
# # If any are off rank, then all halo sizes should be zero
# if any(self.grid.off_rank):
# left = [0]*len(self.dimensions)
# right = [0]*len(self.dimensions)
# else:
# # If the SubDimension is entirely within a rank, then outhalo size
# # should match inhalo
# left = [i if not self.grid._crosses[j][LEFT] else k for i, j, k
# in zip(self._size_inhalo.left,
# self._distributor.dimensions,
# left)]
# right = [i if not self.grid._crosses[j][RIGHT] else k for i, j, k
# in zip(self._size_inhalo.right,
# self._distributor.dimensions,
# right)]

sizes = tuple(Size(i, j) for i, j in zip(left, right))

if self._distributor.is_parallel and (any(left) or any(right)):
Expand Down Expand Up @@ -582,17 +562,13 @@ def _data_in_region(self, region, dim, side):
Typically, this accessor won't be used in user code to set or read
data values.
"""
if self._distributor:
dims = self._distributor.dimensions
else:
dims = self.dimensions
self._is_halo_dirty = True
offset = getattr(getattr(self, '_offset_%s' % region.name)[dim], side.name)
size = getattr(getattr(self, '_size_%s' % region.name)[dim], side.name)
index_array = [
slice(offset, offset+size) if d is dim else slice(pl, s - pr)
for d, s, (pl, pr)
in zip(dims, self.shape_allocated, self._padding)
in zip(self.dimensions, self.shape_allocated, self._padding)
]
return np.asarray(self._data[index_array])

Expand Down Expand Up @@ -786,7 +762,6 @@ def _halo_exchange(self):
"no Grid attached" % self.name)

neighborhood = self._distributor.neighborhood

comm = self._distributor.comm

for d in self._dist_dimensions:
Expand Down
1 change: 0 additions & 1 deletion tests/test_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def define(self, dimensions):
xi, yi = md.dimensions
d = md.distributor

# Decomposition is [[0, 1, 2, 3], [4, 5, 6], [7, 8, 9]]
rank = grid.distributor.comm.rank
if sd[0] == 'middle':
if rank == 0:
Expand Down

0 comments on commit 588c25e

Please sign in to comment.