Writing characters in OpenACC subroutines
Characters are an aggregate variable according to the OpenACC specification
OpenACC 3.3 Glossary 6
Writing while in a device subroutine is not covered in OpenACC. However, there are differences between the compilers, we tested everything with the following program
Code
program main
implicit none
character(len=12) :: message = "Success"
write(*,*) "Checking if characters can be printed in acc nohost subroutine ..."
call write_message(message)
contains
subroutine write_message(message)
!$acc routine seq
implicit none
character(len=12), intent(in) :: message
character(len=14) :: new_message
new_message = message(1:7) // "!"
write(*,*)new_message
end subroutine
end program
Compiler behaviour
| Compiler | Result | Correctness | Notes |
|---|---|---|---|
| Cray Fortran 19.0.0 | ❌ Compile error | Not covered by spec | Characters are not supported at all in device subroutines; the ftn-7066 error is shown below. |
| nvfortran 25.3-0 | ✅ OK | Not covered by spec | Compiles, runs and prints the message. |
The Cray compile error:
Code
new_message = message(1:7) // "!"
ftn-7066 ftn: ERROR WRITE_MESSAGE, File = characters_cray.f90, Line = 13
Unsupported accelerator code error: Fortran character
write(*,*)new_message
ftn-7066 ftn: ERROR WRITE_MESSAGE, File = characters_cray.f90, Line = 14
Unsupported accelerator code error: Fortran character -- new_message