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

Document how to run RNGs in parallel #45

Closed
vks opened this issue Aug 24, 2021 · 1 comment · Fixed by #52
Closed

Document how to run RNGs in parallel #45

vks opened this issue Aug 24, 2021 · 1 comment · Fixed by #52

Comments

@vks
Copy link
Contributor

vks commented Aug 24, 2021

There was some discussion in rust-random/rand#997:

Perhaps you mean that one can safely seed multiple independent streams. For this purpose we specifically chose RNGs supporting ~128-bit seeds or larger. There are some potential issues with PCG streams being too similar, so not all of those RNGs are suitable (but the ones with 64-bit output already use 128-bit internal state).

You also need to ensure the seeding mechanism does not create similarities in state — some people recommend using a different type of RNG for seeding each thread's generator; I'd recommend using a (near) crypto-grade generator such as ChaCha since any such similarities would violate the requirements on a crypto generator. Seeding one RNG from another is easy; see the book.

Use case is you want to split a Monte-Carlo simulation over N processors.
This can be done with skip-ahead, e.g. with ChaCha, but typically we recommend using a cryptographic master generator to seed each parallel generator. Our ChaCha implementation (and most I believe) uses a 64-bit counter, which likely isn't enough for parallel usage, however it uses a 256-bit seed. The parallel generator (ChaCha or other) still needs to support at least 128-bits of state and independent streams (so not recommended to use PCG), but a 64-bit period is acceptable.

I think it would be good to document how to use StdRng (with random seeds) and maybe rand_xoshiro (with skipping) in parallel.

@dhardy
Copy link
Member

dhardy commented Jul 5, 2022

This topic came up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants