Parallel FORTRAN output varies with addition of arbitrary WRITE statement

That's my guessIn summary, the speaker is seeking help with a code that produces different results depending on whether a WRITE statement is included or not. They speculate that the statement may affect the timing and parallel operations, potentially causing a timeout.
  • #1
Hemmer
16
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
  • #2
Just a guess. The WRITE statement drastically alters the timing, which affects parallel operations. It might even trigger a timeout.
 

Related to Parallel FORTRAN output varies with addition of arbitrary WRITE statement

1. Why does adding a WRITE statement affect the output of my parallel FORTRAN program?

Adding a WRITE statement to a parallel FORTRAN program can affect the output because it interrupts the parallel execution of the program. This can lead to a change in the order in which the program is executed, resulting in different output than without the WRITE statement.

2. Can I still use WRITE statements in a parallel FORTRAN program?

Yes, you can still use WRITE statements in a parallel FORTRAN program. However, it is important to carefully consider the placement of the WRITE statements and how they may affect the parallel execution of the program.

3. Is there a way to avoid the variation in output caused by a WRITE statement in a parallel FORTRAN program?

Yes, there are ways to avoid the variation in output caused by a WRITE statement. One option is to use a synchronization mechanism, such as a barrier, to ensure that all processes reach the WRITE statement at the same time. Another option is to use a collective I/O operation, such as parallel output using MPI-IO, which can ensure that the output is consistent across all processes.

4. Are there any best practices for using WRITE statements in a parallel FORTRAN program?

Yes, there are several best practices for using WRITE statements in a parallel FORTRAN program. These include minimizing the use of WRITE statements, using synchronization mechanisms or collective I/O operations when necessary, and carefully considering the placement of WRITE statements in the code to minimize their impact on parallel execution.

5. Is the variation in output caused by a WRITE statement in a parallel FORTRAN program a bug?

No, the variation in output caused by a WRITE statement in a parallel FORTRAN program is not a bug. It is a result of the parallel execution of the program and can be managed by using proper synchronization mechanisms or collective I/O operations. It is important to understand the behavior of WRITE statements in a parallel program and use them appropriately to avoid unexpected variations in output.

Similar threads

  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
2
Views
5K
  • Programming and Computer Science
Replies
2
Views
4K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
31
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
11
Views
14K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
11
Views
2K
Back
Top