alphalinux.org high-perf list (1998-2001)
 help / color / mirror / Atom feed
From: Kazushige Goto <goto@statabo.rim.or.jp>
Subject: Re: Questions on performance methods
Date: Sun, 29 Nov 1998 12:40:47 +0900	[thread overview]
Message-ID: <19981129124047T.goto@statabo.rim.or.jp> (raw)
In-Reply-To: <Pine.LNX.3.96.981128140536.10320C-100000@bec.physics.udel.edu>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4192 bytes --]

From: Jonathan L Dubois <dubois@bec.physics.udel.edu>

Date: Sat, 28 Nov 1998 14:28:39 -0500 (EST)

dubois> The only problem I foresee with doing all the sqrts in r12 at once is that

dubois> I occasionally get some computational savings when (rij <= b)  The

dubois> probability of this occurring is usually fairly low but it increases with

dubois> N and is not easily predicted ahead of time.  It will also probably

dubois> require some restructuring since q[i] is an array of structures which

dubois> contain information other than the 3vectors of interest here.

I modified your routine.  One is slightly optimized, and another is

vectorlized sqrt version.

1. light optimize

The overhead of r12 is pretty heavy.

int find_jastrow(double *result,int j,struct coord *q,double r[3],double b){

  int i;

  double rij;

  double tmp;

  double tmp1, tmp2, tmp3;

  double r1, r2, r3;

  r1 = r[0];

  r2 = r[1];

  r3 = r[2];

  

  tmp = 1.0;

  if(b>0){

    for(i=0;i < N;i++){

      if(i!=j){

        tmp1 = q[i].x[0]-r1;

        tmp1 = tmp1*tmp1;

        

        tmp2 = q[i].x[1]-r2;

        tmp2 = tmp2*tmp2;

        tmp3 = q[i].x[2]-r3;

        tmp3 = tmp3*tmp3;

        rij = sqrt(tmp1 + tmp2 + tmp3);

        if(rij > b){

          tmp *= (1.0 - b/rij);

        }

        else{

          *result = 0;

          return 0;

        }

      }

    }

  }

  *result = tmp;

  return 1;

}

2. using sqrti routine

          tmp *= (1.0 - b/rij);

is pretty slow.  You can use sqrti routine instead of sqrt.

This "sqrti" routine(calculates 1.0/sqrt() quickly) will be included

next libffm version.

double sqrti(double);

int find_jastrow(double *result,int j,struct coord *q,double r[3],double b){

  int i;

  double rij;

  double tmp;

  double tmp1, tmp2, tmp3;

  double r1, r2, r3;

  double bi = 1./b;

  r1 = r[0];

  r2 = r[1];

  r3 = r[2];

  

  tmp = 1.0;

  if(b>0){

    for(i=0;i < N;i++){

      if(i!=j){

        tmp1 = q[i].x[0]-r1;

        tmp1 = tmp1*tmp1;

        

        tmp2 = q[i].x[1]-r2;

        tmp2 = tmp2*tmp2;

        tmp3 = q[i].x[2]-r3;

        tmp3 = tmp3*tmp3;

        rij = sqrti(tmp1 + tmp2 + tmp3);

        if(rij < bi){

          tmp *= (1.0 - b * rij);

        }

        else{

          *result = 0;

          return 0;

        }

      }

    }

  }

  *result = tmp;

  return 1;

}

3. using vectorlized sqrtiv routine.

The sqrti routine is still bottle neck.  We can modify to use

vectorlized sqrti routine.  But it'll be slower if the probability of

"rij < bi" is low.  If it's much improved(depend on your source

parameter), this routine can be faster still more.

I attached libffm.a, but it is a beta version.  

void dsqrtiv(double *, double *, int);

int find_jastrow(double *result,int j,struct coord *q,double r[3],double b){

  int i;

  double tmp;

  double tmp1, tmp2, tmp3;

  double r1, r2, r3;

  double bi;

  double vtemp[N];

  r1 = r[0];

  r2 = r[1];

  r3 = r[2];

  

  tmp = 1.0;

  if(b>0){

    for(i=0;i < N;i++){

        tmp1 = q[i].x[0]-r1;

        tmp1 = tmp1*tmp1;

        

        tmp2 = q[i].x[1]-r2;

        tmp2 = tmp2*tmp2;

        tmp3 = q[i].x[2]-r3;

        tmp3 = tmp3*tmp3;

        vtemp[i] = tmp1 + tmp2 + tmp3;

      }

    dsqrtiv(vtemp, vtemp, N);

    bi = 1.0/b;

    for(i=0;i < N;i++){

      if(i!=j){

        if(vtemp[i] < bi){

          tmp *= (1.0 - b * vtemp[i]);

        }

        else{

          *result = 0;

          return 0;

        }

      }

    }

  }

  *result = tmp;

  return 1;

}

---
goto@statabo.rim.or.jp

Application/Octet-Stream attachment: ibffm.a.gz_

  reply	other threads:[~1998-11-29  3:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-27  7:49 Questions on performance methods Martin Kahlert
1998-11-27 15:42 ` pshimizu
1998-11-28 12:53 ` Kazushige Goto
1998-11-28 19:28   ` Jonathan L Dubois
1998-11-29  3:40     ` Kazushige Goto [this message]
1998-11-29 18:09       ` pshimizu
1998-11-30  2:54         ` naohiko shimizu
1998-12-01  6:24           ` naohiko shimizu
1998-12-01 14:19             ` Joachim Wesner
1998-12-02  3:35               ` naohiko shimizu
1998-12-02  9:21                 ` Joachim Wesner
1998-12-02 15:42                   ` pshimizu
1998-12-02 16:48                     ` Joachim Wesner
1998-12-07  3:24             ` naohiko shimizu
  -- strict thread matches above, loose matches on Subject: below --
1998-11-30 14:09 Richard Gorton
     [not found] <Pine.LNX.3.96.981201174956.16291A-100000@bec.physics.udel.edu>
1998-12-04  2:39 ` naohiko shimizu
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