Skip to content

Commit 85e7304

Browse files
Merge pull request #2972 from devitocodes/hotfix-halo-exchange
mpi: Prevent parallel halo exchanges
2 parents 41e92cc + f5af2f6 commit 85e7304

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

devito/ir/stree/algorithms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ def preprocess(clusters, options=None, **kwargs):
218218
# dimension requiring a loc-index in the HaloScheme. The compiler
219219
# will generate the non-perfect loop nest `t,f ; t,x,y,z,f`, with
220220
# the first nest triggering all necessary halo exchanges along `f`
221-
mapper = as_mapper(found, lambda c1: c1.ispace)
222-
for k, v in mapper.items():
221+
mapper = as_mapper(found, lambda c1: (c1.ispace, c1.properties))
222+
for v in mapper.values():
223223
hs = HaloScheme.union([c1.halo_scheme for c1 in v])
224-
processed.append(c.rebuild(exprs=[], ispace=k, halo_scheme=hs))
224+
processed.append(v[0].rebuild(exprs=[], halo_scheme=hs))
225225
processed.append(c)
226226
else:
227227
# Avoid ugly empty loops

tests/test_mpi.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,38 @@ def test_lift_halo_update_outside_distributed(self, mode):
22422242
halo_update = tloop.nodes[0].body[0].body[0].body[0]
22432243
assert isinstance(halo_update, HaloUpdateList)
22442244

2245+
@pytest.mark.parallel(mode=4)
2246+
def test_ensure_halo_updates_within_seq_loops(self, mode):
2247+
n = 30
2248+
grid = Grid(shape=(n, n))
2249+
2250+
x, y = grid.dimensions
2251+
d = Dimension(name="d")
2252+
2253+
a = Function(name="a", grid=grid, space_order=8)
2254+
b = a.func(name='b')
2255+
2256+
g = Function(name="g", grid=grid, space_order=8, dimensions=(x, y, d),
2257+
shape=(n, n, 2))
2258+
h = g.func(name='h')
2259+
2260+
eqns = [Eq(a, 0.0),
2261+
Eq(h, b * g),
2262+
Inc(a, b * (h.dx + h.dy))]
2263+
2264+
op = Operator(eqns, opt=('advanced', {'openmp': True}))
2265+
_ = op.cfunction
2266+
2267+
# Check generated code -- expected one halo exchange within a sequential
2268+
# `d` loop
2269+
assert_structure(op, ['x,y', 'x,y,d', 'd', 'x,y,d'], 'xyddxyd')
2270+
iters = FindNodes(Iteration).visit(op)
2271+
assert iters[2].dim is d and iters[2].is_Parallel
2272+
assert iters[3].dim is d and iters[3].is_Sequential
2273+
2274+
# Probably unnecessary, but ensures there's no hanging
2275+
op.apply()
2276+
22452277
@pytest.mark.parallel(mode=4)
22462278
def test_halo_inner_dim(self, mode):
22472279
grid = Grid((11, 11, 11))

0 commit comments

Comments
 (0)