Barrier synchronization in OpenMP (OMP BARRIER)

This exercise presents a simple program to demonstrate the use of OMP BARRIER. Compile and run the code provided below. Is the output correct? How can you use OMP BARRIER to ensure correct output?

 

      INTEGER omp_get_thread_num
      INTEGER A(20),B(20),C(20),I,J
      INTEGER D(20), E(20)
      DO I=1,20
         A(I)=0
         B(I)=I
         C(I)=2*I
         D(I)=21-I
      END DO
!$OMP PARALLEL PRIVATE(I,J)
      J = omp_get_thread_num()
!$OMP DO
      DO I=1,20
         A(I) = B(I)+C(I)+100*J
      END DO
!$OMP END DO NOWAIT
!$OMP DO
      DO I=1,20
         E(I) = A(D(I))
      END DO
!$OMP END DO
!$OMP MASTER
      DO I=1,20
        WRITE(*,*)i, e(i), a(d(i))
      END DO
!$OMP END MASTER
!$OMP END PARALLEL
      END