Skip to main content
  1. About
  2. For Teams
Asked
Viewed 106 times
0

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.

5
  • Please use tag fortran for all Fortran questions. Without that only few people will see your question.
    Vladimir F Героям слава
    –  Vladimir F Героям слава
    2022-07-30 06:37:44 +00:00
    Commented Jul 30, 2022 at 6:37
  • 3
    To get a relevant backtrace, compile with debuging symbols using the -g flag. Enable also all debugging checks that your compiler offers. Especially enable array bounds checking.
    Vladimir F Героям слава
    –  Vladimir F Героям слава
    2022-07-30 06:39:08 +00:00
    Commented Jul 30, 2022 at 6:39
  • I will try the array bound checking to see if that helps. It seg faults the same every time I run the code. The input arguments that I use is a test run pack that the author provided. I have gone through that input argument pack and there is no issues. I have not made any logic changes in the code. There are some C files that the code uses and I had to include some header files to remove some warnings.
    Surya Sarvajith
    –  Surya Sarvajith
    2022-07-30 14:50:25 +00:00
    Commented Jul 30, 2022 at 14:50
  • If -g doesn't give you a backtrace (it doesn't seem to on some Windows setups), you could also try running your code through gdb
    veryreverie
    –  veryreverie
    2022-07-30 17:02:17 +00:00
    Commented Jul 30, 2022 at 17:02
  • if the array bound of xb is 1, and nstp is anything other than zero, the array will be out of bounds. You could try * instead of 1 for the array bound but depending on how bit xb is, you may still get a segfault.
    cup
    –  cup
    2023-03-13 05:45:51 +00:00
    Commented Mar 13, 2023 at 5:45

0

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.