Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
3 Views

SUM versus do-loop summing

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
Highlighted
New Contributor I
3 Views

You did not post an entire

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
Highlighted
Beginner
3 Views

Roman,

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