r/CFD • u/PerspectiveNo794 • 4d 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!
2
u/marsriegel 4d 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.
2
u/btrettel 3d ago
Some people do argue for bitwise reproducibility, for example:
https://blog.khinsen.net/posts/2015/01/07/Why-bitwise-reproducibility-matters.html
https://doi.org/10.5194/gmdd-8-4375-2015
https://www.marshallward.org/fortrancon2021
It's definitely an uncommon opinion, though. My personal view is that bitwise reproducibility is nice, but it's far more important that floating point error is small. You can have a bitwise reproducible software with huge floating point error.
2
u/Overunderrated 3d ago edited 3d 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.
1
u/Silveriver118 3d ago
They are really good questions.
Yes, it is useful in practice. It is actually more important than many people think.
Bitwise consistence is used in some commercial CFD software packages. Sometimes close enough is fine but inconsistent results are always annoying for developers.
If results are changed due to the order of operations, it doesn't mean the setup is wrong.