Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions devito/ir/stree/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ def preprocess(clusters, options=None, **kwargs):
# dimension requiring a loc-index in the HaloScheme. The compiler
# will generate the non-perfect loop nest `t,f ; t,x,y,z,f`, with
# the first nest triggering all necessary halo exchanges along `f`
mapper = as_mapper(found, lambda c1: c1.ispace)
for k, v in mapper.items():
mapper = as_mapper(found, lambda c1: (c1.ispace, c1.properties))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does c1.properties end up being used here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the actual bug fix

if you don't use the HaloTouch's properties, where the d loop in correctly tagged as sequential, but rather reuse c's properties via rebuild (main's behaviour) then d may erroneously be tagged as parallell depending on its status in c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so the rebuild was actually changing the properties of the innermost dimension of the cluster?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite. We were using the rebuild to create a new Cluster -- a Cluster whose sole purpose was carrying a halo_scheme. But using c's rebuild cause us inheriting the wrong properties

for v in mapper.values():
hs = HaloScheme.union([c1.halo_scheme for c1 in v])
processed.append(c.rebuild(exprs=[], ispace=k, halo_scheme=hs))
processed.append(v[0].rebuild(exprs=[], halo_scheme=hs))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this changing the type being appended to processed from Cluster to IterationSpace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, v[0] is any c1 within v, that is, a Cluster

if what you said were true, many many tests would fail badly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, this is from me misunderstanding as_mapper

processed.append(c)
else:
# Avoid ugly empty loops
Expand Down
32 changes: 32 additions & 0 deletions tests/test_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,38 @@ def test_lift_halo_update_outside_distributed(self, mode):
halo_update = tloop.nodes[0].body[0].body[0].body[0]
assert isinstance(halo_update, HaloUpdateList)

@pytest.mark.parallel(mode=4)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The incorrect code still gets generated with 1 rank of MPI fwiw. It also won't hang CI in this configuration if it does go wrong, and will instead fail on the structure tests

def test_ensure_halo_updates_within_seq_loops(self, mode):
n = 30
grid = Grid(shape=(n, n))

x, y = grid.dimensions
d = Dimension(name="d")

a = Function(name="a", grid=grid, space_order=8)
b = a.func(name='b')

g = Function(name="g", grid=grid, space_order=8, dimensions=(x, y, d),
shape=(n, n, 2))
h = g.func(name='h')

eqns = [Eq(a, 0.0),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these equations can be dropped or simplified iirc. I had something along the lines of:

eqns = [Eq(h, 1), Inc(a, h.dx + h.dy)]

which also allows for the Functions to be tidied up

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I know, but I don't think it hurts to leave it a little bit more convoluted, in this particular case and based on what I see while I was debugging it

Eq(h, b * g),
Inc(a, b * (h.dx + h.dy))]

op = Operator(eqns, opt=('advanced', {'openmp': True}))
_ = op.cfunction

# Check generated code -- expected one halo exchange within a sequential
# `d` loop
assert_structure(op, ['x,y', 'x,y,d', 'd', 'x,y,d'], 'xyddxyd')
iters = FindNodes(Iteration).visit(op)
assert iters[2].dim is d and iters[2].is_Parallel
assert iters[3].dim is d and iters[3].is_Sequential

# Probably unnecessary, but ensures there's no hanging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hanging CI is annoying at best and I agree the .apply() is overkill

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't hang anyway since we run it under a timeout of 300 secs -- not sign of life in 5 mins => death

op.apply()

@pytest.mark.parallel(mode=4)
def test_halo_inner_dim(self, mode):
grid = Grid((11, 11, 11))
Expand Down
Loading