fortran module save attribute arrays and OpenACC

In a fortran module, i have an array that has a SAVE attribute.

module test
!$acc declare create(STHE)

    subroutine init_sthe()
!initialize sthe on device doesn't work, but initialize on host and copy later owrks
    end subroutine

    subroutine use_sthe()
!!acc copyin(sthe)
    !use sthe on device
    end subroutine
end module

If I try to declare the array on device at module level and initilize it later directly on device in the init subroutine, it doesn’t seem to work. However, if i remove the declare subroutine on STHE, and simply do the initialization on the CPU, then copy the data to the device in use_sthe it works. Why the first approach doesn’t work ?

I read that PGI OpenACC did not support SAVE attribute a while ago, but seems to be supported now since PGI 15.5. Are module level SAVE attribute arrays actually supported now?


Hi Daniel,

The save attribute is implied for module variables so isn’t the problem, though, I’ll need a more complete example to see what’s wrong.

In general, you can put module variable in declare directives. This will allocate space on the device at load or when the array is allocated (if it’s an allocatable). You still need use the “update” directive to set the array’s value since it wont be initialized.