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

Compound Assignment Improving Vectorization?

$
0
0

Hi

I was attempting to write a Fortran equivalent to the code provided in this vectorization tutorial

https://cvw.cac.cornell.edu/vector/exercise_1

My attempt at a Fortran vectorization equivalent is here:

#define ARRAY_SIZE 1024
#define NUMBER_OF_TRIALS 1000000

module array
    !dir$ attributes align:64 :: a, b, c
    double precision, dimension(ARRAY_SIZE) ::  a, b, c
end module

program main

    use array
    implicit none
    integer i, t

    double precision :: m = 1.0001

    ! Populate A and B arrays
    do i=1, ARRAY_SIZE
        b(i) = i
        a(i) = i + 1
    end do

    ! Perform an operation a number of times
    do t = 1, NUMBER_OF_TRIALS;
        do i = 1, ARRAY_SIZE
            c(i) = c(i) + m*a(i) + b(i)
        end do

        ! I have also tried a version with this line
        ! c = c + m * a  + b
    end do

end program

My questions(s):

0) Is this code as near-equivalent to the version 'simple.c' as in the link above?

1) Any further optimization recommendations?

2) The c version appears to always be faster, and I believe to be related to compound assignment (with '+=').  Here's some reasoning http://programmers.stackexchange.com/a/134136/69046

c[i] +=  m*a[i] + b[i];

Am I off base in thinking that this is the primary difference between the C and Fortran versions? 

 

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



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