This tutorial about parallel programming using OpenMP in Fortran, found on the OpenMP website, contains the following example (see pages 11-12):
real(8) :: A(1000), B(1000)
do i = 1, 1000
B(i) = 10 * i
A(i) = A(i) + B(i)
enddo
The text surrounding this example reads:
Since each thread is executing part of the iterations of the do-loop and the updates of the modifications made to the variables are not ensured until the end of the work-sharing construct, the following example will not work correctly using the !$OMP DO/!$OMP END DO directive-pair for its parallelization because the correct value of the matrix B is not ensured until the end of the work-sharing construct !$OMP END DO.
My question is two-fold:
Why would this example not work correctly using the OpenMP DO-construct? The thread that reads B(i) is also the only thread that writes it.
What does "work correctly" mean for this example? Are arrays always zero-initialized automatically in Fortran?
A similar question suggests that, in fact, the example does work correctly using OpenMP, and the tutorial is incorrect. Yet, the tutorial is linked from the official OpenMP website.