program alloc
!$ use OMP_LIB
implicit none
real(8), dimension(:), allocatable :: T,U
integer :: Nx1 = 20, rank, Nx1min, Nx1max
integer :: tnot ! total number of threads
allocate(T(1:Nx1)) ! T is shared, allocate before PR
!$OMP PARALLEL SHARED(T) PRIVATE(U,rank,tnot,Nx1min,Nx1max)
rank = OMP_GET_THREAD_NUM () ! get the rank of current thread
tnot = OMP_GET_NUM_THREADS() ! get the total number of threads currently running this PR
Nx1min = 1 + rank * (Nx1/tnot) ! calculate the first point to be calculated by this thread
Nx1max = (rank +1) * (Nx1/tnot) ! calculate the last point to be calculated by this thread
print *, "rank :", rank, "tnot :", tnot, "min and max :", Nx1min, Nx1max
allocate(U(1:Nx1/tnot)) ! U is private, allocate inside the PR
U(1:Nx1/tnot) = rank + 10
T(Nx1min:Nx1max) = U(1:Nx1/tnot)
deallocate(U)
!$OMP END PARALLEL
print *,T
deallocate(T)
end program alloc