Transfer a scalar variable

Dear All,

In the following case, could you let me know if I should transfer the scalar variable “sum” using the directive “data” ?
Here is the test code.

The scalar variable “sum” is initialized to the value of “0” in order to get a right value.
However I don’t know if PGI compiler initialize the variable to the value of “0”.

----------------------------------- test.F90 ------------------------------
implicit none
inteter(kind=4) :: i
integer(kind=4),parameter :: N = 10
real(kind=8),dimension(N) :: x
real(kind=8) :: sum

sum = 0.0d0
!$acc data copyin(x(1:N))
!$acc kernels
do i = 1,N
sum = sum + x(i)
end do
!$acc end kernels
!$acc end data

end

Hi KOUCHI_Hiroyuki,

In most cases, PGI can automatically detect reductions as shown here in the compiler feedback messages.

% pgf90 test.f90 -acc -Minfo=accel
foo:
      9, Generating copyin(x(:))
     11, Loop is parallelizable
         Accelerator kernel generated
         Generating Tesla code
         11, !$acc loop gang, vector(32) ! blockidx%x threadidx%x
         12, Generating implicit reduction(+:sum)

Though for portability, you should consider using a reduction directive:

% cat test.f90
program foo
implicit none
integer(kind=4) :: i
integer(kind=4),parameter :: N = 10
real(kind=8),dimension(N) :: x
real(kind=8) :: sum

sum = 0.0d0
!$acc data copyin(x(1:N))
!$acc kernels
!$acc loop reduction(+:sum)
do i = 1,N
sum = sum + x(i)
end do
!$acc end kernels
!$acc end data
print *, N
end
% pgf90 test.f90 -acc -Minfo=accel
foo:
      9, Generating copyin(x(:))
     12, Loop is parallelizable
         Accelerator kernel generated
         Generating Tesla code
         12, !$acc loop gang, vector(32) ! blockidx%x threadidx%x
             Generating reduction(+:sum)

Per the OpenACC 2.5 standard (see section 2.5.11), sum reduction variables are initialized to zero. So, yes, PGI does initialize “sum” to zero here.

  • Mat

Dear Mat-san,

Thank you for all the information.
My jobs work normally on NVidia GPU using PGI compiler.

Sincerely yours,