Hi! I hope someone can help me with a (simple but big!) performance problem with a C program.
I'm a computational chemist and I did a C-code which spent much of its time inside a triple loop (few second with the test input data but some day with "real" data).
These loops compute a variable, "sjk", very fast (less than 2 sec.) if I don't put OUT of the loops any instruction like:
printf("%f",sjk);
But, if I try to visualize this variable with a printf, the code runs very much slower (> 1000 sec.).
I tried to rename it out of the loop etc... I always have the same problem.
I discover also that if "sjk" is declared as a global one, the program runs slowly even thoug I don't use printf.
I think the problem could be some optimization option of the compiler (I compile with gcc -fast on MacOsx Tiger, G4) which can not switched on when I try to print "sjk" or I use it as a global variable.
Do anyone know the reason (and possibly a solution) of my problem?
Thank you!
Code:sjk=0.; for(i=0;i<natoms;i++){ for(j=rows_xyz[0][i];j<=rows_xyz[1][i];j++){ xloc=x[j]; yloc=y[j]; zloc=z[j]; for(k=rows_xyzls[0][i];k<=rows_xyzls[1][i];k++){ D[0]=xloc-xls[k]; D[1]=yloc-yls[k]; D[2]=zloc-zls[k]; D[0]=D[0]*D[0]; D[1]=D[1]*D[1]; D[2]=D[2]*D[2]; D[2]=D[0]+D[1]+D[2]; D[2]=sqrt(D[2]); if (D[2]!=0.){ D[2]=1./D[2]; sjk=sjk+D[2]*lagwj[k]; } } sjk=sjk*pinv; } } /* Here I want to print sjk! */



LinkBack URL
About LinkBacks



Is your program really long? Perhaps you could post a little more of it to have a look at?