I am parallelizing calls to newSeed() and rand(),static member functions of class Random. newSeed() feeds a static member of class Random (let’s call it seed). To be more concrete, I parallelize calls to this function in another class, the Method class:
double* Method::randomPoint(double* bottom_, double* top_ )
{
try{
Random generator_ ;
double* pt_ = new double[m_ndim];
generator_.newSeed();
for(int i=0;i<m_ndim;i++)
{
pt_[i]= generator_.rand(bottom_[i],top_[i]);
}
return pt_;
}
catch(...)
{
return NULL;
}
}
To sum up, in each parallelized call, I create a new instance of class Random, I call newSeed() and rand() method in this object. Since newSeed() is called on a given instance, I hope that newSeed() initializes the seed member for this object – and thus for this thread only. Since seed is static and newSeed() is static as well, am I modifying seed for ALL currently running instances of Random class (and for all threads)?
Please tell me if question must be clarified.
Thanks and regards.
The static fields are shared amongst ALL the instance of the class of the process.
Also, the threads are running in the same process, meaning that are sharing the memory, using the same classes
So, if you modify the static field seed, all of the “Random” instances in all of your threads will have the modification.