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

      program sections_f
      implicit none
      integer            :: i,j,k,id,omp_get_thread_num
      integer, parameter :: idp = 8, nsize_a = 20000, nsize_b = 40000, nsize_c = 2000
      real(kind=idp)     :: temp,time_start,time_end,omp_get_wtime
      real(kind=idp), dimension(0:nsize_a-1,0:nsize_a-1) :: array_a
      real(kind=idp), dimension(0:nsize_b-1,0:nsize_b-1) :: array_b
      real(kind=idp), dimension(0:nsize_c-1) :: array_c



      time_start = omp_get_wtime()

!$omp parallel sections

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

      write(*,'(a,f9.6)')  'The last array_a element = ', array_a(nsize_a-1,nsize_a-1)

!!$omp section
!      id = omp_get_thread_num()
!      write(*,*) 'section 2. My id is ', id
!      do i = 0, nsize_b-1
!      do j = 0, nsize_b-1
!         temp = SQRT(dble(i+j))
!         array_b(j,i) = COS(temp) -SIN(temp)
!      end do
!      end do
!
!      write(*,'(a,f9.6)')  'The last array_b element = ', array_b(nsize_b-1,nsize_b-1)
!
!!$omp section
!      id = omp_get_thread_num()
!      write(*,*) 'section 3. My id is ', id
!      do i = 0, nsize_c-1
!        temp = SIN(dble(i)) - COS(dble(i))
!         array_c(i) = EXP(temp)
!      end do
!
!      write(*,'(a,f9.6)') 'The last array_c element = ',array_c(nsize_c-1)

!$omp end parallel sections


      time_end = omp_get_wtime()

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


      end program sections_f

