Please test following code by pgfortran V11.4:
program test
use kernel
IMPLICIT NONE
double precision, device :: data1(10)
double precision :: data2(10)
call functest<<<1,10>>>(data1)
data2 = data1
write(0,*) data2
end program
MODULE kernel
CONTAINS
attributes(global) SUBROUTINE functest(output)
IMPLICIT NONE
double precision :: output(:)
double precision,constant :: s = 2.d0
output(threadidx%x) = s
END SUBROUTINE functest
END MODULE kernel
Compiled by “pgfortran -Mcuda test.F90”
Results:
0.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000
Analysis:
All initial values of constant variable are set to 0 in .gpu file by the compiler.