Zero-based index for device data

When I allocate an array as

real, dimension(:), allocatable, device: arr_J, arr_I


and when I use these arrays inside the kernel, would the kernel know which one is zero-based index?

attributes(device) mykernel()
ii = … // detect index

use arr_J(ii) !!! --> zero-based or not???
use arr_I(ii)

or I have to pass the information explicitly like this

attributes(device) mykernel(arr_J, arr_I, size)
real, dimension(0:size), device: arr_J
real, dimension(size), device: arr_I

ii = … // detect index

use arr_J(ii) !!! --> zero-based or not???
use arr_I(ii)


Hi Tuan,

Since these are allocatable arrays and hence have a F90 array descriptor which contains the bounds information, you shouldn’t need to pass this information. Are you encountering an error?

  • Mat

Hi Mat,
I didn’t have a runtime error. But in CPU, suppose the memory address is

arr_J[0] at address 100
arr_J[1] at address 101

if I don’t pass the dimension explicitly to the function, say

function foo(arr_J)
  real, dimension(:) :: arr_J
  arr_J(1) = 10
end function

the first element of the zero-based allocated array arr_J(1) will be interpreted as location 100. So, I don’t know how it works with GPU data.

UPDATE: The above fact maybe wrong. Please correct me! Based on your answer, it means that the dimension information is kept with ‘allocatable’ array, so it doesn’t matter if we pass the explicit dimension information or not to the function that use this ‘allocatable’ array?