Using OMP ORDERED to order output from OpenMP threads

 

This exercise presents a simple program to demonstrate the use of OMP ORDERED. Compile and run the code provided below. What happens if you remove the ORDERED/END ORDERED lines?

 

!$omp parallel do ordered schedule(dynamic)
      do i=1,4
         call work(i)
      enddo
      end


      subroutine work(k)
!$omp ordered
      write(*,*)k
!$omp end ordered
      return
      end