Segmentation fault due to memory access issue

92 Views Asked by At

When I run my f77 code, I get a segmentation fault due to memory access issue.

This is the message that my terminal outputs:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000f523b7 in bcvnmtn (xb=<error reading variable: Cannot access memory at address 0xc44a8000c3818>, 
    yb=<error reading variable: Cannot access memory at address 0xc5dc8000c5138>, nstp=0, npoints=0, tx=..., ty=..., anx=..., any=...) at ./bcvnmtn.F:14
14            tx(1) = xb(1+nstp) - xb(1)

Here is the subroutine that encounters this segmentation fault

      subroutine bcvnmtn(xb,yb,nstp,npoints,tx,ty,anx,any)

c-----compute the vertex valued tangential and normal vector fields
c----- (tx,ty)(n) and (anx,any)(n) to the curve (xb,yb)((n-1)*nstp+1)
c----- for n=1 to npoints

cdir$ nolist
      include 'paramcom.h'
cdir$ list
      dimension xb(1),yb(1),tx(1),ty(1),anx(1),any(1)

c-----get tangent vector field

      tx(1) = xb(1+nstp) - xb(1)
      ty(1) = yb(1+nstp) - yb(1)

      in = 1
      do 100 n=2,npoints-1
        inp = in + 2*nstp
        tx(n) = (xb(inp) - xb(in))*0.5
        ty(n) = (yb(inp) - yb(in))*0.5
        in = in + nstp
  100 continue

      nlast = npoints
      ilast = 1 + (npoints-1)*nstp
      tx(nlast) = xb(ilast) - xb(ilast-nstp)
      ty(nlast) = yb(ilast) - yb(ilast-nstp)

c-----normalize to unit length and rotate to get normal vector

      do 200 n=1,npoints
        tl = sqrt( tx(n)**2 + ty(n)**2 )
        tx(n) = tx(n) / ( tl + tiny )
        ty(n) = ty(n) / ( tl + tiny )
        any(n) = tx(n)
        anx(n) = -ty(n)
  200 continue

      return
      end

The subroutine above is called by the following subroutine:

      subroutine bcsymgd(xi,yi)

c-----compute ghost point locations along a symmetry boundary

cdir$ nolist
      include 'common.h'
      include 'inputcom.h'
      include 'pointer.h'
cdir$ list
      common /bcpoint/ idimfrm,jdimfrm,isttfrm,jsttfrm,nstpfrm,nofffrm,
     %                 idimtoo,jdimtoo,istttoo,jstttoo,nstptoo,nofftoo,
     %                 npoints
      dimension xi(0:idimfrm,0:jdimfrm),yi(0:idimfrm,0:jdimfrm)
      call bcvnmtn(xi(isttfrm,jsttfrm),yi(isttfrm,jsttfrm),
     %             nstpfrm,npoints,tangx,tangy,anormx,anormy)
      call bcdifvf(dispx(isttfrm,jsttfrm),dispy(isttfrm,jsttfrm),
     %             nofffrm,nstpfrm,
     %             xi(isttfrm,jsttfrm),yi(isttfrm,jsttfrm),
     %             (- nofftoo),nstpfrm,
     %             xi(isttfrm,jsttfrm),yi(isttfrm,jsttfrm),
     %             nofffrm,nstpfrm,npoints)
      call bctrflc(dispx(isttfrm,jsttfrm),dispy(isttfrm,jsttfrm),
     %             dispx(isttfrm,jsttfrm),dispy(isttfrm,jsttfrm),
     %             nstpfrm,npoints,tangx,tangy,anormx,anormy)
      call bcaddvf(xi(istttoo,jstttoo),yi(istttoo,jstttoo),
     %             nofftoo,nstptoo,
     %             dispx(isttfrm,jsttfrm),dispy(isttfrm,jsttfrm),
     %             nofffrm,nstpfrm,
     %             xi(isttfrm,jsttfrm),yi(isttfrm,jsttfrm),
     %             nofffrm,nstpfrm,npoints)

      return
      end

The xi and yi (in bcymgd.F) are coordinates to a geometry. But as you can see, it seems to go from 2 dimension in bcymgd.F to 1 dimension (xb,yb) in bcvnmtn.F

This is a very large and old code. I do not have too much flexibility to edit the source code at this moment. I am using a pgi/2020.4 compiler.

If someone can help me with this that would be great. Please let me know if I can provide more info.

0

There are 0 best solutions below