Forcing regions of a code to be executed by only the master thread using OMP MASTER

 

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

 

      PROGRAM SINGLE_USE
      INTEGER omp_get_thread_num
!$OMP PARALLEL
!$OMP MASTER
      PRINT *, omp_get_thread_num(), "   YOU SHOULD ONLY SEE THIS ONCE"
!$OMP END MASTER
!$OMP END PARALLEL
      END