Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!helios.physics.utoronto.ca!aurora.physics.utoronto.ca!neufeld From: neufeld@aurora.physics.utoronto.ca (Christopher Neufeld) Subject: Re: Execution time bottleneck: How Message-ID: <1991Feb25.231321.12226@helios.physics.utoronto.ca> Sender: news@helios.physics.utoronto.ca (News Administrator) Nntp-Posting-Host: aurora.physics.utoronto.ca Organization: University of Toronto Physics/Astronomy/CITA Date: Mon, 25 Feb 1991 23:13:21 GMT In article <21658@yunexus.YorkU.CA> racine@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@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.