I am trying to use the SUM intrinsic to sum over only one index in an array, I do not want to sum over all of the elements. Below I provide a sample code that works fine.
I was wondering if there is an easier way to do this though. If so, how can I optimize this code? Thanks
PROGRAM mysample
INTEGER :: i,j
INTEGER, PARAMETER :: nx = 2, ny = 2
REAL, DIMENSION(nx, ny) :: f
REAL, DIMENSION(nx) :: a
DO i = 1,nx
DO j = 1,ny
f(i,j) = i + 2.*j
END DO
END DO
DO j = 1,ny
a(j) = SUM(f(:,j)) !this line sums over the second array index only
END DO
DO i = 1,nx
PRINT*, a(i) !the output is correct
END DO
END PROGRAM