Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

SUM versus do-loop summing

Ralph_Nelson
Novice
548 Views

I'm building a vector-parallelized Fortran code.  Looking at hot spots and waits, I found that

x_sum=SUM(X) and

x_sum = zero
Do i 1,n
  x_sum = x_sum + X(i)
ENDDO

X is a real.

preform differently. In my code the do-loop is ~30% faster.  Note there are a number of summations involved so that reflects an overall result for a test case.

Must be my error but please point it out to me.

 

0 Kudos
2 Replies
Roman1
New Contributor I
548 Views

You did not post an entire program, so this is a guess.  What is the size of X?  Is is possible that  SIZE(X) > n , and when you do x_sum=SUM(X)  ,  you are summing over more elements?

 

0 Kudos
Ralph_Nelson
Novice
548 Views

Roman,

Program is BIG with a number of subroutines and why I didn't post. The SUMs in question are in the routine that handles much of the computations.

n ~ 12500

0 Kudos
Reply