OpenACC firstprivate variables

260 views Asked by At

I encounter an issue with arrays in OpenACC kernels. Here is the demo code:

module mpoint
   type point
      real :: x, y, z
      real :: tmp
      real :: v(3)
   end type point
 end module mpoint
 
 program main
   
   use mpoint
   
   implicit none
 
   integer, parameter :: n = 3
   real, allocatable :: array(:)
   !--------------------------------
   
   allocate(array(n))
   array(:) = 1.0

   call vecadd
   
 contains
   subroutine vecadd()
     integer :: i
     type(point) :: A
     real :: w(3)
     real :: scalar

     A%v(:) = 0.0
     A%v(1) = 1.0

     w(:) = 0.0
     w(1) = 1.0
     
     scalar = 1.0

     write(*,*) 'host: v(1) = ', A%v(1)
     write(*,*) 'host: w(1) = ', w(1)
     write(*,*) 'host: scalar = ', scalar

     !$acc parallel loop firstprivate(A,w)
     do i = 1, n
        write(*,*) 'device: v(1) = ', A%v(1)
        write(*,*) 'device: w(1) = ', w(1)
        write(*,*) 'device: scalar = ', scalar
     enddo

   end subroutine vecadd
   
 end program main

When I compile it with nvfortran -acc -Minfo=accel test.f90 and run, it shows that on the device the values in the arrays are 0.0, not the correct values 1.0 I set on the host side. This happens only for arrays: scalars, like shown in the example, has the right values.

I am wondering if this is a limitation for nvfortran, or the current OpenACC standard?

1

There are 1 answers

0
Mat Colgrove On

Looks like a compiler issue where we're not initializing the small arrays on the host. In looking through our existing bug reports, I see one that's nearly identical, just with C instead of Fortran, that by coincidence got fixed in our development compiler this morning. Unfortunately it didn't seem to fix your issue as well. I sent a note to the compiler engineer assigned to the issue asking if he can take a look.

Worst case if the issue turns out to be similar but unrelated, I'll open a new problem report and update this post with the tracking number.