Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!bellcore!uunet!mcsun!ukc!mrccrc!dcurtis From: dcurtis@crc.ac.uk (Dr. David Curtis) Newsgroups: comp.lang.c Subject: Re: Execution time bottleneck: How Message-ID: <492@tin.crc.ac.uk> Date: 21 Feb 91 12:30:51 GMT References: <233522@<1991Feb12> <20900015@inmet> Reply-To: dcurtis@crc.ac.uk (Dr. David Curtis) Organization: MRC Human Genome Resource Centre Lines: 55 >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? 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@UK.AC.UCL.SM.PSYCH Middlesex Hospital, Elsewhere: dc@PSYCH.SM.UCL.AC.UK Mortimer Street, London W1N 8AA. EARN/Bitnet: dc%PSYCH.SM.UCL@UKACRL Tel 071-636 8333 Fax 071-323 1459 Usenet: ...!mcsun!ukc!mrccrc!D.Curtis