Execution time bottleneck: How
Dr. David Curtis
dcurtis at crc.ac.uk
Thu Feb 21 23:30:51 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?
Yes, apart from decrementing instead of incrementing the loop, as has
already been suggested:
for (j=1; j <= n; j++) {
float xj;
xj=x[j];
sum = 0.0;
for (i=1; i<= n; i++) {
float xjfromi;
xfromj=x[i]-xj;
sum += exp( con * xfromj * xfromj);
}
a[j] = k*sum;
}
Now what follows I'm less sure of. The main aim is to avoid calculating
array offsets and just increment pointers instead. Can anyone say if
that kind of thing produces significant speed-ups?
float *ap,*xjp,*jp,*a1p,*x1p;
a1p=&a[1];
x1p=&x[1];
for (ap=a1p, xjp=x1p, j=n; j ; --j, ++ap, ++xjp) {
float xj;
xj=*xjp;
sum = 0.0;
for (xip=x1p, i=n; i; --i, ++xip) {
float xjfromi;
xfromj=*xip-xj;
sum += exp( con * xfromj * xfromj);
}
*ap = k*sum;
}
Dave Curtis
Academic Department of Psychiatry, Janet: dc at UK.AC.UCL.SM.PSYCH
Middlesex Hospital, Elsewhere: dc at PSYCH.SM.UCL.AC.UK
Mortimer Street, London W1N 8AA. EARN/Bitnet: dc%PSYCH.SM.UCL at UKACRL
Tel 071-636 8333 Fax 071-323 1459 Usenet: ...!mcsun!ukc!mrccrc!D.Curtis
More information about the Comp.lang.c
mailing list