living.thematri
Registered
Hi!
I'm a computational chemist and I did a C-code which spent much of its time inside a triple loop.
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 that if "sjk" is declared as a global one, the program runs slowly also if I don't print it.
I think the problem could be some optimization option of the compiler (I compile with -fast) 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!
living.thematrix@gmail.com
for(i=0;i<natoms;i++){
for(j=rows_xyz[0];j<=rows_xyz[1];j++){
xloc=x[j];
yloc=y[j];
zloc=z[j];
sjk=0.;
for(k=rows_xyzls[0];k<=rows_xyzls[1];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;
}
}
I'm a computational chemist and I did a C-code which spent much of its time inside a triple loop.
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 that if "sjk" is declared as a global one, the program runs slowly also if I don't print it.
I think the problem could be some optimization option of the compiler (I compile with -fast) 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!
living.thematrix@gmail.com
for(i=0;i<natoms;i++){
for(j=rows_xyz[0];j<=rows_xyz[1];j++){
xloc=x[j];
yloc=y[j];
zloc=z[j];
sjk=0.;
for(k=rows_xyzls[0];k<=rows_xyzls[1];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;
}
}