The random rand(3) random) number generator rand(3) uses global state variables (hidden in the (g) libc implementation). Accessing them from multiple threads leads to cache problems and is not thread safe. You should use the rand_r(3) call with the seed parameter private to the stream:
long i; unsigned seed; #pragma omp parallel private(seed) {
Please note that in parallel execution, a different stream of random numbers will be generated than when executed in sequential order. I would also recommend erand48(3) as the best (pseudo) random source number.
Hristo iliev
source share