From: Stefan Schroepfer <scr@iis.fhg.de>
Subject: Re: request for perf improvement suggestions
Date: Thu, 26 Nov 1998 10:45:38 +0100 [thread overview]
Message-ID: <365D2342.446B9B3D@iis.fhg.de> (raw)
In-Reply-To: <Pine.LNX.3.96.981125155452.6224A-100000@bec.physics.udel.edu>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]
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
next prev parent reply other threads:[~1998-11-26 9:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-11-25 21:15 request for perf improvement suggestions Jonathan L Dubois
1998-11-25 21:44 ` Adam
1998-11-26 9:45 ` Stefan Schroepfer [this message]
1998-11-26 15:48 ` Joachim Wesner
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox