BOUT-dev icon indicating copy to clipboard operation
BOUT-dev copied to clipboard

Caching pattern globally not on instances.

Open will-saunders-ukaea opened this issue 4 months ago • 1 comments

I was browsing the mesh implementation to get a better understanding of how it works. I see patterns like [1] which look like they cache instance specific values globally across the entire program. See [2] for example. Maybe I am missing something or have parsed this C++ wrong or maybe you only have one mesh instance per program execution and never hit an issue?

[1] https://github.com/boutproject/BOUT-dev/blob/396f6a7618a6a8dcdc6f9d46e51acb9e38e84d19/src/mesh/mesh.cxx#L426 [2] https://godbolt.org/z/x8h5onMqs

Will

will-saunders-ukaea avatar Aug 14 '25 16:08 will-saunders-ukaea

Yes, a static local variable is per-class for that method, and not per-instance. And indeed, we have one Mesh per MPI process that lives for the whole simulation, although we have (slowly) been trying to get away from that.

I'm not sure why that particular function isn't just computed once in the constructor and stored! That would be a fairly easy fix that would remove the static variable.

ZedThree avatar Aug 14 '25 16:08 ZedThree