Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Optimization question: Using temporary variables instead of direct array access

$
0
0

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!


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>