!-------------------------------------------------------!
! The current code has three purposes:                  !
! (1) how loop iterations are mapped to threads.        !  
! (2) demonstrates the work-sharing in parallel region. !
! (3) work-sharing does not spawn multiple threads.     !
!-------------------------------------------------------!
! Xiaoxu Guan at LSU HPC.                               !
! March 07, 2016                                        !
!-------------------------------------------------------!

      program mapping_threads
      implicit none
      integer ::  i,id,omp_get_thread_num,nothread,omp_get_num_threads
      integer, parameter :: nsize = 40

!$omp parallel private (id,i) shared(nothread)
      id = omp_get_thread_num()
      nothread = omp_get_num_threads()
!!      write(*,'(1x,a,i3,a,i3)') &
!!     &   "Hello World! from ID ", id, " out of ", nothread
!$omp do
      do i = 1, nsize
         write(*,'(1x,2(a,i4))') "id = ",id, " i = ",i
      end do
!$omp end do
!$omp end parallel

      end program mapping_threads
