https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108336
--- Comment #6 from Gareth Davies <gareth.davies.ga.code at gmail dot com> --- (In reply to anlauf from comment #4) > There is one flaw with the testcase: when OMP_NUM_THREADS > n1, > array elements threadval(n1+1:OMP_NUM_THREADS) are filled with > undefined values. Yes, my bad in trying to simplify the test case... We should have n1 >= nt. > > When I replace the line > > if(omp_get_thread_num() /= 0) call random_number(x1) > > by the following loop: > > do i = 1, nt > if (i > 1 .and. omp_get_thread_num() == i-1) call random_number(x1) > !$omp barrier > end do > > and furthermore do > > print*, minval(threadval(1:n1)), maxval(threadval(1:n1)) > > I get repeatable results. > > Am I missing something? Thanks, I also get repeatable results with those changes. A "weaker" approach to getting deterministic results without forcing a 1:1 mapping of random numbers to threads is to replace: > do i = 1, nt > if (i > 1 .and. omp_get_thread_num() == i-1) call random_number(x1) > !$omp barrier > end do with: !$omp critical if(omp_get_thread_num() /= 0 ) call random_number(x1) !$omp end critical !$omp barrier This is what I was looking for.