I have a code which looks like this (simplified):
write(*,'(2(a,f8.2))') ' Min = ', Tmin, ' Max = ', Tmax *dec$ if defined (_OPENMP_) *$omp parallel if ( enableOpenMP .AND. omp_bc ) num_threads ( threads ) default ( shared ) *$omp& firstprivate ( ..., Tmin, Tmax, ... ) *$omp do schedule(dynamic,3) *dec$ end if do ij = 1,(i2-i1+1)*(j2-j1+1) ! write(*,'(2(a,f8.2))') ' Min = ', Tmin, ' Max = ', Tmax call apply_BC ( ..., Tmin, Tmax, ... )
Tmin and Tmax (both real*8) contain nonzero values before the parallel region is entered. If the commented line inside the parallel region is uncommented, Tmin and Tmax are the same as before the parallel region. However, letting the line commented out and calling the write command from the subroutine apply_BC causes that both Tmin and Tmax are suddenly 0 (generally a different value). When the program comes to the first line of my example code again, Tmin and Tmax are correct.
So, it seems entering the parallel region is causing some problems. It might be a bug in my code (quite big - 2300 lines), but I have no idea what I should focus on when trying to find the cause of the problem.
Parallel debug version and a version with enableOpenMP = .false. (no parallelization) work correctly.