Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Binary search speed in Alpha
@ 1998-11-27 10:07 Jaap Schellekens
  1998-11-27  8:58 ` Matti Aarnio
  0 siblings, 1 reply; 15+ messages in thread
From: Jaap Schellekens @ 1998-11-27 10:07 UTC (permalink / raw)
  To: axp-list


Hello all,

I have a model of unsaturated flow which I try to optimize
speedwise. I'm asking you this becuase we are in the process
of getting one ore two new workstation for modelling and I would
love to get an Alpha. 

From profiling I concluded that most of the time is not spend
in the matrix solving, but in the functions to construct the matrix.
Basically I'm now looking at a method for searching a sorted table
that has a better performance on an Alpha. I suspect the 
memory access pattern of the binary search I use does not
favour the Alpha architecture a lot. Some numbers (seconds):

Arch				TimeA	     TimeB    TimeC
----------------------------------------------------------
pentium 293MMX (used to be 233):  19.1       37.1       -
Alpha XL300:			  19.4	     100.7     26.1
SPARC Ultra 170:		  30.3	     91.5       -

TimeA: run time with look-up tables 
TimeB: run time original function 
TimeB: run time original function using libfm and libffm


From this i conclude:
 1) libfm  and libffm are a Good Thing Indeed!!
 2) Somehow the binary search is not well optimized
    for the Alpha architecture


I have tried several things, including changing the size of the look up
tables but that has very little influence on the results. The same for
changing the type of the tables from double to float.

Any suggestions (also pointers to books on this subject) are welcome,


Jaap


The code (based on an old -- freeware -- pascal version of numerical recipies):

double getval_short(TBL *tab, double xval)
{
	unsigned long index,mid,lo,up,n;
	int ascnd;
	double top,bott,rico;

	/* first check high and low points */	
	if (xval <= tab->x[0])
		return tab->y[0];
	else if (xval >= tab->x[(tab->points) - 1])
		return tab->y[(tab->points) - 1];

	/* Find position in array: x[index] < xval < x[index +1]*/
	n = tab->points;
	lo = -1; up = n;

	ascnd = (tab->x[n - 1] >= tab->x[0]);
	while (up - lo > 1){
		mid = (up + lo) >> 1;
		if (xval >= tab->x[mid] == ascnd)
			lo = mid;
		else
			up = mid;
	}
	if ( xval == tab->x[0])  index = 0;
	else if (xval == tab->x[n-1]) index =  n - 2;
	else index = lo;

	/* linear interpolation */
	top = (tab->y[index + 1] - tab->y[index]);
	bott = (tab->x[index + 1] - tab->x[index]);
	rico =  top/bott;
	return (rico * (xval - tab->x[index])) + tab->y[index];
}

-- 
--------------------------------------------------------------
Jaap Schellekens                E-mail:         schj@geo.vu.nl
Hydro(geo)logy Dept.            Fax:            ++31 20 6462457
Inst. of Earth Sc.              Voice:          ++31 20 4447287
Vrije Universiteit
De Boelelaan 1085               use finger schj@flow.geo.vu.nl
                                for extra information
1081 HV Amsterdam NL            See also:   http://flow.geo.vu.nl


^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: Binary search speed in Alpha
@ 1998-11-27 13:58 Wessels, Hans
  0 siblings, 0 replies; 15+ messages in thread
From: Wessels, Hans @ 1998-11-27 13:58 UTC (permalink / raw)
  To: 'axp-list@redhat.com'

Hi  Jaap,

>double getval_short(TBL *tab, double xval)
>{
>	unsigned long index,mid,lo,up,n;
>	int ascnd;
>	double top,bott,rico;
>
>	/* first check high and low points */	
>	if (xval <= tab->x[0])
>		return tab->y[0];
>	else if (xval >= tab->x[(tab->points) - 1])
>		return tab->y[(tab->points) - 1];
>
>	/* Find position in array: x[index] < xval < x[index +1]*/
>	n = tab->points;
>	lo = -1; up = n;
>
>	ascnd = (tab->x[n - 1] >= tab->x[0]);
>	while (up - lo > 1){
>		mid = (up + lo) >> 1;
>		if (xval >= tab->x[mid] == ascnd)
>			lo = mid;
>		else
>			up = mid;
>	}
>	if ( xval == tab->x[0])  index = 0;
>	else if (xval == tab->x[n-1]) index =  n - 2;
>	else index = lo;
>
>	/* linear interpolation */
>	top = (tab->y[index + 1] - tab->y[index]);
>	bott = (tab->x[index + 1] - tab->x[index]);
>	rico =  top/bott;
>	return (rico * (xval - tab->x[index])) + tab->y[index];
>}
>

Tried to change your data structures?

From what y read TAB is something like:
struct TAB_struct
{
  int points;
  double x[];
  double y[];
} TAB;

try something like
struct coord_struct
{
  double x;
  double y;
}

struct TAB_struct
{
  struct coord_struct c[];
  int points;
}

If your coordinates are allocated dynamicly get the pointer local in
your function:
{
  struct coord_struct* = tab->c;
}

so no double pointer dereferencing is needed (don't know how good gcc or
egcs is with tricks like that).

Bye, Hans

----------------------------------------------------------------------
   /|   /\/\/\   |\      ir. Hans Wessels
  / |  / /\/\ \  | \     H.Wessels@Energie-Delfland.nl
 /  | / / /\ \ \ |  \    tel.: 015 251 4397
/   |/ / /  \ \ \|   \   
\   |\ \ \  / / /|   /   prive:
 \  | \ \ \/ / / |  /    mr_ni@mbh.org
  \ |  \ \/\/ /  | /     Fidelus Bittus et Fuckus Clockcyclus!
   \|   \/\/\/   |/      


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~1999-05-26 15:38 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-11-27 10:07 Binary search speed in Alpha Jaap Schellekens
1998-11-27  8:58 ` Matti Aarnio
1998-11-27 13:27   ` Jaap Schellekens
1998-11-28 19:12     ` Bibek Sahu
1998-11-28 19:36       ` Jaap Schellekens
1998-11-28 20:46         ` Dave Gilbert
1998-11-29 16:54           ` Jaap Schellekens
1999-05-26 13:05       ` ElectricFence/Alpha Jaap Schellekens
1999-05-26 14:03         ` ElectricFence/Alpha Uncle George
1999-05-26 14:52           ` ElectricFence/Alpha Jaap Schellekens
1999-05-26 14:06         ` ElectricFence/Alpha Alvin Starr
1999-05-26 14:24         ` ElectricFence/Alpha Maciej W. Rozycki
1999-05-26 14:45         ` ElectricFence/Alpha Giuliano Procida
1999-05-26 14:56         ` ElectricFence/Alpha Mark Probst
  -- strict thread matches above, loose matches on Subject: below --
1998-11-27 13:58 Binary search speed in Alpha Wessels, Hans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox