Skip to content
Snippets Groups Projects

Update RandomGenerator to not use uniform_real_dist

Fix for issue #85

Clang's codegen leaves uninlined calls to logl when using uniform_real_distribution, which leads to worse performance, sometimes up to 2x.

Hence, I have changed _GeneralizedRandomGenerator to generate its own floating-point numbers from a PRNG which can provide 64-bit integers.

The default PRNGs were changed to mt19937_64 and pcg64, it's possible to use a 32-bit version and use bitmasks to create a 64-bit number yourself, which is probably a bit faster, but I haven't benchmarked it.

Clang 17.0.6 unpatched Clang 17.0.6 patched Performance improvement
11.776 5.209 2.26
11.725 5.211 2.25
11.721 5.216 2.24
11.775 5.212 2.25
11.773 5.214 2.25
11.872 5.211 2.27
11.723 5.258 2.22
11.771 5.216 2.25
11.767 5.212 2.25
11.72 5.211 2.24

Merge request reports

Members who can merge are allowed to add commits.
Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
32
32 33 std::seed_seq _seed;
33 34 RNG _rng;
34 35
35 36 public:
36 37 explicit _GeneralizedRandomGenerator(const std::string &rng_seed) NOEXCEPT :
37 _rng_distribution(0, 1),
38 38 _seed(rng_seed.begin(), rng_seed.end()),
39 39 _rng(_seed)
40 40 { }
41 41
42 // Generates a double in the unit interval [0, 1)
43 // https://prng.di.unimi.it/#remarks
42 44 inline Type get_real() NOEXCEPT {
43 return _rng_distribution(_rng);
45 return static_cast<Type>(_rng() >> 11) * 0x1.0p-53;
  • Ivan Zhechev added 1 commit

    added 1 commit

    Compare with previous version

  • I have changed the default PRNGs from their 64-bit versions to the 32-bit ones so that the scene is the same as the one in the README.rst.

  • Ivan Zhechev added 1 commit

    added 1 commit

    Compare with previous version

  • Ivan Zhechev added 1 commit

    added 1 commit

    • 3d50a899 - Add a template parameter to RandomGenerator for a distribution function

    Compare with previous version

  • Please register or sign in to reply
    Loading