Fortran Parallel FORTRAN output varies with addition of arbitrary WRITE statement

AI Thread Summary
The discussion centers on a code snippet that behaves inconsistently when a WRITE statement is included within an OpenMP parallel loop. The code calculates energy contributions in a two-dimensional array, but omitting the WRITE statement leads to incorrect and varying results. The inclusion of the WRITE statement appears to stabilize the output, likely due to its impact on timing and synchronization in the parallel execution. This suggests that the timing alterations caused by the WRITE statement may inadvertently affect the parallel operations, potentially leading to race conditions or other synchronization issues. The problem highlights the importance of understanding how output operations can influence the behavior of parallel code execution.
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
 
Technology news on Phys.org
Just a guess. The WRITE statement drastically alters the timing, which affects parallel operations. It might even trigger a timeout.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
8
Views
4K
Replies
2
Views
5K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
6
Views
3K
Replies
11
Views
3K
Replies
4
Views
2K
Replies
6
Views
2K
Back
Top