Fortran array subscript ranges


I have a local array variable in my cuda kernel that is size 5. Since the array variable is inside the kernel, it will be the same size for each thread. However, I want to access the array with a different subscript range in each thread based on the thread’s id. For example, one thread might access it with 1:5 while another might use -2:2. Is this possible to implement or is there an easy workaround for this? Thanks in advance.

Hi jmark3,

Negative index are fine in Fortran, provided that the array was defined with a negative lower bound. Though, if you do not give a lower bound, the default value of 1 is used and a negative index would give you an out-of-bounds error.

You could make your array’s bounds from -2 to 5. “REAL, dimension(-2:5) :: myarray”. to make it fit your algorithm. You would just
be wasting a bit of space if you only used 5 elements.

Hope this helps,