r/CFD • u/PerspectiveNo794 • 13d ago
Deterministic simulation testing from distributed systems: does it have a place in CFD solver development?
Okay so I’m still pretty new to the solver side of CFD, but I came across this article and it kind of blew my mind: https://martinfowler.com/articles/deterministic-simulation-testing.html
It’s actually about distributed systems, not CFD at all, but the idea is that you make your program run exactly the same way every single time, down to the last bit. So if a bug shows up once, you can replay it perfectly and step through it instead of crossing your fingers that it happens again.
What got me thinking was learning that floating-point addition isn’t associative?? Like (a + b) + c can give a slightly different answer than a + (b + c). I had no idea. And apparently in parallel solvers the order things get added up can change from run to run depending on which threads or processes finish first. So in theory the exact same case could give you slightly different residuals each time you run it. That’s wild to me.
From what I understand, getting rid of that would mean forcing the additions to always happen in the same order, seeding anything random, and avoiding compiler optimizations that reorder math. Which I’m guessing makes things slower?
So I have a bunch of questions for people who actually write solvers:
- Is this something you actually run into in practice, or is it mostly a theoretical thing?
- Does anyone go out of their way to make their runs bit-for-bit reproducible, or is “close enough” fine?
- If results change depending on the order of additions, does that mean something’s wrong with the setup itself?
Sorry if these are dumb questions, just found this really interesting and wanted to hear from people who know way more than me!
View all comments
3
u/marsriegel 13d ago
Practically speaking this probably won’t make a difference aside maybe from fringe codes wo want to optimize things with custom number formats. For the lower fidelity models you won’t encounter a big difference as we normally run in double precision and the solution accuracy is several orders of magnitude below floating point precision anyway. And yes ensuring the exact execution order will be slow.
It is however known that non associative addition can lead to symmetry breaking in high order codes, but the things we solve with scale resolving methods are chaotic anyway and whether it’s accumulated floating point truncation or a physical tripping of this chaotic state doesn’t really matter too much. In short, we don’t really worry too much about that.