I cannot seem to figure out where I am getting a segmentation fault in my program. I've narrowed it down to where it is occurring but everything seems ok to me.
Code:
void nearest_neighbor(int s){
int k = 0, i = 0, count = 0; // loop counters
int bin = 0.0; // A temp. variable to use to bin r's
float rx = 0.0 , r1, r2;
float ry = 0.0;
float rz = 0.0;
float rA[NUM_A], rB[NUM_B], rAN[NUM_A], rBN[NUM_B];
float dr = Lx/2.0/Nbins;
/******************* AA Histogram Calculation **************************************/
for(k = 0; k < NUM_A; k++){
// sit on one particle and calculate/store all distances between all pairs
for(i = 0; i < NUM_A; i++){
if (k == i){ i++; } // skip the case when i = k because it will always be 0.0
rx = (x[k] - x[i])- Lx*rintl((x[k] - x[i])/Lx);
ry = (y[k] - y[i])- Ly*rintl((y[k] - y[i])/Ly);
rz = (z[k] - z[i])- Lz*rintl((z[k] - z[i])/Lz);
rA[i] = sqrt(rx*rx*+ry*ry+rz*rz);
}
quickSort(rA, NUM_A); // sort the distances between pairs
rAN[k] = rA[s];
}
for (i = 0; i < Nbins; i++){
r1 = i*dr;
r2 = r1 + dr;
for (count = 0; count < NUM_A; count++){
if (rAN[count] < r2 && rAN[count] >= r1){
histAA[i]++;
}
}
}
/***************************************************************************************************************/
}
I'm pretty sure it is happening during the last nested loop of the function. FYI histAA[] has Nbins elements and is defined globally.
Any help would be huge.
Thanks!
Paddon