passing two dimensional fortran array to CUDA C

I am trying to use fortran wrapper for CUDA C.In fortran routine, I declare array as A(10,3) , and then pass this array to the CudaC program as a one dimensional pointer. How should I access the elements of this array in Cuda C.I am confused.Plz help(Important part of the code is in block)My code for fortran is:

program main

implicit none

integer :: Nmol,mol,i,j,k,m
real,dimension(10) :: Xo_h,Yo_h,Zo_h,ee_h
real,dimension(10,3) :: Xi_h,Yi_h,Zi_h
real,dimension(3) :: xii,yii,zii
real,dimension(3) :: CHARGE

real ::temp,xij,yij,zij,tmp,rij,rij2,de,rrlcut,rrlcutsq
real :: box_x,box_y,hbox_x,hbox_y,t2,t1
real :: gpu_de
mol = 3
Nmol = 10
rrlcut = 10.0
rrlcutsq = 100.0
box_x = 36.182351
box_y = 36.182351
hbox_x = 0.5box_x
hbox_y = 0.5
CHARGE(1) = -0.8476
CHARGE(2) = 0.4238
CHARGE(3) = 0.4238

de = 0.0

ee_h = 0.0
Xi_h = 0.0
Yi_h = 0.0
Zi_h = 0.0

open(20,file = ‘results.dat’)

open( 30, file = ‘xyz_00.dat’ )

    do m = 1, 6
    end do

 do i = 1, Nmol

    read(30,*) temp, Xo_h(i), Yo_h(i),Zo_h(i)
    do j = 1, 3
    read(30,*) temp,Xi_h(i,j),Yi_h(i,j),Zi_h(i,j)
   if( j==1) write(20,*)Xi_h(i,j),Yi_h(i,j),Zi_h(i,j)
    end do
 end do

call host(Xi_h,Yi_h,Zi_h,ee_h,mol,Nmol)

NOW THE CUDA C Function is:

extern “C” void host_(float *Xi_h,float *Yi_h,float Zi_h,float ee_h,int mol,int Ntot)

int nBytes, i,j, N,index ;
float *Xi_d, *Yi_d, *Zi_d, *ee_d ;
float xii_oxy_d,yii_oxy_d,zii_oxy_d;
float xii_H1_d,yii_H1_d,zii_H1_d;
float xii_H2_d,yii_H2_d,zii_H2_d;

N = *Ntot;
index = *mol -1 ;

printf(“index is %i \n”,index);

nBytes = 3Nsizeof(float);

///// Here I access A(3,j) of fortran array.This is giving me wrong answers ///////

xii_oxy_d = Xi_h[index];
yii_oxy_d = Yi_h[index];
zii_oxy_d = Zi_h[index];
xii_H1_d = Xi_h[31+index];
yii_H1_d = Yi_h[3
zii_H1_d = Zi_h[31+index];
xii_H2_d = Xi_h[3
yii_H2_d = Yi_h[32+index];
zii_H2_d = Zi_h[3

I thought real types in fortran were double precision? I’m not certain though…

If F is declared with dimension F(n, m) in fortran to access F(a, b ) you would need to access C[(b - 1) * n + (a - 1)] in C.

No - default real type in Fortran is single precision. The other part of your comment is basically correct, though: two-dimensional arrays are stored in column-major order in Fortran, thus C/C++ code accessing this kind of array should take care of this. So I guess OP should change, in his C++ code, lines like:

xii_H1_d = Xi_h[3*1+index];

to something like (although is very hard to be sure when the code posted is neither complete nor minimal, and without much hint on what exactly are expected outputs of the problematic operation):

xii_H1_d = Xi_h[10*1+index];

Thanks a lot for your reply.I will try these changes.