EGSnrc
EGSnrc copied to clipboard
Implement RANLUX random number generator in egs++
This is a resubmission of https://github.com/nrc-cnrc/EGSnrc/pull/292 since my develop branch was removed. The original message was: "I noticed a lack of the RANLUX random number generator in egs++, so I implemented a class EGS_Ranlux for it based on GSL's integer implementation (gsl_rng_ranlux), which is pretty much the same as the original Fortran implementation in EGSnrc. I haven't done extensive testing, but it seems to be working fine."
Thank you @serios! 🙏🏻
Will look into the PR again. May I push to your develop
branch (on EGSnrc-1) if I need to make changes?
Sure! I opened that repo specifically for this. No problem, I'm happy to contribute to this great piece of software!
@serios thanks for the invitation on the repo, but I will do it from here, i.e., push to the pull request branch you just re-created. By default, admin of the repo against which you create a PR can push to the PR branch on your repo. I was just asking if that was ok, as it might come across as a little invasive if you are not expecting it. 😄
OK, no problem, I wasn't aware of that :)
I wanted to note that C++11 added RANLUX to the standard library: https://en.cppreference.com/w/cpp/header/random (ranlux24
, ranlux48
). It might be worth comparing the performance of both implementations, perhaps the standard has some tricks up its sleeve.
Thanks for the note @mxxo. This simplifies the issue of integrating GNU code inside the EGSnrc project, in terms of licensing! I am adding this to the list of projects #790.
We ought to provide hooks in egs++ to call on the <random>
generators provided as part of STL (since C++11). I don't look favorably upon maintaining our own generator code inside EGSnrc, not anymore.
In cursory testing, I found that the ranlux24 generator is ~20 times slower than the default EGSnrc ranmar. the Mersenne Twister about twice as slow as ranmar. The latter is thus a good alternative (and perhaps a good default?), while ranlux would only be practical for investigating the quality of the faster generators in a scenario where this is thought to be an issue.
For my own reference, here is a boiler plate for the C++11 STL random:
#include <random>
#include <iostream>
int main() {
auto seed = 12345;
std::mt19937 mt {seed};
std::uniform_real_distribution<double> uniform(0.0, 1.0);
for (int i=0; i<10; i++) {
std::cout << uniform(mt) << "\n";
}
}
I also remain curious about xoshiro and pcg64 generators to boost simulation speed.