Somehow Enzyme mutates an array

33 views
Skip to first unread message

Onur Akdemir

unread,
Dec 14, 2023, 10:24:24 AM12/14/23
to Enzyme AD
Hi, 

I have kinda spooky condition with Enzyme and maybe you can give insights to locate the error.

Background: I'm using Enzyme to calculate Jacobian in my CFD code. I need to set the neighbor cell value based on face type (interior, Neumann, or Dirichlet). If the face is interior, the neighbor cell value is the actual neighboring cell; if Neumann, it's the center cell value. These are working well. However, when it comes to Dirichlet, where I get the cell value from an array, I encounter an issue. After running the Jacobian, my array holding boundary values is changed when using Enzyme. It's worth noting that when I use PETSc's Jacobian via graph coloring, there is no problem, so looks like my residual calculation function is not mutating boundary array.

The most interesting part (for me) is that in my CFD code, I separately solve momentum and pressure equations. And this issue only arises in the pressure equation. In momentum equation there is no problem. The problematic code snippet is:

if (user->PFaceType[face][0] == DRICHLET) { pN = user->PBoundaryVal[face][0]; }

If I include this part, my code fails with Enzyme. However, if I set pN = 0 hardcoded, there is no problem.

I am using latest Enzyme version with LLVM 16. Actually I wanted to include my code but it has many LOCs but if you tell me where to look specifically I can provide you something.

Thanks,

Manuel Drehwald

unread,
Dec 21, 2023, 8:03:31 PM12/21/23
to Enzyme AD
Sorry to hear you had an issue. Can you please create an issue under github.com/EnzymeAD/Enzyme for the compilation failure?
Some reasons for the compilation might be easy to fix, as a minimum a stack trace (and whatever Enzyme prints before) will be needed to see the error.

For the first issue it would be good if you could minimize this to some minimized reproducer where Enzyme modifies arrays that it shouldn't write to.
Reply all
Reply to author
Forward
0 new messages