File reading problem

Dear all,

I’m trying to read in numbers from a file and encounter a strange problem in that the program reads in values correctly from the file
but always crashes when trying to assign the values to more than one array. It would only accept one of the lines reading

                h_eigenvector_realx[address] = (double)c1;
                h_eigenvector_imagx[address] = (double)c2;
                h_eigenvector_realy[address] = (double)c3;
                h_eigenvector_imagy[address] = (double)c4;
                h_eigenvector_realz[address] = (double)c5;
                h_eigenvector_imagz[address] = (double)c6;

I have to comment out five of the six lines above, then it will work. If more than one line is uncommented than it will crash. This is rather
puzzling as I would not expect this to happen. All of the above 6 arrays are allocated using (double*) malloc(nphononbranches * natoms * sizeof(double)). nphononbranches is 96 and natoms 32, so would not expect a problem using too much memory.

Here is the code segment:

        for(int nfreq=0; nfreq < nphononbranches; nfreq++)
        {
            printf("Loop counter %d \n", nfreq);
            for(int nat=0; nat < natoms; nat++)
            {

// printf(“Loop counter here %d \n”, nat);
fgets(s,400,phononfile);
// printf(“Past here\n”);
if(feof(phononfile))
{
printf(“Missing information in %s\n”, phononfile);
fclose(phononfile);
exit(-1);
};
// printf(“Just before reading %s\n”, s);
sscanf(s, “%d %d %f %f %f %f %f %f, \n”, &n1, &n2, &c1, &c2, &c3, &c4, &c5, &c6);
printf(“Read %s\n”, s);
printf(“c1, c2 %f %f \n”, c1, c2);
address = nfreq * nphononbranches + nat;
h_eigenvector_realx[address] = (double)c1;
h_eigenvector_imagx[address] = (double)c2;
h_eigenvector_realy[address] = (double)c3;
h_eigenvector_imagy[address] = (double)c4;
h_eigenvector_realz[address] = (double)c5;
h_eigenvector_imagz[address] = (double)c6;
};
};

I would appreciate very much any suggestions to get this working. I’m using CUDA 2.3 under Windows XP.

Many thanks!

Your index is off:
The last position for example is:
address = nfreq * nphononbranches + nat;
with nfreq == nphononbranches-1 and nat == natoms-1
which gives: address = (nphononbranches-1) * nphononbranches + natoms - 1 => 9596+31 == 9151
You only have room for: 96
32 == 3072 doubles.