With the following reproducer,
module coefficient_module
implicit none
real, allocatable :: coeff(:)
contains
subroutine initialize_coeff(N)
integer, intent(in) :: N
allocate(coeff(N))
coeff = 2.0
end subroutine initialize_coeff
end module coefficient_module
program openmp_example
use coefficient_module, only: coeff, initialize_coeff
! comment out the next line to make the error disappear
use coefficient_module, only: coeff
implicit none
integer :: N, i
real, allocatable :: input(:), result(:)
N = 100
allocate(input(N), result(N))
input = 1.0
call initialize_coeff(N)
!$omp target teams distribute parallel do defaultmap(none) default(none) &
!$omp map(to: input) map(tofrom: result) &
!$omp shared(coeff, input, result, N)
do i = 1, N
result(i) = input(i) * coeff(i)
end do
print *, "First 5 results: ", result(1:5)
end program openmp_example
nvfortran -gpu=cuda11.8 -mp=gpu -O2 test_omp.f90
generates the following error:
NVFORTRAN-S-0155-coeff must appear in a SHARED or PRIVATE clause (test_omp.f90: 30)
This error message is somewhere between confusing and wrong. It does not appear if coeff is instead marked as private, or if the duplicate use is removed. If the compiler doesn’t like that, it should complain about that instead.
The example works fine as-is in Cray Fortran.
I’m using nvfortran 24.7-0 64-bit target on x86-64 Linux, using the nvhpc/24.7 toolkit.