Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
3 Views

Write statement causing segmentation fault

Hello,

I am using a fortran code called EPW and I would like to extract a matrix from a loop. The structure of the loop is as follows:

Open file to write to

Allocate(A(nbnd,modes,nkf))  ! A is the matrix to be printed

Loop iq ! iq runs from 1 to nqf

       Loop ik !  ik runs from 1 to nkf

               Loop imode ! imode runs from 1 to nmodes

                   Loop ibnd ! ibnd runs from 1 to nbnd

                         A is defined here

                   ENDDO ! ibnd loop

               ENDDO ! imode loop

         ENDDO ! ik loop

        WRITE A(1,1,1) to file ! Writing the first element, one for each iq

ENDDO ! iq loop

DEALLOCATE (A)

I compiled with intel fortran and am running this code serially but get a segmentation fault. The code runs fine if I do not ALLOCATE and WRITE.

I would appreciate any suggestions you may have.

Thank you,

Vahid

Vahid Askarpour

 

0 Kudos
2 Replies
Highlighted
Beginner
3 Views

I just realized that I had

I just realized that I had declared A as real allocatable outside the ik loop and inside the ik loop. The ik loop is done in a subroutine. So I declared it REAL inside the subroutine and real allocatable outside the subroutine and now I don't get the segmentation fault.

0 Kudos
Highlighted
3 Views

I will comment that snippets

I will comment that snippets and paraphrases of code are not useful in helping resolve problems. These almost always fail to show the actual cause, as you found. In the future, please make sure you post actual source code that can be used to demonstrate the problem. Often users find that simply reducing the test case into something they can share reveals a coding error that was the cause.

Retired 12/31/2016
0 Kudos