C **********************************************************************
C                     
C                     Example 2 : Omp_Hello_World.f
C
C   Objective : OpenMP program to print "Hello World"
C               This example demonstrates the use of
C               OpenMP PARALLEL PRIVATE directive and 
C               run-time library routines
C               OMP_GET_THREAD_NUM
C               OMP_GET_NUM_THREADS
C
C   Input     : User has to set OMP_NUM_THREADS environment variable for
C               n number of threads
C
C   Output    : Each thread prints a message "Hello World" and its 
C               identifier
C
C   Necessary Condition : Number of threads should be less than or 
C                         equal to number of processors of an SMP node
C
C **********************************************************************

       program HelloWorld

       integer NoofThreads, ThreadID, OMP_GET_NUM_THREADS
       integer OMP_GET_THREAD_NUM

C     Fork a team of threads giving them their own copies of variables
C$OMP PARALLEL PRIVATE(NoofThreads, ThreadID)

C     Obtain and print thread identifier
      ThreadID = OMP_GET_THREAD_NUM()
      print *, 'Hello World from thread = ', ThreadID

C     Only master thread does this
      if (ThreadID .EQ. 0) then
        NoofThreads = OMP_GET_NUM_THREADS()
        print *, 'Number of threads = ', NoofThreads
      end if

C     All threads join master thread 
C$OMP END PARALLEL

       stop
       end

