Hi,
lately I've seen a piece of code out of a famous scientific article, which is known for its fastness. In it the author always uses temporary variables to restrict access to array elements to a minimum. For example in a inner loop for a recurrent formula he uses:
... real :: temp real :: p(:) ... do i=2,m temp=foo(temp) ... some read access to 'temp' for other variables... p(i)=temp end do ...
I personally would prefer:
... real :: p(:) ... do i=2,m p(i)=foo(p(i-1)) ... some read access to 'p(i)' for other variables... end do ...
So therefor my question: Is the first version really faster then the second one?
I by myself always believed in the compilers capabilities of automated optimization of such simple stuff (regarding memory and register management), but now I'm a bit unsure since the first version is from a very established author...
Thanks for your advice!