! CSC/PATC Introduction to parallel programming using MPI and OpenMP
! (c) CSC 2013

program exer1
  implicit none
  integer :: var1, var2
  var1 = 1
  var2 = 2

  !$OMP PARALLEL PRIVATE(VAR1, VAR2)
  write(*,'(A,I0,A,I0)') 'Region 1:       var1=', var1, ', var2=', var2
  var1 = var1 + 1
  var2 = var2 + 1
  !$OMP END PARALLEL
  write(*,'(A,I0,A,I0)') 'After region 1: var1=', var1, ', var2=', var2
  print *

  !$OMP PARALLEL FIRSTPRIVATE(VAR1, VAR2)
  write(*,'(A,I0,A,I0)') 'Region 2:       var1=', var1, ', var2=', var2
  var1 = var1 + 1
  var2 = var2 + 1
  !$OMP END PARALLEL
  write(*,'(A,I0,A,I0)') 'After region 2: var1=', var1, ', var2=', var2
  print *

  !$OMP PARALLEL
  write(*,'(A,I0,A,I0)') 'Region 3:       var1=', var1, ', var2=', var2
  var1 = var1 + 1
  var2 = var2 + 1
  !$OMP END PARALLEL
  write(*,'(A,I0,A,I0)') 'After region 3: var1=', var1, ', var2=', var2
  print *

end program exer1
