Compiling error when use "acc declare" with OpenMP

Hello,

I am trying to use both OpenMP and OpenACC for my Fortran code. I find that if I use “declare create” for the global variables in my modules, I will have a problem when compiling the code.

This is an example code

module test
  use omp_lib
  use openacc
  implicit none
  real, allocatable, dimension(:,:,:) :: a, b, c
!$acc declare create(a)

  contains

  subroutine run
    integer :: i
    real :: s
    allocate(a(100000,10000,2))
!$omp parallel num_threads(1)
!$acc parallel loop
    do i=1,100000
      s=a(1,1,1)
    enddo
!$omp end parallel
  end subroutine

end module

When compiling the code, I got the following error.

$pgfortran -c -r8 -Mpreprocess -mp -acc -ta=tesla test.f90
PGF90-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unknown variable reference (test.f90: 28)
PGF90-F-0704-Compilation aborted due to previous errors. (test.f90)
PGF90/power Linux 19.9-0: compilation aborted

This error can be eliminated by either removing omp directives, or by commenting “!$acc declare create”.

But I do need acc declare since this array will be used by other acc routines. I don’t understand why OpenMP matters here.

Modifying your example slightly:

#define N 100000

module test
  use omp_lib
  use openacc
  implicit none
  real, allocatable, dimension(:) :: a, b, c
  !$acc declare create(a,b)

  contains

  subroutine run
    integer :: i

    allocate(a(N))
    allocate(b(N))

    a = 1.0
    b = 2.0

!$omp parallel num_threads(1)
!$acc parallel loop
    do i=1,N
      c(i) = a(i) + b(i)
    enddo
!$omp end parallel
  end subroutine

end module

Moving the declare create into the subroutine will work, but that defeats the purpose and is no better than a normal data region.

2132 If the declare directive appears in a global context, then the data in var-list is statically allocated
2133 in device memory and the structured reference counter is set to one.

Seems like it should work at the module-level, so I’ve filed TPR #27862 to at least look again more closely.