I want to compute the summation more efficient. There are nested loops, which I want to avoid.
! If i+j <= I,then A_{j} = \sum_{m,n,i} C_{m, i+j} G_{ m, n, i, j} C_{n, i}
! else if i+j >= I, then A_{j} = \sum_{m,n,i} C_{m, i+j-I} G_{ m, n, i, j} C_{n, i}
program main
implicit none
real, allocatable :: A(:)
real, allocatable :: C(:,:), G(:,:,:,:)
integer :: i, j, m, n
integer, parameter :: N = 1500, I = 2000
allocate(A(J))
allocate(C(N,I))
allocate(G(N,N,I,I))
! If i+j <= I,then
! A_{j} = \sum_{m,n,i} C_{m, i+j} G_{ m, n, i, j} C_{n, i}
! else if i+j >= I, then
! A_{j} = \sum_{m,n,i} C_{m, i+j-I} G_{ m, n, i, j} C_{n, i}
do j = 1, I
do i = 1, I
if ( i + j <= I ) then
do n = 1, N
do m = 1, N
A(j) = A(j) + C(m,i+j) * G(m,n,i,j) * C(n,i)
end do
end do
else
do n = 1, N
do m = 1, N
A(j) = A(j) + C(m,i+j-I) * G(m,n,i,j) * C(n,i)
end do
end do
end if
end do
end do
end program main