Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal_distribution implimentation dependence #353

Open
JPRichings opened this issue Apr 21, 2021 · 1 comment
Open

Normal_distribution implimentation dependence #353

JPRichings opened this issue Apr 21, 2021 · 1 comment

Comments

@JPRichings
Copy link
Contributor

Grid like many codes uses the standard libraries implementation of the normal_distribution. This takes a uniform random number generator as a input and calls it twice to generate normally distributed random numbers using the polar method. This generates two normally distributed random numbers, one is returned in the current call to the normal distribution and the other is cached for the next call.

This causes an issue as the order in which the two normally distributed random number are returned and cached is not defined by the C++ standard. The implementations by llvm and gcc take different choice in the ordering of the returned and cached random numbers.

In essence this is not a bug as both compilers generate valid normally distributed random numbers but it makes the results dependent on the implementation of the standard as the sequence will have a different ordering. This can be problematic when comparing results between systems and hardware (CPU and GPU) as the implementation of the standard can change.

@paboyle
Copy link
Owner

paboyle commented Apr 21, 2021

will declare this a feature, not a bug.

the system is self reproducible (by language standard) if you use the same libstdc++.

the benefits of using the C++11 standardised random interfaces greatly exceeds the inconvenience of Clang and GCC using different (legal) orderings with respect to each other.

We just have to keep in mind that GCC and Clang will behaved differently. They actual Gaussian implementation algorithm is not standardised, just that it must be gaussian and self reproduce.

(Bitwise) self reproduction on the SAME machine & compiler is Grids goal - for use as a hardware test. Rounding and other things will differ in any case between different numbers of MPI ranks and between compilers (or even compiler flags) and other machines.

This is a (far) faster loss of correlation than I like, so I don't like to give this up, but the other option of binning the libstdc++ because we don't like the legal behaviour seems drastic. Another option would be to take one of the "gaussian" distribution headers and make it compile on both, but that seems to be an unnecessary maintenance burden and also assumes the correctness risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants