!----------------------------------------------------------------    
module mod_test
use ISO_FORTRAN_ENV, only : ik => int32
use ISO_FORTRAN_ENV, only : rk => real64
implicit none

private
integer(ik),public :: nvar
public :: bar

!$OMP THREADPRIVATE(nvar)

interface
    module subroutine bar(i, j, k, d, icase)
    implicit none
    integer(ik), intent(in ) :: i, j, k, icase
    real(rk)   , intent(out) :: d
    end subroutine bar
end interface
    
end module mod_test
!----------------------------------------------------------------
    

!----------------------------------------------------------------    
submodule (mod_test) smod_test
!variables private to this submodule:
integer(ik),dimension(:),allocatable :: iarray

!$OMP THREADPRIVATE(iarray)     !<-- issue:  stating this $OMP directive (also in non-OMP use case), 
                                !together with /Qopenmp compiler switch, causes the variable to not 
                                !be accessible in VS debugger (watch window).
contains
    
    module subroutine bar(i, j, k, d, icase)
    use ISO_FORTRAN_ENV, only : ik => int32
    use ISO_FORTRAN_ENV, only : rk => real64
    implicit none
    integer(ik), intent(in ) :: i, j, k, icase
    real(rk)   , intent(out) :: d
    integer(ik) :: ig
    integer(ik),dimension(nvar) :: iray
    !.............
    if (icase == 1) then
        allocate(iarray(nvar))
        iarray = [(ig, ig = 1,nvar)]
    endif
    iray = i*iarray(1:nvar)

    d = real(i*j*k,rk)

    if (icase == 5) then
        deallocate(iarray)    
    endif
    end subroutine bar

end submodule smod_test 
!----------------------------------------------------------------


!----------------------------------------------------------------
program submodule_test2
use ISO_FORTRAN_ENV, only : ik => int32
use ISO_FORTRAN_ENV, only : rk => real64
use mod_test
implicit none

integer(ik) :: i, j, k, icase
real   (rk) :: d
! ----------------------------------------------

nvar = 5

i = 2
j = 5
k = 3
icase = 1
call bar(i,j,k,d,icase)
write(*,'(1ES18.4)') d

icase = 5
call bar(i,j,k,d,icase)
write(*,'(1ES18.4)') d

end program submodule_test2
!----------------------------------------------------------------