I am trying to use igraph as a threaded application (I have compiled it in thread-safe mode), together with random number generators. From the docs I gathered that for reproducibility I need a RNG for each thread but I must still be missing something there. I have the following Minimal-Not-Working-Example:
I am quite lost - the solution must be simple but I’m not getting it. Igraph works perfectly fine otherwise on my machine. I’d be grateful for any help! (I am seeding my RNGs, just cut it out for this example).
This is not necessary. You only ever need to include igraph.h
This is a pointer, but what is it pointing to? It is not initialized to any meaningful value, so you end up trying to access arbitrary memory locations, leading to a crash.
You need a variable to store the RNG data. This should be of type igraph_rng_t. Then you will be passing pointers to this variable to RNG functions. So:
Each thread will need to have its own RNG, i.e. you will need an igraph_rng_t which lives in that thread.
You can achieve this for example by declaring a thread-local igraph_rng_t variable, initializing it once from each thread, then using it from those thread. The variable must be initialized on thread startup.
What you show in the example is two RNG state variables, both in the main thread. This is not what you would normally do.
Thank you!! The pointer was a leftover artefact from when i used igraph_default_rng, oops. I knew it had to be simple
Do you have any idea why it works when I only try to initialize one rng? That had me stumped but maybe I just got lucky there.
I think I’m doing the threading correctly, I just removed it all so it didnt distract from the problem I was having. Thank you either way!