!-------------------------------------------------------!
! The current code has a purpose:                       !
! (1) how to use atomic (critical) directive.           !
!-------------------------------------------------------!
! Xiaoxu Guan at LSU HPC.                               !
! March 07, 2016                                        !
!-------------------------------------------------------!

      program atomic
      implicit none
      integer, parameter  :: idp=8,nsize = 1000
      integer ::  i,id,omp_get_thread_num,nothread,omp_get_num_threads
      real(kind=idp)  :: x, answer



!$omp parallel private (i) shared(x)
!$omp do
      do i = 0, nsize-1
!$omp atomic
         x = x + dble(i)
      end do
!$omp end do
!$omp end parallel

      answer = 0.5_idp * (nsize-1)*nsize
      write(*,'(a,f10.2)') 'parallel sum is ',x
      write(*,'(a,f10.2)') 'correct answer is ', answer


      end program atomic
