This content has been marked as final. Show 1 reply
The only difference I see between the first and second versions of the code is that in the first version we have PRIVATE(i,j), while in the second version this clause is left out. (In the second version there's a missing 'end do', but I assume this is just a typo.)
In Fortran, PRIVATE(i,j) is not needed, because i and j will be privatized anyway.
j will be privatized because of the following bullet in the specification (see OpenMP 4.0 RC2 at http://www.openmp.org/mp-documents/OpenMP_4.0_RC2.pdf, p. 123):
* The loop iteration variable(s) in the associated do-loop(s) of a do or parallel do construct is (are) private.
i will be privatized because of the following bullet (OpenMP 4.0 RC2, p. 123):
* A loop iteration variable for a sequential loop in a parallel or task construct is private in the innermost such construct that encloses the loop.
Note that the above bullet about loop iteration variable for a sequential loop applies to Fortran only. It does not apply to C/C++.
By the way, there appears to be a data race condition in the code, since the same element of the phi array may be accessed concurrently by two different threads and one of the accesses is a write.