I wanted to post up better psuedo code the reflects what I think is the real problem with this code.
Code:
typedef struct{
double *xp;
double cp;
} SV_FDIndx
typedef SV_FDIndx * SV_pFDIndx
SV_pFDIndx fd_phi;
double *a;
double *xvals;
//assume all mallocs memsets appropriately done
for (int i = 0; i < get_n_nodes(); i++){
fd_phi = struct_returning_function(i); //this actually returns it from within another, separate structure not relevant here
a[i] = fd_phi->cp; //"c" for constant
}
for(int j = 0; j < 500; j++){
for(int k = 0; k < 3; k++){
for(int n = 0; n < get_n_nodes(); n++){
fd_phi = struct_returning_function(n);
psi[n] = a[n] * *fd_phi->xp;
}
//assume something may modify the value of xp here
}
}
This seems to be what is happening, at least. I am the one who modified it to include the array a[] within that inner loop. it used to be
Code:
psi[n] = fd_phi->cp * *fd_phi->xp;
and once I realized those were constants, it worked fine.
I have also tried to, in my "pre-load" loop at the beginning, define an array of type SV_pFDIndx, and store all the values returned from struct_returning_function(n); so that I could attempt to write
Code:
fd_struct_array[i] = struct_returning_function(i);
*xvals[i] = *fd_struct_array[i]->xp;
in the preload loop, and
Code:
for(int n = 0; n < get_n_nodes(); n++){
fd_phi = struct_returning_function(n);
psi[n] = a[n] * xvals[n];
}
in the main loop.
This didnt seem to work for me, but if I did
Code:
for(int n = 0; n < get_n_nodes(); n++){
psi[n] = a[n] * *fd_struct_array[i]->xp;
}
it did seem to work.
This got me thinking about declaring that array of pointers, and how I might be doing that wrong/is it any faster anyway?