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, as the array in fortran is column major and in CUDA C ,it is row major .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.5box_y
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
read(30,*)
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[31+index];
zii_H1_d = Zi_h[31+index];
xii_H2_d = Xi_h[32+index];
yii_H2_d = Yi_h[32+index];
zii_H2_d = Zi_h[32+index];