1 Reply Latest reply: May 30, 2013 4:04 PM by nkcopty RSS

    Openmp with Fortran 90

    1011586
      Hi all, I'm a new to this website,

      i have a main program with many modules in FORTRAN 90, i have a question about the difference if i apply this example, i have not clear if declare private variable or not, here a example

      !$OMP PARALLEL DEFAULT(SHARED) PRIVATE(i,j)
      !$OMP DO
           do j=2,nj-1
           do i=2,ni-1
           phi(i,j)=(1.0d0/4.0d0)*(
      + phi(i+1,j)+phi(i-1,j)+
      + phi(i,j+1)+phi(i,j-1)-rhs(i,j)*delta*delta)
           end do
           end do
      !$OMP END DO
      !$OMP END PARALLEL


      Or

      !$OMP PARALLEL DEFAULT(SHARED)
      !$omp do

           do j=2,nj-1
           do i=2,ni-1
           phi(i,j)=(1.0d0/4.0d0)*(
      + phi(i+1,j)+phi(i-1,j)+
      + phi(i,j+1)+phi(i,j-1)-rhs(i,j)*delta*delta)
           end do

      !$OMP END DO
      !$OMP END PARALLEL

      and what is the correct or different command that i can do use, are there some difference in calculation?
        • 1. Re: Openmp with Fortran 90
          nkcopty
          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.