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

Make the global RNG a Julia global variable instead of a libdSFMT variable #8399

Closed
wants to merge 4 commits into from

Conversation

rfourquet
Copy link
Member

This is a follow-up of https://groups.google.com/forum/#!topic/julia-dev/0MUE8MoyO0k, where it is found that with simplistic benchmarks a global RNG controlled by Julia is no slower (and maybe slightly faster) than the one controlled by the dSFMT library (which is currently used by rand() with no rng argument).
So this PR is to test more widely this assertion and find other possible problems.

Julia managing itself its global RNG may have advantages in a multi-threaded world (one "global" RNG per thread?). Are there any drawbacks? Note that an interface to the global RNG from libdSFMT can be kept (it just wouldn't be the default) if one really wants access to it.

This PR is built on #8380 (unmerged), and in fact adds only one small commit: I did the bare minimum so that everything builds and the tests pass. I certainly have missed things, please report problems.

MersenneTwister's constructor making an instance with an Uint32 seed
were removed in commit 4fb4622. But a subsequent call to
srand(r::MersenneTwister, seed) would only accept an Uint32 as a seed,
and would always make r.seed an Uint32; this was not consistent.
The srand methods working on a MersenneTwister instance did not catch
up with those working on the global RNG. They are now made similar
thanks to the make_seed function, which implements the different
logics.
Also, the manual is more precise on the types of valid seeds.
And similarly for rand!, randbool.
Fixes JuliaLang#8360.
@ViralBShah
Copy link
Member

So, does #8380 need to be merged before this one?

Let's keep the global version for now. It is likely that someone will find a performance issue once we merge and we may have to revert later. If no regressions are found, we can excise it in a few weeks.

@ViralBShah
Copy link
Member

BTW, you can add commits to a PR after creating it too, if you need to add commits.

@rfourquet
Copy link
Member Author

Yes this depends on #8360. Really the goal here is to start testing a Julia global RNG but by no means it is ready to be merged.
ps: I didn't know if this was fine to add commits to non-WIP PRs so thanks for clarification. But in this case I think #8360 is ready and independant, and adding globalised RNG to it would have make it "not ready".

@jiahao jiahao force-pushed the master branch 3 times, most recently from 6c7c7e3 to 1a4c02f Compare October 11, 2014 22:06
@ViralBShah
Copy link
Member

It would be good to have just the global RNG part of this PR (where the global state is in Julia rather than in libdSFMT) merged, in light of other dSFMT work.

@rfourquet
Copy link
Member Author

This is now implemented by #8832.

@rfourquet rfourquet closed this Oct 30, 2014
@rfourquet rfourquet deleted the random-global branch October 30, 2014 09:46
@ViralBShah ViralBShah added the randomness Random number generation and the Random stdlib label Nov 22, 2014
@ViralBShah ViralBShah changed the title WIP: Make the global RNG a Julia global variable instead of a libdSFMT variable Make the global RNG a Julia global variable instead of a libdSFMT variable Nov 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants