srand

The engine.
Post Reply
mesterharm
Posts: 6
Joined: Wed May 13, 2015 9:59 pm

srand

Post by mesterharm »

I'm using jSmile and want to do inference on influence diagrams with sampling. I created some jni code to call srand() and that allows me to set a seed. I assume because srand() works that the C++ code for sampling is using rand() to generate random numbers. Does this mean I can't do multithreaded sampling since rand() is not thread safe?

Thanks,
Chris
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: srand

Post by shooltz[BayesFusion] »

mesterharm wrote:I'm using jSmile and want to do inference on influence diagrams with sampling. I created some jni code to call srand() and that allows me to set a seed. I assume because srand() works that the C++ code for sampling is using rand() to generate random numbers. Does this mean I can't do multithreaded sampling since rand() is not thread safe?
I would avoid multithreading with sampling. Depending on the sampling algorithm selected, it may use built-in rand() function (and your call to srand() will have an effect), or a custom random generator which is not thread-safe (and is not influenced by seed specified in the stand() call).

Are you using sampling due to problems with exact inference being unable to complete the calculations (error -42?)
mesterharm
Posts: 6
Joined: Wed May 13, 2015 9:59 pm

Re: srand

Post by mesterharm »

I would avoid multithreading with sampling. Depending on the sampling algorithm selected, it may use built-in rand() function (and your call to srand() will have an effect), or a custom random generator which is not thread-safe (and is not influenced by seed specified in the stand() call).
Thanks, this is good to know.
Are you using sampling due to problems with exact inference being unable to complete the calculations (error -42?)
No, I'm using sampling to implement a distributed solution for research purposes. The influence diagrams we are solving are small enough that junction trees are very fast, but in principal we want to be able to handle larger networks.

Thanks,
Chris
Post Reply