Jonathan L Dubois wrote: > > void r12(double *rij,double *x1,double *x2){ > int i; > double tmp1,tmp2; > > tmp2 = 0; > for(i=0;i<3;i++){ > tmp1 = x1[i]-x2[i]; > tmp2 += tmp1*tmp1; > } > tmp2 = sqrt(tmp2); > *rij = tmp2; > } From my experience I would start from something like the following. I assume usage of C++ to have `inline' available as part of the standard and not as a GNU CC extension. In C I would prefer a macro implementation. inline void r12(double *rij,double *x1,double *x2){   double tmp1, tmp2, tmp3;   tmp1 = x1[0] - x2[0];   tmp2 = x1[1] - x2[1];   tmp3 = x1[2] - x2[2];   *rij = sqrt (tmp1 * tmp1 + tmp2 * tmp2 + tmp3 * tmp3); } Improvements over the first version version:  - Entirely avoided inner loop.  - Differences can be calculated independently. Be sure that  - you are using libffm's sqrt ()  - you really need the distance computed every time you call    this function and not its sqare (an alternative would be    to do the sqrt () selectively in the calling functions) Stefan Schroepfer scr@iis.fhg.de