Execution time bottleneck: How

Christopher Neufeld neufeld at aurora.physics.utoronto.ca
Tue Feb 26 10:13:21 AEST 1991


In article <21658 at yunexus.YorkU.CA> racine at yunexus.yorku.ca (Jeff Racine) writes:
>   for (j=1; j <= n; j++) {
>      sum = 0.0;
>      for (i=1; i<= n; i++) {
>         sum += exp( con * (x[i]-x[j]) * (x[i]-x[j]) );
>      }
>      a[j] = k*sum;
>   }
>This part of the algorithmn is a bottleneck. I want to make this as
>quick as possible. What are my options? I have heard that assembler
>would be faster. How much faster would assembler be? Would it be worth
>the effort? Are there other alternatives that you can see?
>
   Well, this might look obvious, but do those delta-x form a discrete
set? If so, you can use a lookup table and calculate all the
exponentials out in front. It depends on your application, but when I
was doing Monte-Carlo simulations which passed through an evaluation
step like this some 10^6 times per data point, I sped things up by
making a lookup table of some thousands of entries, all worked out ahead
of time, and then modified the algorithm so that it believed that it was
working with integers (to simplify the algebra in calculating the table
index number). If you've got enough memory, and that inner loop is
executed often enough, then an approach like this might help.


-- 
 Christopher Neufeld....Just a graduate student  | Note: new host.
 neufeld at aurora.physics.utoronto.ca    Ad astra! | helios will still
 cneufeld@{pnet91,pro-cco}.cts.com               | forward my mail to
 "Don't edit reality for the sake of simplicity" | me on aurora.



More information about the Comp.lang.c mailing list