! using parallel do directives to parallel do loop
! incorect runtime results (vary from run to run)
! do to the writing to 'total' globle varable which 
! cannot simply make it private
! need synchronisation !
program sharing_par1
use omp_lib
  implicit none
  integer, parameter :: N = 50000000
  integer(selected_int_kind(17)) :: x(N)
  integer(selected_int_kind(17)) :: total
  integer :: i
  !$omp parallel
     !$omp do
         do i = 1, N
            x(i) = i
         end do
      !$omp end do
      total = 0
      !$omp do
          do i = 1, N
             total = total + x(i)
          end do
     !$omp end do
  !$omp end parallel
  write(*,*) "total = ", total
end 
