Hi
it’s well kown fortran is column-major. but i found some problem in cuda fortran.
A is a MN matrix in device memory, i stored it in a 1-d array A(MN).
in order to test, i write a sample like this
ix = (blockidx%x - 1) * blockdim%x + threadidx%x
iz = (blockidx%y - 1) * blockdim%y + threadidx%y
A(nz*(iz-1)+ix) = iz
if cuda fortran is column-major, then this will be ok, but i can’t get the right answer. some elements of a are not given the right value.
then i make some change by citing element of A through following usage.
A(nz*(ix-1)+iz) = iz
the answer is right. only if A is row-major can the answer be right.
the confusion is cuda fortran row-major in device memory?
Since there are only one-dimensional arrays in the code that you showed, I suspect that the issue is not with how two-dimensional arrays are mapped into one-dimensional arrays, but with confusion about computing the linear offset from two indices. The line
A(nz*(iz-1)+ix) = iz
is suspicious; specifically, with a two dimensional array B(M,N) in Fortran, the offset of B(i,j) from the base of B is (j - 1)*M + (i - 1). Note in particular that the multipler of the second index (j) is the first declared dimension (M).