Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Write statement causing segmentation fault

Vahid_A_2
Beginner
537 Views

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
Vahid_A_2
Beginner
537 Views

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
Steven_L_Intel1
Employee
537 Views

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.

0 Kudos
Reply