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

"Segmentation fault occurred" occurs in Fortran, but the error disappears when the print statement is written

Jump to solution

Dear all,

I am creating a program in Fortran90.

"Forrtl: severe (174): SIGSEGV, segmentation fault occurred" occurs in an array in a structure.
I tried to check the index by writing a print statement to identify the cause, but the error disappeared when I wrote the print statement for some reason. Also, when I added -check bounds, the error disappeared as well.

The compiler used intel Fortran, and an error occurred at that time, but when using gfortran, no error occurred.

If you know the cause, can you tell me?

Thank you.

Best
Christoph

0 Kudos

Accepted Solutions
Highlighted
214 Views

I would suggest you first compile your code with all the warnings and runtime checks enabled. You may have argument mismatch and/or index out of range. I see you used -check bounds. This will catch many of the indexing errors, but not all. The interface checking will also catch additional bounds errors. For example when a dummy argument is declared as REAL FOO(10) and called with actual argument of size other than 10..

If that doesn't lead to a resolution then, are you linking with 3rd party libraries (including your own) which may not have a properly declared interfaces? For example, calling a C compiled function without declaring the interface is to use C calling convention/

AT90's reference is to declaring (explicitly or implicitly) a loop/function/subroutine as to being vector aligned when in fact it is not.

Please state the version number of the compiler.

Jim Dempsey

View solution in original post

0 Kudos
4 Replies
Highlighted
Beginner
214 Views

Are you by any chance enabling vectorization?

One possible answer is that you have told the compiler to vectorize the loop, and that causes a seg fault due to fault memory access. 

When you enable print statements the loop won't vector any longer and hence the seg fault does not occur. 

 

But the best would be to show the code to specifically say what is wrong.  

0 Kudos
Highlighted
Valued Contributor I
214 Views
0 Kudos
Highlighted
215 Views

I would suggest you first compile your code with all the warnings and runtime checks enabled. You may have argument mismatch and/or index out of range. I see you used -check bounds. This will catch many of the indexing errors, but not all. The interface checking will also catch additional bounds errors. For example when a dummy argument is declared as REAL FOO(10) and called with actual argument of size other than 10..

If that doesn't lead to a resolution then, are you linking with 3rd party libraries (including your own) which may not have a properly declared interfaces? For example, calling a C compiled function without declaring the interface is to use C calling convention/

AT90's reference is to declaring (explicitly or implicitly) a loop/function/subroutine as to being vector aligned when in fact it is not.

Please state the version number of the compiler.

Jim Dempsey

View solution in original post

0 Kudos
Highlighted
214 Views

Thank you so much everyone! That fixed my issue.

0 Kudos