Closed bangerth closed 4 years ago
Given this code comment, do you think we should check and ensure the consistency of the standard random generator implementations across all compilers?
I personally don't think it's important to have consistency in this case and would much rather get rid of the BOOST dependency. User is requesting random numbers, user gets random numbers, however they are generated.
So I'd just as well go with what you have in #9204. What do others think?
We reverted #8312 in https://github.com/dealii/dealii/pull/8332 that addressed the same issue since we just had too many problems with failing tests.
Thank you @masterleinad for directing us to the history of these types of changes.
It seems that the C++11 random number generators are fully portable (except std::default_random_engine
and std::random_device
), but the distributions might be platform dependent (link). So one idea is that we define our own random distribution, which replicates the implementation of its boost
counterpart. This way, hopefully, we can remove dependence on boost::random
and simultaneously keep old tests passing without modification.
I am happy with all changes that replace boost
functions by corresponding ones in the C++ standard library and pass the test suite for all configurations. If it is just about updating the output files, that is also OK, but with compiler/platform-dependent output it gets pretty nasty.
In the end, I agree with @bangerth that it should really matter which random numbers are returned by these functions and therefore it might not be a good idea to print random numbers in test output at all. On the other hand, it is likely infeasible to modify all corresponding tests accordingly.
I don't really see an advantage defining our own random distributions instead of the ones provided by boost
, though. We are not going to get rid of the boost
dependency in the near future and boost::random
has worked pretty fine so far.
Okay I will change the tests to not print the random numbers, instead the tests will check general properties of the generated numbers.
I think as a general principle, if there is C++11 functionality that we can use instead of using BOOST, then that's what we should do. I do agree that that sometimes is not possible for practical reasons.
I do wonder whether the C++11 standard specifies how exactly things like mt19937 are supposed to work. It specifies the general algorithm, and I suspect also the initializer? If so, then we shouldn't incur any dependency on the actual compiler used.
By the way, scroll all the way to the bottom of https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine and you will find two very interesting notes:
The 10000th consecutive invocation of a default-constructed std::mt19937 is required
to produce the value 4123659995.
The 10000th consecutive invocation of a default-constructed
std::mt19937_64 is required to produce the value 9981545732273789042
So I think we can assume that the std::
random number generators generate numbers in a platform-independent way.
Yes, I read that the random-number generators are platform-independent. However, the random number distributions such as std::uniform_real_distribution
can be implementation dependent.
Oh :-( I missed that part. Let's hope that we don't get into too much trouble. I think it was still the right thing to do, and probably a good idea to not actually output random numbers.
9125 alerts me to the fact that the
source/base/function_parser.cc
file still uses the BOOST random number facilities. #9125 moves this functionality tosource/base/mu_parser_internal.cc
, so we should wait till that PR has been merged, but after that, we should replace the BOOST random facilities by the corresponding C++11 facilities.@konsim83 -- FYI.