!----------------------------------------------------!
! The current code has the purpose:                  !
! (1) how to use single blocks.                      !
!----------------------------------------------------!
! Xiaoxu Guan at LSU HPC.                            !
! March 17, 2016                                     !
!----------------------------------------------------!

      program single_f
      implicit none
      integer            :: i,j,k,id,omp_get_thread_num
      integer, parameter :: idp = 8, nsize_a = 800, nsize_b = 200
      real(kind=idp)     :: temp,time_start,time_end,omp_get_wtime
      real(kind=idp), dimension(1:nsize_a,1:nsize_a,1:nsize_a) :: array_a
      real(kind=idp), dimension(1:nsize_b,1:nsize_b)           :: array_b


      time_start = omp_get_wtime()

!$omp parallel

!$omp single
      id = omp_get_thread_num()
      write(*,*) 'single block 1. My id is ', id
      do i = 1, nsize_a
      do j = 1, nsize_a
      do k = 1, nsize_a
         temp = SIN(dble(i+j+k))
         array_a(k,j,i) = EXP(temp)
      end do
      end do
      end do
!$omp end single

!$omp single
      id = omp_get_thread_num()
      write(*,*) 'single block 2. My id is ', id
      do i = 1, nsize_b
      do j = 1, nsize_b
         temp = SIN(dble(i+j))
         array_b(j,i) = EXP(temp)
      end do
      end do
!$omp end single


!$omp end parallel


      time_end = omp_get_wtime()

      write(*,*) 'elapsed time (seconds) = ', time_end - time_start
      write(*,*)


      end program single_f

