devitocodes / devito

DSL and compiler framework for automated finite-differences and stencil computation
http://www.devitoproject.org
MIT License
564 stars 229 forks source link

Illegal parallel code with global symbols in absence of explicit data dependencies #2061

Open FabioLuporini opened 1 year ago

FabioLuporini commented 1 year ago

Reproducer:

import numpy as np

from devito import *
from devito.types import Symbol

configuration['language'] = 'openmp'

grid = Grid(shape=(10,))
x, = grid.dimensions

f = Function(name='f', grid=grid, space_order=0)
s = Symbol(name='s', dtype=np.int32)

eqns = [Eq(s, 0),
        Eq(f[s], x),
        Eq(s, s + 1, implicit_dims=(x,))]

op = Operator(eqns)

op.apply()

assert np.all(f.data == list(range(10)))

Without openmp, this assert passes

FabioLuporini commented 1 year ago

Copy-pasting from slack:

The fix [...] isn’t obvious at all, since here we have sequentialism dictated by an irregular access, not an explicit dependence across two accesses (so it sort of escapes the lamport framework), and so far we’re only looking at explicit dependences (see here https://github.com/devitocodes/devito/blob/master/devito/ir/clusters/analysis.py#L88)

georgebisbas commented 1 year ago

Link to slack: https://devitocodes.slack.com/archives/C7JMLMSG0/p1675846801725969