Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to fix Segmentation fault in fortran ?!

Status
Not open for further replies.

B4M

Member level 2
Joined
Aug 3, 2016
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
318
Hello, I have this error
Code:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
I believe it is due to the use of allocate to define the variables
Code:
REAL, ALLOCATABLE :: M(:,:)
REAL, ALLOCATABLE :: N(:,:)
How to turn around this error?!
thanks a lot!
 

As before with your FORTRAN problems, you should preferably post all statements related to the problem. The ALLOCATABLE statements does nothing with respective ALLOCATE, and the segment fault probably occurs when you are using a memory range that wasn't properly allocated.

What I wonder is this: As you are apparently not very familiar with advanced FORTRAN features, won't it be better to restrict your coding to more basic FORTRAN constructs? Doesn't your PC have sufficient memory space to define the variable arrays statically? Focus on the actual calculation problem instead of practicing new FORTRAN language elements?
 

well the code is suppose to extract the matrix M and N
Code:
INTEGER ::ROWS, COLUMNS, I, J
REAL, ALLOCATABLE :: M (:,:)
REAL, ALLOCATABLE :: N(:,:)
OPEN (19, FILE="OnSp.mat", FORM='UNFORMATTED')
READ (19) ROWS
READ (19) COLUMNS
DO J=1, COLUMNS
READ (19) (M (I,J), I=1, ROWS)
READ (19) (N(I,J), I=1, ROWS)
END DO
CLOSE (19)
 

As guessed before: No memory space allocated, missing ALLOCATE statement. Better use static arrays.
 

The idea of the code is to be applicable to any file with the same structure, knowing that the size of the matrices is not fixed. Any further suggestions are very welcome!
Thank you!
 

The solution seems quite obvious,in the present case, you would perform an allocate after reading the rows and columns info.
 

Thank you very much ! unfortunately it generates this error:
Code:
Error: Unexpected data declaration statement at (1)
looking around I have found that the cause of this error is placing a data declaration statement after a normal statement.:bang:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top