Run the same particle simulation twice, once on 4 cores and once on 16, and in most solvers you get two different answers. The heaps look alike and the averages agree to a few digits, but the particle positions do not match, and after enough steps no single grain is where it was in the other run.

This is usually accepted as a fact of life. It does not have to be. A simulation is bitwise reproducible when the same input produces exactly the same output bytes, whatever the number of cores, the processor or the device. This article explains where the differences come from, what they cost, and how the solver is built to avoid them.

Where the differences come from

Floating-point addition depends on order

Computers store real numbers in a fixed number of bits, so most results are rounded. Rounding makes addition lose a property that arithmetic on paper has: it is no longer associative. Adding a to b and then c can give a different last bit than adding b to c and then a.

Three numbers, two orders, two answers

IEEE 754 double precision

One thread(0.1 + 0.2) + 0.30.1 + 0.2 = 0.30000000000000004… + 0.3 = 0.60000000000000010.6000000000000001Two threads0.1 + (0.2 + 0.3)0.2 + 0.3 = 0.50.1 + … = 0.60.6same three numbers, different order, different last bit

Both results are correct roundings of their own sequence of operations. Neither is a bug. They differ by one unit in the last place.

A particle in a packed bed has several contacts, and the force on it is the sum of the contact forces. On one thread those forces are added in one order. Split the work across threads and the order changes, because each thread adds up its own share and the shares are combined afterwards. The same happens with vector instructions that add four or eight values at once, and with a GPU that reduces thousands of values in a tree.

Processors and compilers differ

Order is not the only source. Some processors fuse a multiplication and an addition into a single operation with one rounding instead of two, and a compiler may or may not use it. Library functions such as sine and cosine are not required to return the same last bit on every platform. Move a run from an x86 server to an ARM laptop and the bits can change even on one core.

Granular systems amplify small differences

A difference in the sixteenth digit would not matter if it stayed there. In a granular system it does not. A slightly different force gives a slightly different position, which shifts the moment at which a contact opens or closes, which changes the forces on the neighbours. Collisions amplify small differences, so two runs that agree to sixteen digits at the start can show clearly different particle positions later on.

The bulk statistics often survive: the flow rate, the mean heap angle. The individual trajectories do not, and anything sensitive to a single event, such as an arch forming or a bond breaking, can go either way.

What it costs you

Debugging

A run fails at step three million with a particle leaving the domain. You add output and run it again, and the failure is gone, or it happens somewhere else. When a rerun does not repeat the original, you cannot bisect, cannot add a probe without disturbing the patient, and cannot hand a colleague a case that fails on their machine too. A reproducible run turns a rare event into one you can visit as often as you like.

Calibration

Calibration compares runs that differ in one parameter. Suppose friction goes from 0.50 to 0.52 and the heap angle rises by 0.3 degrees. If the solver’s own run-to-run scatter is also a few tenths of a degree, you cannot tell signal from noise, and you end up averaging many repeats of each point. With exact reproducibility a difference between two runs has only one possible cause, which is the input you changed.

Randomness is still under your control. Changing the seed of a particle factory gives a different packing, and repeating a point with several seeds remains a good way to measure real physical scatter. The point is that you choose when to vary it.

Regression testing

Every solver changes: a new contact model, a faster neighbour search, a compiler upgrade. The question after each change is whether old results still hold. If results are only repeatable within a tolerance, every test needs a tolerance, someone has to pick it, and a real defect smaller than the tolerance passes unseen. If results are exact, the test is a file comparison. A refactoring that should change nothing must change no byte, and one that does is caught at once.

Trust and audit

An engineering result often has to be checked by someone else, sometimes years later. “Run the deck and you will get these files” is a stronger statement than “run the deck and you will get something similar”.

How the solver approaches it

Wind’s solver treats reproducibility as part of its design, not as a setting. The same deck produces the same bytes on one core or forty, on a laptop or a server, on ARM or x86, and at FP64 on the GPU.

Two design choices that we can state here make this possible.

Positions are stored as exact integers. A floating-point number has a spacing that depends on its magnitude: the further a particle is from the origin, the coarser the grid of values it can sit on. Integers have the same spacing everywhere, and integer addition is exact, so the result does not depend on the order of the operations.

Where a position can sit

floating point against integer ticks

Floating pointthe gap doubles at every power of two124816Integer ticksthe same gap everywhere, and sums are exact124816distance from the origin (arbitrary units)

Illustration with a toy number format. With floating point, resolution falls as the coordinate grows. With integer ticks it is uniform across the domain.

Precision is chosen for the run. A run is FP32 or FP64 because you asked for it, not because of the device it happened to land on. Each precision gives its own answer, and that answer is the same everywhere.

The evidence:

  • The angle-of-repose case at FP64 produced 124 output files, and all 124 were identical across core counts.
  • A superquadric pour was run 8 times: on an Apple M3 laptop and on an NVIDIA GPU workstation, at 1 and 4 cores, in both precisions. Each precision gave one hash across both machines.
  • Multibody results are identical at any core count and on CUDA at FP64.

One limit to state plainly: the Apple Metal GPU route is FP32 only, so FP64 runs on a GPU mean NVIDIA CUDA.

What reproducibility is not

It is not accuracy. A solver can return the same wrong answer every time. Whether the answer is right is a separate question, settled by verification against theory and, eventually, by validation against experiment.

It is not insensitivity either. Change the time step, the seed or a material value and the result changes, as it should. Reproducibility only promises that nothing else changes it.

How to test a solver

The test is short, and you can apply it to any code:

  1. Run a deck with a few thousand particles on one core. Keep the output.
  2. Run the same deck on all cores. If the solver has a GPU route at the same precision, run that too.
  3. Hash every output file from each run, for example with shasum -a 256, and compare the lists.

If the hashes match, small differences between your runs mean something. If they do not, measure how large the scatter is before you draw a conclusion from a small difference.