I have written code in which I use parallel computing. Because adding random numbers to a parallel loop is tricky, I have tried to generate independent random numbers by generating the random numbers just before the parallel loop. However, I am still not sure if this is completely correct or could cause other problems. I would appreciate it if you could help me with this.
The part of the code which is relevant to the above discussion is:
void Nran::UpdateF(bool first)
{
const int numbe=100;
double figran[numbe];
for(unsigned fr=0; fr<Domain; ++fr)
{
figran[fr]=random_real()-0.5;
}
#pragma omp parallel for num_threads(nthreads) if(nthreads)
for(unsigned g=0; g<DomainSize; ++g)
UpdateNode(g, first,figran);
}
IMPORTANT NOTE: in the function UpdateNode
I do some calculations with each random number in the array (figran[g]).