Motahareh Kia
Motahareh Kia

Reputation: 103

fortran *** Error in `./a.out': free(): invalid next size (normal): 0x0e18b000 ***

I am new in fortran. and this is my code:

  subroutine fft_forward(Q,ier,fftable,ffwork,nfftable,nffwork,     &
 &                       nfft1,nfft2,nfft3,nfftdim1,nfftdim2,       &
 &                       nfftdim3)
  implicit none 

  integer nfft1,nfft2,nfft3,nfftdim1,nfftdim2,nfftdim3
  integer nfftable,nffwork,ier
  double precision,dimension(nfftdim1,nfftdim2,nfftdim3):: Q
  double precision,dimension(nfftable):: fftable
  double precision,dimension(nffwork):: ffwork 

  call pubz3d(Q,ier,nfft1,nfft2,nfft3,nfftdim1,nfftdim2,nfftdim3,   &
 &            fftable,nfftable,ffwork,nffwork)
  write(6,*) 'bye'
  return
  end

I put some write statements at different lines in pubz3d subroutine,and they work (it prints 'hi' at last line of subroutine). But the subroutine does not return any value and even print 'bye'.

  subroutine pubz3d(Q,ier,nfft1,nfft2,nfft3,nfftdim1,nfftdim2,      &
 &                  nfftdim3,wsave,lensav,work,lenwrk)
  implicit none
  double precision,dimension(nfftdim1,nfftdim2,nfftdim3)::Q
  double precision,dimension(lensav)::wsave      
  double precision,dimension(nfft1)::r
  double precision,dimension(lenwrk)::work
  integer nfft1,nfft2,nfft3,nfftdim1,nfftdim2,nfftdim3,n
  integer lensav,lenwrk,ier
  integer i,j,k

  n = nfftdim1 * nfftdim2 *nfftdim3

  do  k = 1, nfft3
   do  j = 1, nfft2
    do  i = 1,nfft1
      r(i) = Q(i,j,k)
    continue
    call dfft1f(n,1,r,n + 1,wsave,lensav,work,lenwrk,ier)
    do  i = 1,nfft1
     Q(i,j,k) = r(i)
    continue
   continue
  continue

  do  k = 1,nfft3
   do  i = 1,nfft1
    do  j = 1,nfft2
      r(j) = Q(i,j,k)
    continue
    call dfft1f(n,1,r,n + 1,wsave,lensav,work,lenwrk,ier)
    do  j = 1,nfft2
      Q(i,j,k) = r(j)
    continue
   continue
  continue

  do  i = 1, nfft1
   do  j = 1, nfft2
    do  k = 1,nfft3
      r(k) = Q(i,j,k)
    continue
    call dfft1f(n,1,r,n + 1,wsave,lensav,work,lenwrk,ier)
    do  k = 1,nfft3
      Q(i,j,k) = r(k)
    continue
   continue
  continue
  write(6,*) 'hi'
  return
  end

Running I get

hi
*** Error in `./a.out': free(): invalid next size (normal): 0x0e5a9000 ***
Program received signal SIGABRT: Process abort signal.
Backtrace for this error:
#0  0xB760B163
#1  0xB760B800
#2  0xB77103FF
#3  0xB7710424
#4  0xB7416606
#5  0xB7419A32
#6  0xB7450E52
#7  0xB745B339
#8  0xB745BFAC
#9  0x804BD3B in pubz3d_
#10  0x804BFE4 in fft_forward_
#11  0x8055FF4 in do_pmesh_kspace_
#12  0x8054F2D in MAIN__ at main.f:?
Aborted

Thank you

Upvotes: 1

Views: 5370

Answers (1)

Are you sure that nfft1>nfft2 and nfft1>nfft3? Your auxiliary variable r has size nfft1, but you use it in loops up to nfft2 and nfft3 both. If either of these is larger than nfft1, then you'll get an error. Make sure that the dimension of r is large enough to accommodate all three kinds of loops.

If this isn't the problem, try compiling with some array bounds check (gfortran: -fcheck=all, ifort: -check all to be safe). This might throw a more informative error at the point where something goes wrong.

Upvotes: 2

Related Questions