Skip to content

Per thread RNG state in multi-threaded code #10441

Closed
@ViralBShah

Description

@ViralBShah

On the threads branch, I want to be able to have a differently seeded RNG in each thread. I am using the threads with the @threads macro to parallelize for loops. There doesn't seem to be a concept of a long running thread with global state.

I am guessing I should have a global array of RNG states, and every thread then just does something like rand(MT(threadid())). Is there a way I can do something like this for now? The @threads only applies to the for loop and I would like to do some thread local setup before that?

This is not going to work well with a Cilk-style threading model in general - but I just want something that can work for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    multithreadingBase.Threads and related functionalityrandomnessRandom number generation and the Random stdlib

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions