My supposedly deterministic program produces one of a few slightly different outputs on different runs. The input, compiler and computer are unchanging. I'm not sure which output is right because it always looks reasonable.
Besides a stray call to rand(), how could this be possible?
In classical physics nondeterminism is due to uncontrolled causes that are recognized to exist and that, if better known, would make the predictions better.
One example of a non-deterministic algorithm is the execution of concurrent algorithms with race conditions, which can exhibit different outputs on different runs.
Nondeterminism means that the path of execution isn't fully determined by the specification of the computation, so the same input can produce different outcomes, while deterministic execution is guaranteed to be the same, given the same input. Related terms to "nondeterministic" are "probabilistic" and "stochastic".
In a deterministic algorithm, for a given particular input, the computer will always produce the same output going through the same states but in the case of the non-deterministic algorithm, for the same input, the compiler may produce different output in different runs.
If your program use float / double, there may be difference in the result if there are context switch on some architecture.
On x86, the FPU use extended precision for intermediary result, but when saved in memory (which happens when there is a context switch either process or thread), such precision is lost. That could cause some small divergence of the result (we've detected such problem in our program). One way to avoid this issue is to ask the compiler not to use FPU but SSE for floating point operations.
http://www.network-theory.co.uk/docs/gccintro/gccintro_70.html
If your output depends on an address allocated on the heap:
int main(int argc, char* argv[])
{
printf("%p", malloc(42));
return 0;
}
For each run, the malloc() may return a different virtual address - not to mention NULL in case the allocation failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With