program sample
   implicit none

   integer, parameter :: ncycle = 50000


   ! Variables
   real*8 time0, timef, t, sdrho, sdt, sum1, sdtj, sdr(10), trm
   real*8, allocatable :: uij(:,:), assoc_int_drho(:,:)
   real*8, dimension(11,11) :: a_assoc
   integer ii, jj, i, j, ncomp, icycle


   !Set variables
   ncomp = 20
   a_assoc = 0.5d0
   allocate(uij(ncomp, ncomp), assoc_int_drho(ncomp, ncomp))
   uij = 0.7d0
   t = 2.0;
   sdrho = 0.3

   print *, "Entering loop"
   call CPU_TIME(time0)
   do icycle =1, ncycle
      do i = 1, ncomp
         do j = i, ncomp
            sdt =  t / uij(i,j)
            sum1 = 0.0d0
            do  jj=1,11
               do  ii=2,12-jj
!Super slow line
                  sum1 = sum1 + a_assoc(ii,jj) * sdrho**(ii-2)* sdt**(jj-1)*DBLE(ii-1)
               enddo
            enddo
            assoc_int_drho(i,j)=sum1
            assoc_int_drho(j,i)=sum1
         end do
      end do
   enddo
   call CPU_TIME(timef)

   !Some random operation to give an output based on the arrays
   sum1 = DOT_PRODUCT(uij(:,ncomp), MATMUL(assoc_int_drho, uij(:,1)))

   print *, "Exiting loop. Duration: ", timef - time0
   print *, "Sum was: ", sum1

   trm = 1d0
   sdr(1)=1d0
   do i = 2,10
      trm = trm*sdrho
      sdr(i) = trm*dble(i)
   end do
   time0 = timef
   do icycle =1, ncycle
      do i = 1, ncomp
         do j = i, ncomp
            sdt =  t / uij(i,j)
            sdtj = 1d0
            sum1 = 0.0d0
            do  jj=1,11
               do  ii=2,12-jj
                  !Super slow line
                  sum1 = sum1 + a_assoc(ii,jj) * sdr(ii-1)* sdtj
               enddo
               sdtj = sdtj*sdt
            enddo
            assoc_int_drho(i,j)=sum1
            assoc_int_drho(j,i)=sum1
         end do
      end do
   enddo
   call CPU_TIME(timef)

   !Some random operation to give an output based on the arrays
   sum1 = DOT_PRODUCT(uij(:,ncomp), MATMUL(assoc_int_drho, uij(:,1)))

   print *, "Exiting loop. Duration: ", timef - time0
   print *, "Sum was: ", sum1
end program sample

