drake icon indicating copy to clipboard operation
drake copied to clipboard

std::normal_distribution produces different numbers on mac clang vs ubuntu

Open RussTedrake opened this issue 8 years ago • 5 comments
trafficstars

Based on quick testing in #4358, it appears that the uniform distribution produces consistent results across the platforms, but that I'm seeing different results from std::normal_distribution on mac and linux (the linux builds are all consistent with each other though).

That would be consistent with the observation reported here: http://stackoverflow.com/questions/34903356/c11-random-number-distributions-are-not-consistent-across-platforms-what-al

I wanted to open this issue for two reasons to document this finding, but also to discuss. How much do we value getting consistent results here? We could implement our own distribution (as in the Box-Muller in the post above), but presumably at some cost in terms of performance (statistical and cpu time). What do folks think?

I suspect we want something like this for drake: http://mooseframework.org/docs/doxygen/moose/classMooseRandom.html

RussTedrake avatar Dec 04 '16 21:12 RussTedrake

I guess the way I think about it is the best way to minimize effort to reach the end goal. Having platform-varying behavior is probably a meaningful cost, but so is writing and/or optimizing our own normal distribution.

Would it make sense to write the code in terms of a Drake normal distribution, but for now have it call the system C++11 normal distribution? If that mostly works, it seems like an easy way to make progress but leave a seam open to insert a custom implementation.

But also, the code for normal_distribution::operator() is actually pretty terse, so maybe its cheap to in-tree our own anyway, and we should do that from the start.

jwnimmer-tri avatar Dec 05 '16 20:12 jwnimmer-tri

Per the manipulation subgroup meeting this morning, I just wanted to clarify that the differences in std::normal_distribution are likely due to differences in the implementations of the standard C++ libraries on OSX vs. Ubuntu and not due to clang vs. gcc.

(The above statement is a conjecture that needs to be verified.) (The title of this issue includes the word "clang", which could be inferred to imply that there is a difference between gcc vs. clang.)

liangfok avatar Dec 07 '16 18:12 liangfok

I think we understand that the results are inconsistent across platforms, and are going to live with it.

RussTedrake avatar Sep 23 '18 15:09 RussTedrake

The pain of differing platforms has been increasing. I'll probably try to implement some of the fixes discussed above.

jwnimmer-tri avatar Jul 27 '23 15:07 jwnimmer-tri

Most acutely, probably the std::uniform_real_distribution is more important to make cross-platform bit exact (vs the normal distribution).

Anyway if we're just going to vendor the Boost real number distributions then we might as well do all of them at once.

jwnimmer-tri avatar Feb 21 '24 19:02 jwnimmer-tri