Skip to content

Commit 19cfcb6

Browse files
authored
Merge pull request #2582 from devitocodes/fixup-mpi-bundles
mpi: Fix correctness of halo exchanges for Bundles
2 parents 0c9f18b + f7ff108 commit 19cfcb6

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

devito/mpi/halo_scheme.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,32 @@ class HaloSchemeEntry(EnrichedTuple):
3131

3232
__rargs__ = ('loc_indices', 'loc_dirs', 'halos', 'dims')
3333

34-
def __init__(self, loc_indices, loc_dirs, halos, dims, getters=None):
35-
self.loc_indices = frozendict(loc_indices)
36-
self.loc_dirs = frozendict(loc_dirs)
37-
self.halos = frozenset(halos)
38-
self.dims = frozenset(dims)
34+
def __new__(cls, loc_indices, loc_dirs, halos, dims, getters=None):
35+
items = [frozendict(loc_indices), frozendict(loc_dirs),
36+
frozenset(halos), frozenset(dims)]
37+
kwargs = dict(zip(cls.__rargs__, items))
38+
return super().__new__(cls, *items, getters=cls.__rargs__, **kwargs)
3939

4040
def __hash__(self):
41-
return hash((self.loc_indices,
42-
self.loc_dirs,
43-
self.halos,
44-
self.dims))
41+
return hash((self.loc_indices, self.loc_dirs, self.halos, self.dims))
42+
43+
def union(self, other):
44+
"""
45+
Return a new HaloSchemeEntry that is the union of this and `other`.
46+
The `loc_indices` and `loc_dirs` must be the same, otherwise an
47+
exception is raised.
48+
"""
49+
if self.loc_indices != other.loc_indices or \
50+
self.loc_dirs != other.loc_dirs:
51+
raise HaloSchemeException(
52+
"Inconsistency found while building a HaloScheme"
53+
)
54+
55+
halos = self.halos | other.halos
56+
dims = self.dims | other.dims
57+
58+
return HaloSchemeEntry(self.loc_indices, self.loc_dirs, halos, dims,
59+
getters=self.getters)
4560

4661

4762
Halo = namedtuple('Halo', 'dim side')
@@ -410,9 +425,11 @@ def add(self, f, hse):
410425
"""
411426
Create a new HaloScheme that contains all entries in `self` plus the one
412427
passed in input. If `f` already exists in `self`, the old value is
413-
overridden.
428+
augmented with `hse` (i.e., the halos are unioned).
414429
"""
415-
fmapper = dict(self.fmapper.items())
430+
fmapper = dict(self.fmapper)
431+
if f in fmapper:
432+
hse = fmapper[f].union(hse)
416433
fmapper[f] = hse
417434
return HaloScheme.build(fmapper, self.honored)
418435

devito/mpi/routines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ def _arg_defaults(self, allocator, alias, args=None):
12171217

12181218
def _arg_values(self, args=None, **kwargs):
12191219
# Any will do
1220-
for f in self.target.handles:
1220+
for f in self.target.components:
12211221
try:
12221222
alias = kwargs[f.name]
12231223
break

devito/tools/data_structures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def __getitem_hook__(self, key):
8282
def __getnewargs_ex__(self):
8383
# Bypass default reconstruction logic since this class spawns
8484
# objects with varying number of attributes
85-
return tuple(self), dict(self.__dict__)
85+
sdict = {k: v for k, v in self.__dict__.items() if k not in self.getters}
86+
return tuple(self), sdict
8687

8788
def get(self, key, val=None):
8889
return self.getters.get(key, val)

devito/tools/dtypes_lowering.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ def dtype_len(dtype):
218218
"""
219219
try:
220220
# Vector types
221-
return len(dtype)
221+
dlen = len(dtype)
222+
if 'padding0' in dtype.fields:
223+
dlen -= 1
224+
return dlen
222225
except TypeError:
223226
return 1
224227

0 commit comments

Comments
 (0)