Skip to content

pyop3: compiled assignment in "inc" mode gives wrong values in parallel #5642

Open

Description

@sghelichkhani

On more than one rank, an eager pyop3 assignment in "inc" mode with eager_strategy="compile" gives wrong values. The "array" strategy gives the right values.

from firedrake import *
import numpy as np

mesh = UnitSquareMesh(6, 6)
V = FunctionSpace(mesh, "CG", 1)
g = Function(V).assign(1)

for strategy in ["array", "compile"]:
    f = Function(V).assign(1)
    f.dat.assign(g.dat, "inc", eager=True, eager_strategy=strategy)
    nwrong = mesh.comm.allreduce(np.count_nonzero(f.dat.data_ro != 2))
    PETSc.Sys.Print(f"{strategy}: {nwrong} owned entries differ from 2")

On main (ed5fcad) with mpiexec -n 3 this prints

array: 0 owned entries differ from 2
compile: 31 owned entries differ from 2

On 1 rank both strategies are correct. On 2 and 4 ranks the compile strategy gives 19 and 29 wrong owned entries. The lazy form f.dat.iassign(g.dat)() gives the same wrong values, and so does op3.loop(p := V.nodes.iter(), f.dat[p].iassign(g.dat[p]), eager=True).

The wrong entries are the owned entries that are ghost entries on other ranks. Each of them gets g once from its own rank and once more from every rank that holds it as a ghost, so its value is 2 plus the number of ghost copies. Before the halo exchange the ghost entries hold 0 + g, so the compiled assignment visits them as well, and the INC halo exchange then adds them to their owners.

Is "inc" meant to work for an assignment to a whole Dat with ghost entries? Or is INC only valid in a loop over owned entities?

An LLM (Claude Code) found this while I was digging into other pyop3 assignment work. G-ADOPT does not use this path but I am flagging it anyway.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions