title: How to get rid of the 'Killed' after longtime running in a fortran program?
body: <p>I met the 'killed' problem when I run my f90 function for calculating autocorrelation function, in which I need calculate average over a number (<code>np</code>) of time series when the parameter<code>np</code> is very large.</p>
  
  <p>When <code>np</code> is small,my code can work very well. But when <code>np</code> is quite large (<code>10^6</code>), The function is killed after some time of running. Could someone give any suggestion on this problem? The code is as follows.</p>
  
  <pre><code>     program acf
       implicit none
      !========================
      !parameters and variables
      !========================
      character(LEN=20) :: filename
      integer,parameter :: rk=4
      real,parameter :: rooc=29.16, rohc=12.25, cosphic=0.866
      real(kind=rk),parameter :: delta_t=0.005
      real           :: ave_qj
      integer        :: i,j,k,nmo,nat,iat,&amp;
                      imo,np,m1,m2,m3,mt
      real(kind=rk),allocatable,dimension (:,:) :: r12, r13, r23,h
      real(kind=rk),allocatable,dimension (:,:) :: cosphi, pm
      real,allocatable,dimension (:,:)         :: x,y,z
      character(LEN=3),allocatable,dimension (:) :: atom_type
      integer,allocatable,dimension (:)   :: ndx_1, ndx_2, ndx_3
      real,allocatable,dimension (:)      :: qj
      real(kind=rk),allocatable,dimension (:) :: corr_h
      real(kind=rk),allocatable,dimension (:) :: scalar_h
      !==================
      !read data in input
      !==================
      open(10,file='acqjond_k_pair_input')
      read(10,*)filename
      read(10,*)nmo     !number of movie steps
      read(10,*)nat     !number of atoms per mole.
      read(10,*)np      !number of pairs   
      allocate(ndx_1(np))
      allocate(ndx_2(np))
      allocate(ndx_3(np))
      do k=1,np
         read(10,*)ndx_1(k),ndx_2(k),ndx_3(k)
      enddo
      close(10)
      !         
      allocate(atom_type(nat))
      allocate(x(nat,nmo))
      allocate(y(nat,nmo))
      allocate(z(nat,nmo))
      allocate(cosphi(nmo,np))
      allocate(pm(nmo,np))
      allocate(r12(nmo,np))
      allocate(r13(nmo,np))
      allocate(r23(nmo,np))
      allocate(h(nmo,np))
      allocate(qj(np))
      !=======================
      !read in trajectory file 
      !=======================
      open(10,file='traj_pos.xyz')
      do imo=1,nmo
         read(10,*)                  !Neglect data of this line
         read(10,*)                  !Neglect data of this line
         do iat= 1,nat
             read (10,*)atom_type(iat),x(iat,imo),&amp;
                     y(iat,imo),z(iat,imo)
         enddo
      enddo
      close(10)
      !
  
      do k=1,np
          qj(k)=0
          m1=ndx_1(k)
          m2=ndx_2(k)
          m3=ndx_3(k)
          do j =1, nmo
              h(j,k)=0
              r13(j,k)= (x(m1,j)-x(m3,j))**2+  &amp;
                        (y(m1,j)-y(m3,j))**2+  &amp;
                        (z(m1,j)-z(m3,j))**2      !r:squra of distances
              r12(j,k)= (x(m1,j)-x(m2,j))**2+  &amp;
                        (y(m1,j)-y(m2,j))**2+  &amp;
                        (z(m1,j)-z(m2,j))**2
              r23(j,k)= (x(m2,j)-x(m3,j))**2+  &amp;
                        (y(m2,j)-y(m3,j))**2+  &amp;
                        (z(m2,j)-z(m3,j))**2
              pm(j,k)= (x(m3,j)-x(m2,j))*   &amp;
                       (x(m1,j)-x(m2,j))+   &amp;
                       (y(m3,j)-y(m2,j))*   &amp;
                       (y(m1,j)-y(m2,j))+   &amp;
                       (z(m3,j)-z(m2,j))*   &amp;
                       (z(m1,j)-z(m2,j))
              cosphi(j,k)= pm(j,k)/(sqrt(r23(j,k)*r12(j,k)))                 
              if (r13(j,k) .lt. rohc .and. r12(j,k).lt.rooc          &amp;
                .and. cosphi(j,k).gt. cosphic) then
                h(j,k)=1.0
                qj(k)=qj(k)+h(j,k)
              endif
           enddo
           qj(k)=qj(k)/nmo
       enddo
       deallocate (x,y,z,atom_type) 
      !================
      !Write the result
      !================
      open(10,file=trim(filename)//'_nqj.dat')
      do k=1,np
           write(10,*) k, qj(k)
           do j =1,nmo
               write(10,*)j,j*delta_t,h(j,k)
           enddo
       enddo
       close(10)
       deallocate (cosphi,pm,                                          &amp;
               r12,r13,r23,ndx_1,ndx_2,ndx_3)
      !==================================
      !Calculate autocorrelation function
      !==================================
    allocate(corr_h(nmo))
    allocate(scalar_h(np))
    do i=1, nmo
        corr_h(i)=0
    enddo
    ave_qj=0.d0
    ! calculate ave_qj
    do k=1, np
        ave_qj=ave_qj+qj(k)
    enddo
    ave_qj=ave_qj/np
    write(6,*) ave_qj
    ! calculate &lt;f(0)f(t)&gt;/&lt;f&gt; 
    do mt=0,nmo-1     ! time interval
        do k=1, np
            scalar_h(k)=0.d0
            do j=1, nmo-mt-1
                scalar_h(k)=scalar_h(k)+h(j,k)*h(j+mt,k)
            enddo
            scalar_h(k)=scalar_h(k)/(nmo-mt)
            corr_h(mt+1)=corr_h(mt+1)+scalar_h(k)
        enddo
        corr_h(mt+1)=corr_h(mt+1)/(np*ave_qj)
      enddo
      !=====================
      !Write the correlation
      !C(t)       
      !=====================
      open(10,file=trim(filename)//'_acf_h.dat')
          do i=1,int(nmo*rate)
              write(10,*)i-1,corr_h(i)
          enddo
          write(6,*)'written in '//trim(filename)//'_acf_h.dat'
      close(10)
      !==============================================================
      end
  </code></pre>