r/CFD • u/PerspectiveNo794 • 12d 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
2
u/Overunderrated 11d ago edited 11d ago
Run into it all the time in practice. Developing cfd codes requires automated testing which requires you to check exactness/correctness/regressions on floating point data, both integrated scalar quantities like lift and drag but also convergence histories. Main sources of variance in those are often (1) parallel-related, where reductions are often non-deterministic, and partitioning where many common preconditioners and solvers are algebraically different than they are in serial, and atomic operations, and (2) different optimizations for different instruction sets, e.g. you're likely to see a little convergence history noise difference between say avx2 and avx512 for any sufficiently complex simulation.
I have seen both bit-for-bit and close-enough. My preference in development is probably to do a "close-enough" automated test with very tight tolerance, and if you end up seeing that test failing on different new hardware, use judgment to loosen the tolerance or make a hardware-specific reference value.
Nope. Algorithmic reality. But hopefully results changes are in the noise (often they're not and something bad happens).
I'd add that there are multiple levels of testing in cfd dev; while entire-sim bit-for-bit exactness or determinism might not be realistic, finer-grained unit tests can be.