From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 3582 invoked from network); 27 Nov 1998 10:08:20 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 27 Nov 1998 10:08:20 -0000 Received: from flow.geo.vu.nl (schj@flow.geo.vu.nl [130.37.64.19]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id FAA00519 for ; Fri, 27 Nov 1998 05:07:39 -0500 Received: (from schj@localhost) by flow.geo.vu.nl (8.8.7/8.8.5) id LAA27460; Fri, 27 Nov 1998 11:07:38 +0100 From: Jaap Schellekens MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 27 Nov 1998 11:07:37 +0100 (MET) To: axp-list@redhat.com Subject: Binary search speed in Alpha X-Mailer: VM 6.43 under 20.4 "Emerald" XEmacs Lucid Message-ID: <13918.31089.348053.439622@flow.geo.vu.nl> 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