I\'m getting a \"bus error\" from an OpenMP parallel section of code. I recreated a simple version of my problem below. The code essentially makes many calls to the function
I think the most convenient solution would involve a thread_local
RNG and a seeding that involves the thread ID as a unique number for each thread, for example, you can do a XOR between the system time and the thread-id to seed the RNG. Something along the lines of (using C++11):
#include
#include
#include
#include
boost::random::mt19937& get_rng_engine() {
thread_local boost::random::mt19937 eng(
reinterpret_cast(std::time(NULL)) ^ std::this_thread::get_id());
return eng;
};
(NOTE: you can also use
if you are going to use C++11)
If you can't use C++11 then you can use boost::thread
instead to have a similar behavior, see the Boost page on thread-local storage too.