Parallel FORTRAN output varies with addition of arbitrary WRITE statement

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
Hemmer
Messages
15
Reaction score
0
Hi there,

I've been puzzling over the following code (which works in serial). It produces radically different answers if the (blank) WRITE(*,*) is included or not. Any help greatly appreciated!

Code:
eps = 0.0

  !$omp parallel do default(none) private(i, j, current_angle, current_energy) &
  !$omp shared(a, N, J_0, eps)
    do j = 1, N
       do i = 1, N

          ! find energy
          current_angle = a(i,j)
          call get_neighbouring_contrib(a, current_angle, i, j, current_energy, J_0, N)

          [B]!if i have this (or any) WRITE statement, program gets answer correct
          !otherwise get garbage results which vary each time[/B]
          write(*,*)

          ! and sum
          !$omp atomic
          eps = eps + current_energy
       end do
    end do
    !$omp end parallel do
 
Physics news on Phys.org