A large data file (having 1000000 rows and 2 columns) is required to be accessed from a device function. At every step of computation, the value of a variable changes in the device function and the values of a particular row of the data file is required. So the whole data file should be available in the device function as there is no control over the value of the variable at every step.
In the following program, the value of the variable is sent to a host device function from a device function and then the variable is sent to a host function (where the data file is available) from the host device function.The host function picks up the required values from the entire array and in this way the required values for one particular step may be got at the device function. But this process is not working for the code.
I don't know whether the keyword __host__ __device__
works in cuda V0.2.1221 or not.
Please suggest a way to accss the large data file in a device function.
The required portion of the code is given beow.
__host__
void magnetic( R *xx, R *magfield)
{
float Bx[1000001],By[1000001];
R x[3];
int k;
FILE *fp;
fp = fopen("field.dat", "r");
for (int i=0;i<=1000000;i++)
{
fscanf(fp, "%f%f", &Bx[i], &By[i]);
}
fclose(fp);
printf("%f\t%f\n",Bx[0],By[0]);
for( int i=0;i<3;i++){
x[i]=*xx;
xx++;
}
//printf("%f\t%f\t%f\n",x[0],x[1],x[2]);
k=round((zi+x[2])/dz);
magfield[0]=Bx[k];
magfield[1]=By[k];
magfield[2]=2.;
}
__host__
void magnetic(R *xx, R *magfield);
__host__ __device__
void field(R *xx, R *magfield){
R x[3];
for( int i=0;i<3;i++){
x[i]=*xx;
xx++;
}
magnetic(x,magfield);
}
__host__ __device__
void field( R *xx, R *magfield);
__device__
void eval_rhs( R *f, R *df, R time, int istep) {
R magfield[3],vXB[3];
df[0] = f[3];
df[1] = f[4];
df[2] = f[5];
field( &f[0], magfield);
crossmultiply(&f[3], magfield, vXB);
df[3] = Ex + vXB[0];
df[4] = Ey + vXB[1];
df[5] = Ez + vXB[2];
}